Skip to content

Commit a6c10aa

Browse files
Cleanup some warnings reported by Coverity and cppcheck.
This fixes some memory leaks in sds.c, printf format string mistakes, and a possible NULL ptr dereference.
1 parent 30dfeda commit a6c10aa

File tree

10 files changed

+17
-19
lines changed

10 files changed

+17
-19
lines changed

src/DS/sds.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,9 @@ static int ds_sds_compose_add_component_dependencies(xmlDocPtr doc, xmlNodePtr d
904904
if (ret < 0) {
905905
// oscap_seterr has already been called
906906
oscap_htable_free0(exported);
907+
xmlXPathFreeObject(xpathObj);
908+
xmlXPathFreeContext(xpathCtx);
909+
free(filepath_cpy);
907910
free(dir);
908911
return -1;
909912
}

src/OVAL/oval_agent.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ oval_agent_session_t * oval_agent_new_session(struct oval_definition_model *mode
9494
struct oval_generator *generator;
9595
int ret;
9696

97-
dI("Started new OVAL agent.", name);
97+
dI("Started new OVAL agent %s.", name);
9898

9999
/* Optimalization */
100100
oval_definition_model_optimize_by_filter_propagation(model);

src/OVAL/oval_component.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1950,7 +1950,7 @@ static long unsigned int _parse_datetime(char *datetime, const char *fmt[], size
19501950
}
19511951
}
19521952

1953-
dE("Unable to interpret \"%s\" as a datetime string");
1953+
dE("Unable to interpret \"%s\" as a datetime string", datetime);
19541954

19551955
return (0);
19561956
}

src/OVAL/oval_probe_ext.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ static inline int _handle_SEAP_receive_failure(SEAP_CTX_t *ctx, oval_pd_t *pd, S
365365
case 0:
366366
break;
367367
case 1: /* no error found */
368-
dE("Internal error: An error was signaled on sd=%d but the error queue is empty.");
368+
dE("Internal error: An error was signaled on sd=%d but the error queue is empty.", pd->sd);
369369
oscap_seterr(OSCAP_EFAMILY_OVAL, "SEAP_recverr_byid: internal error: empty error queue.");
370370
return (-1);
371371
case -1: /* internal error */

src/OVAL/probes/SEAP/seap-packet.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ static int SEAP_packet_sexp2msg (SEXP_t *sexp_msg, SEAP_msg_t *seap_msg)
113113

114114
attr_name = SEXP_list_nth (sexp_msg, msg_n);
115115
if (attr_name == NULL) {
116-
dI("Unexpected error: No S-exp (attr_name) at position %u in the message (%p).",
116+
dI("Unexpected error: No S-exp (attr_name) at position %lu in the message (%p).",
117117
msg_n, sexp_msg);
118118

119119
free(seap_msg->attrs);
@@ -126,7 +126,7 @@ static int SEAP_packet_sexp2msg (SEXP_t *sexp_msg, SEAP_msg_t *seap_msg)
126126

127127
attr_val = SEXP_list_nth (sexp_msg, msg_n + 1);
128128
if (attr_val == NULL) {
129-
dI("Unexpected error: \"%s\": No attribute value at position %u in the message (%p).",
129+
dI("Unexpected error: \"%s\": No attribute value at position %lu in the message (%p).",
130130
"id", msg_n + 1, sexp_msg);
131131

132132
free(seap_msg->attrs);
@@ -170,7 +170,7 @@ static int SEAP_packet_sexp2msg (SEXP_t *sexp_msg, SEAP_msg_t *seap_msg)
170170
seap_msg->attrs[attr_i].value = SEXP_list_nth (sexp_msg, msg_n + 1);
171171

172172
if (seap_msg->attrs[attr_i].value == NULL) {
173-
dI("Unexpected error: \"%s\": No attribute value at position %u in the message (%p).",
173+
dI("Unexpected error: \"%s\": No attribute value at position %lu in the message (%p).",
174174
seap_msg->attrs[attr_i].name, msg_n + 1, sexp_msg);
175175

176176
free(seap_msg->attrs[attr_i].name);

src/OVAL/probes/SEAP/sexp-manip_r.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,6 @@ SEXP_t *SEXP_string_newf_rv(SEXP_t *sexp_mem, const char *format, va_list ap)
266266
return NULL;
267267
}
268268

269-
if (v_strlen < 0) {
270-
/* TODO: handle this */
271-
return (NULL);
272-
}
273-
274269
if (SEXP_val_new (&v_dsc, sizeof (char) * v_strlen,
275270
SEXP_VALTYPE_STRING) != 0)
276271
{

src/OVAL/probes/oval_fts.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ static int badpartial_check_slash(const char *pattern)
389389
if (regex == NULL) {
390390
dE("Failed to validate the pattern: pcre_compile(): "
391391
"error: '%s', error offset: %d, pattern: '%s'.\n",
392-
errofs, errptr, pattern);
392+
errptr, errofs, pattern);
393393
return -1;
394394
}
395395
ret = pcre_fullinfo(regex, NULL, PCRE_INFO_FIRSTBYTE, &fb);

src/OVAL/probes/unix/linux/rpmverifypackage_probe.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,13 +369,13 @@ void rpmverifypackage_probe_fini(void *ptr)
369369
rpmFreeMacros(NULL);
370370
rpmlogClose();
371371

372-
// This will be always set by probe_init(), lets free it
373-
probe_chroot_free(&r->chr);
374-
375372
// If r is null, probe_init() failed during chroot
376373
if (r == NULL)
377374
return;
378375

376+
// This will be always set by probe_init(), lets free it
377+
probe_chroot_free(&r->chr);
378+
379379
// If r->rpm.rpmts was not initialized the mutex was not as well
380380
if (r->rpm.rpmts == NULL)
381381
return;
@@ -401,7 +401,7 @@ static int rpmverifypackage_additem(probe_ctx *ctx, struct rpmverify_res *res)
401401
NULL);
402402

403403
if (res->vflags & VERIFY_DEPS) {
404-
dI("VERIFY_DEPS %d", res->vresults & VERIFY_DEPS);
404+
dI("VERIFY_DEPS %lu", res->vresults & VERIFY_DEPS);
405405
value = probe_entval_from_cstr(OVAL_DATATYPE_BOOLEAN, (res->vresults & VERIFY_DEPS ? "1" : "0"), 1);
406406
probe_item_ent_add(item, "dependency_check_passed", NULL, value);
407407
SEXP_free(value);

src/OVAL/probes/unix/process_probe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ static int read_process(SEXP_t *cmd_ent, probe_ctx *ctx)
421421
int fixfmt_year;
422422

423423
r.scheduling_class = malloc(PRCLSZ);
424-
strncpy(r.scheduling_class, (psinfo->pr_lwp).pr_clname, sizeof(r.scheduling_class));
424+
strncpy(r.scheduling_class, (psinfo->pr_lwp).pr_clname, PRCLSZ);
425425

426426
// Get the start time
427427
s_time = time(NULL);

src/source/oscap_source.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ xmlDoc *oscap_source_get_xmlDoc(struct oscap_source *source)
270270
source->xml.doc = xmlReadMemory(source->origin.memory, source->origin.memory_size, NULL, NULL, 0);
271271
if (source->xml.doc == NULL) {
272272
if (memory_file_is_executable(source->origin.memory, source->origin.memory_size)) {
273-
dI("oscap-source in memory was detected as executable file. Skipped XML parsing", oscap_source_readable_origin(source));
273+
dI("oscap-source in memory was detected as executable file '%s'. Skipped XML parsing", oscap_source_readable_origin(source));
274274
oscap_string_clear(xml_error_string);
275275
} else {
276276
oscap_setxmlerr(xmlGetLastError());
@@ -299,7 +299,7 @@ xmlDoc *oscap_source_get_xmlDoc(struct oscap_source *source)
299299
source->xml.doc = xmlReadFd(fd, NULL, NULL, 0);
300300
if (source->xml.doc == NULL) {
301301
if (fd_file_is_executable(fd)) {
302-
dI("oscap-source file was detected as executable file. Skipped XML parsing", oscap_source_readable_origin(source));
302+
dI("oscap-source file was detected as executable file '%s'. Skipped XML parsing", oscap_source_readable_origin(source));
303303
oscap_string_clear(xml_error_string);
304304
} else {
305305
oscap_setxmlerr(xmlGetLastError());

0 commit comments

Comments
 (0)