Skip to content

Commit cd24be4

Browse files
committed
Updated session.c null dereference path
1 parent 7b9ac8e commit cd24be4

2 files changed

Lines changed: 72 additions & 64 deletions

File tree

agent.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,10 @@ static bool main_loop(void)
498498
/*true in the config file.If EnrollOnStartup is true, the agent */
499499
/* makes a keypair & a CSR to send up to the platform for the agent) */
500500
log_verbose("%s::%s(%d) : Connecting to platform for session & job list", LOG_INF);
501-
register_session(&SessionData, &JobList, AGENT_VERSION);
501+
if (0 != register_session(&SessionData, &JobList, AGENT_VERSION)) {
502+
log_error("%s::%s(%d) : Failed to register session with platform", LOG_INF);
503+
return false;
504+
}
502505
currentJob = JobList;
503506

504507
/**************************************************************************/

session.c

Lines changed: 68 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -218,74 +218,79 @@ static bool register_agent(SessionRegisterReq_t * sessionReq) {
218218
/* @param [Input] : a session response */
219219
/* @return none */
220220
/* */
221-
static void prioritize_jobs(ScheduledJob_t * *pJobList,
222-
SessionRegisterResp_t * response) {
223-
int i;
224-
SessionJob_t *job_to_schedule = NULL;
225221

226-
if (!pJobList || !response) {
227-
log_error("%s::%s(%d) : Null pointer dereference - pJobList or response is NULL", LOG_INF);
228-
return;
229-
}
222+
static void prioritize_jobs(ScheduledJob_t **pJobList,
223+
SessionRegisterResp_t *response) {
224+
int i;
225+
SessionJob_t *job_to_schedule = NULL;
230226

231-
log_verbose("%s::%s(%d) : Prioritizing jobs", LOG_INF);
227+
if (!pJobList || !response) {
228+
log_error(
229+
"%s::%s(%d) : Null pointer dereference - pJobList or response is NULL",
230+
LOG_INF);
231+
return;
232+
}
232233

233-
/* Store management ADD jobs */
234-
for (i = 0; response->Session.Jobs_count > i; i++) {
235-
job_to_schedule = response->Session.Jobs[i];
236-
if (!job_to_schedule || !job_to_schedule->JobTypeId) {
237-
log_warn("%s::%s(%d) : Null job or JobTypeId at index %d", LOG_INF, i);
238-
continue;
239-
}
240-
if (0 == strcasecmp(CAP_PEM_MANAGEMENT, job_to_schedule->JobTypeId)) {
241-
if (MANAGEMENT_ADD_PRIORITY == job_to_schedule->Priority) {
242-
log_trace("%s::%s(%d) : Adding management ADD job %s", LOG_INF,
243-
job_to_schedule->JobId);
244-
schedule_job(pJobList, job_to_schedule, time(NULL));
245-
}
246-
}
234+
log_verbose("%s::%s(%d) : Prioritizing jobs", LOG_INF);
235+
236+
/* Store management ADD jobs */
237+
for (i = 0; response->Session.Jobs_count > i; i++) {
238+
job_to_schedule = response->Session.Jobs[i];
239+
if (!job_to_schedule || !job_to_schedule->JobTypeId) {
240+
log_warn("%s::%s(%d) : Null job or JobTypeId at index %d", LOG_INF, i);
241+
continue;
247242
}
248-
/* Reenrollment jobs */
249-
for (i = 0; response->Session.Jobs_count > i; i++) {
250-
job_to_schedule = response->Session.Jobs[i];
251-
if (!job_to_schedule || !job_to_schedule->JobTypeId) {
252-
log_warn("%s::%s(%d) : Null job or JobTypeId at index %d", LOG_INF, i);
253-
continue;
254-
}
255-
if (0 == strcasecmp(CAP_PEM_REENROLLMENT, job_to_schedule->JobTypeId)) {
256-
log_trace("%s::%s(%d) : Adding reenrollment job %s", LOG_INF, job_to_schedule->JobId);
257-
schedule_job(pJobList, job_to_schedule, time(NULL));
258-
}
243+
if (0 == strcasecmp(CAP_PEM_MANAGEMENT, job_to_schedule->JobTypeId)) {
244+
if (MANAGEMENT_ADD_PRIORITY == job_to_schedule->Priority) {
245+
log_trace("%s::%s(%d) : Adding management ADD job %s", LOG_INF,
246+
job_to_schedule->JobId);
247+
schedule_job(pJobList, job_to_schedule, time(NULL));
248+
}
259249
}
260-
/* Store management non-ADD jobs */
261-
for (i = 0; response->Session.Jobs_count > i; i++) {
262-
job_to_schedule = response->Session.Jobs[i];
263-
if (!job_to_schedule || !job_to_schedule->JobTypeId) {
264-
log_warn("%s::%s(%d) : Null job or JobTypeId at index %d", LOG_INF, i);
265-
continue;
266-
}
267-
if (0 == strcasecmp(CAP_PEM_MANAGEMENT, job_to_schedule->JobTypeId)) {
268-
if (MANAGEMENT_ADD_PRIORITY != job_to_schedule->Priority) {
269-
log_trace("%s::%s(%d) : Adding management non-ADD job %s", LOG_INF, job_to_schedule->JobId);
270-
schedule_job(pJobList, job_to_schedule, time(NULL));
271-
}
272-
}
250+
}
251+
/* Reenrollment jobs */
252+
for (i = 0; response->Session.Jobs_count > i; i++) {
253+
job_to_schedule = response->Session.Jobs[i];
254+
if (!job_to_schedule || !job_to_schedule->JobTypeId) {
255+
log_warn("%s::%s(%d) : Null job or JobTypeId at index %d", LOG_INF, i);
256+
continue;
273257
}
274-
/* Inventory jobs */
275-
for (i = 0; response->Session.Jobs_count > i; i++) {
276-
job_to_schedule = response->Session.Jobs[i];
277-
if (!job_to_schedule || !job_to_schedule->JobTypeId) {
278-
log_warn("%s::%s(%d) : Null job or JobTypeId at index %d", LOG_INF, i);
279-
continue;
280-
}
281-
if (0 == strcasecmp(CAP_PEM_INVENTORY, job_to_schedule->JobTypeId)) {
282-
log_trace("%s::%s(%d) : Adding inventory job %s", LOG_INF, job_to_schedule->JobId);
283-
schedule_job(pJobList, job_to_schedule, time(NULL));
284-
}
258+
if (0 == strcasecmp(CAP_PEM_REENROLLMENT, job_to_schedule->JobTypeId)) {
259+
log_trace("%s::%s(%d) : Adding reenrollment job %s", LOG_INF,
260+
job_to_schedule->JobId);
261+
schedule_job(pJobList, job_to_schedule, time(NULL));
285262
}
286-
return;
263+
}
264+
/* Store management non-ADD jobs */
265+
for (i = 0; response->Session.Jobs_count > i; i++) {
266+
job_to_schedule = response->Session.Jobs[i];
267+
if (!job_to_schedule || !job_to_schedule->JobTypeId) {
268+
log_warn("%s::%s(%d) : Null job or JobTypeId at index %d", LOG_INF, i);
269+
continue;
270+
}
271+
if (0 == strcasecmp(CAP_PEM_MANAGEMENT, job_to_schedule->JobTypeId)) {
272+
if (MANAGEMENT_ADD_PRIORITY != job_to_schedule->Priority) {
273+
log_trace("%s::%s(%d) : Adding management non-ADD job %s", LOG_INF,
274+
job_to_schedule->JobId);
275+
schedule_job(pJobList, job_to_schedule, time(NULL));
276+
}
277+
}
278+
}
279+
/* Inventory jobs */
280+
for (i = 0; response->Session.Jobs_count > i; i++) {
281+
job_to_schedule = response->Session.Jobs[i];
282+
if (!job_to_schedule || !job_to_schedule->JobTypeId) {
283+
log_warn("%s::%s(%d) : Null job or JobTypeId at index %d", LOG_INF, i);
284+
continue;
285+
}
286+
if (0 == strcasecmp(CAP_PEM_INVENTORY, job_to_schedule->JobTypeId)) {
287+
log_trace("%s::%s(%d) : Adding inventory job %s", LOG_INF,
288+
job_to_schedule->JobId);
289+
schedule_job(pJobList, job_to_schedule, time(NULL));
290+
}
291+
}
292+
return;
287293
} /* prioritize_jobs */
288-
289294
/* */
290295
/* Add the capabilities allowed in this version of the agent by */
291296
/* capability GUID defined in Keyfactor */
@@ -964,12 +969,12 @@ int register_session(SessionInfo_t * session, ScheduledJob_t * *pJobList, uint64
964969
free(url);
965970
free(reqString);
966971
return 0;
967-
#else /* __DEBUG__ */
972+
#else /* __DEBUG__ */
968973
/* Run HTTP POST if we aren't in __DEBUG__ */
969974
httpRes = http_post_json(url, ConfigData->Username, ConfigData->Password,
970975
ConfigData->TrustStore, ConfigData->AgentCert, ConfigData->AgentKey,
971-
ConfigData->AgentKeyPassword, reqString, &respString,
972-
ConfigData->httpRetries, ConfigData->retryInterval);
976+
ConfigData->AgentKeyPassword, reqString, &respString,
977+
ConfigData->httpRetries, ConfigData->retryInterval);
973978

974979
if (0 == httpRes) {
975980
log_trace("%s::%s(%d): decoding json response", LOG_INF);

0 commit comments

Comments
 (0)