Failure in startup - modified to handle memory exhaustion when loading file

This commit is contained in:
Olof hagsand 2019-04-18 15:38:15 +02:00
parent b714eff077
commit 728c97ab6d
2 changed files with 14 additions and 6 deletions

View file

@ -180,6 +180,7 @@ startup_common(clicon_handle h,
if (clicon_option_bool(h, "CLICON_XMLDB_MODSTATE"))
if ((msd = modstate_diff_new()) == NULL)
goto done;
clicon_debug(1, "Reading startup config from %s", db);
if (xmldb_get(h, db, "/", &xt, msd) < 0)
goto done;
if (msd){
@ -211,6 +212,7 @@ startup_common(clicon_handle h,
/* 5. Make generic validation on all new or changed data.
Note this is only call that uses 3-values */
clicon_debug(1, "Validating startup %s", db);
if ((ret = generic_validate(yspec, td, cbret)) < 0)
goto done;
if (ret == 0)
@ -282,6 +284,7 @@ startup_validate(clicon_handle h,
* @retval -1 Error - or validation failed (but cbret not set)
* @retval 0 Validation failed (with cbret set)
* @retval 1 Validation OK
* Only called from startup_mode_startup
*/
int
startup_commit(clicon_handle h,
@ -292,6 +295,10 @@ startup_commit(clicon_handle h,
int ret;
transaction_data_t *td = NULL;
if (strcmp(db,"running")==0){
clicon_err(OE_FATAL, 0, "Invalid startup db: %s", db);
goto done;
}
/* Handcraft a transition with only target and add trees */
if ((td = transaction_new()) == NULL)
goto done;
@ -302,6 +309,13 @@ startup_commit(clicon_handle h,
/* 8. Call plugin transaction commit callbacks */
if (plugin_transaction_commit(h, td) < 0)
goto done;
/* [Delete and] create running db */
if (xmldb_exists(h, "running") == 1){
if (xmldb_delete(h, "running") != 0 && errno != ENOENT)
goto done;;
}
if (xmldb_create(h, "running") < 0)
goto done;
/* 9, write (potentially modified) tree to running
* XXX note here startup is copied to candidate, which may confuse everything
*/

View file

@ -641,9 +641,6 @@ main(int argc,
/* Copy original running to tmp as backup (restore if error) */
if (xmldb_copy(h, "running", "tmp") < 0)
goto done;
/* [Delete and] create running db */
if (startup_db_reset(h, "running") < 0)
goto done;
ret = startup_mode_startup(h, "tmp", cbret);
/* If ret fails, copy tmp back to running */
if (ret != 1)
@ -656,9 +653,6 @@ main(int argc,
/* Copy original running to tmp as backup (restore if error) */
if (xmldb_copy(h, "running", "tmp") < 0)
goto done;
/* [Delete and] create running db */
if (startup_db_reset(h, "running") < 0)
goto done;
/* Load and commit from startup */
ret = startup_mode_startup(h, "startup", cbret);
/* If ret fails, copy tmp back to running */