Skip to content

Commit 7b9ac8e

Browse files
committed
Return failure on null dereferences in management.c
1 parent 55c266c commit 7b9ac8e

4 files changed

Lines changed: 431 additions & 421 deletions

File tree

agent.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -340,19 +340,23 @@ int run_job(SessionJob_t * job)
340340
}
341341

342342
#if defined (__RUN_CHAIN_JOBS__)
343-
if (chainJobId) {
344-
log_info("%s::%s(%d) : Completed job indicates that job %s should be run immediately", LOG_INF, chainJobId);
345-
chainJob = get_job_by_id(&JobList, chainJobId);
346-
if (chainJob) {
347-
(void)run_job(chainJob);
348-
} else {
349-
log_info("%s::%s(%d) : Job %s could not be found in the scheduled jobs list, and will not be run", LOG_INF, chainJobId);
343+
if (0 == status) {
344+
if (chainJobId) {
345+
log_info("%s::%s(%d) : Completed job indicates that job %s should be run immediately", LOG_INF, chainJobId);
346+
chainJob = get_job_by_id(&JobList, chainJobId);
347+
if (chainJob) {
348+
(void)run_job(chainJob);
349+
} else {
350+
log_info("%s::%s(%d) : Job %s could not be found in the scheduled jobs list, and will not be run", LOG_INF, chainJobId);
351+
}
350352
}
351353
}
352354
#endif
355+
353356
if (chainJobId) {
354357
free(chainJobId);
355358
}
359+
356360
return status;
357361
} /* run_job */
358362

@@ -480,14 +484,15 @@ bool release_platform(void)
480484
} /* release_platform */
481485

482486
/* */
483-
/* Runs a single loop agent */
484-
/* @param - none */
485-
/* @return - none */
487+
/* Main program loop. Establishes a session with the platform, retrieves the */
488+
/* job list, and executes all scheduled jobs in priority order. */
489+
/* */
490+
/* @return true if all jobs executed successfully, false otherwise */
486491
/* */
487492
static bool main_loop(void)
488493
{
489494
time_t now = 0;
490-
bool error_status = false;
495+
bool success = true;
491496
/* First establish a session with the platform; the session registration */
492497
/* gets all of the jobs from the platform. (Unless EnrollOnStartup is */
493498
/*true in the config file.If EnrollOnStartup is true, the agent */
@@ -504,7 +509,7 @@ static bool main_loop(void)
504509
//Run the jobs based on the time queue
505510
now = time(NULL);
506511
if (0 != run_job(currentJob->Job)) {
507-
error_status = true;
512+
success = false;
508513
}
509514
log_info("%s::%s(%d) : Advancing to job number %s", LOG_INF,
510515
NULL == currentJob->NextJob ? "NULL" : currentJob->NextJob->Job->JobId);
@@ -513,7 +518,7 @@ static bool main_loop(void)
513518

514519
log_info("%s::%s(%d) : No jobs to run -- Begin Agent Shutdown & Memory Release", LOG_INF);
515520

516-
return error_status;
521+
return success;
517522
} /* main_loop */
518523

519524
/* */

management.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ int cms_job_manage(SessionJob_t * jobInfo, char *sessionToken,
388388
jobInfo->ConfigurationEndpoint, &manConf);
389389
if (res != 0) {
390390
log_error("%s::%s(%d) : Failed to get management config", LOG_INF);
391+
free(statusMessage);
391392
return res;
392393
}
393394

openssl_wrapper/openssl_wrapper.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2279,6 +2279,8 @@ bool ssl_PemInventoryItem_create(struct PemInventoryItem** pem, const char* cert
22792279
bResult = true;
22802280
} else {
22812281
log_error("%s::%s(%d) : Error populating cert", LOG_INF);
2282+
PemInventoryItem_free(*pem);
2283+
*pem = NULL;
22822284
}
22832285

22842286
cleanup:

0 commit comments

Comments
 (0)