Skip to content

Commit f0a7b4c

Browse files
Code cleanup from static analysis
1 parent fcc2136 commit f0a7b4c

File tree

14 files changed

+43
-23
lines changed

14 files changed

+43
-23
lines changed

audisp/audispd.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,12 @@ static int safe_exec(plugin_conf_t *conf)
498498
}
499499

500500
/* Set up comm with child */
501-
dup2(conf->plug_pipe[0], 0);
501+
if (dup2(conf->plug_pipe[0], 0) < 0) {
502+
close(conf->plug_pipe[0]);
503+
close(conf->plug_pipe[1]);
504+
conf->pid = 0;
505+
return -1; /* Failed to fork */
506+
}
502507
for (i=3; i<24; i++) /* Arbitrary number */
503508
close(i);
504509

audisp/plugins/remote/audisp-remote.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,26 +1254,30 @@ static int recv_msg_gss (unsigned char *header, char *msg, uint32_t *mlen)
12541254

12551255
if (utok.length < AUDIT_RMW_HEADER_SIZE) {
12561256
sync_error_handler ("message too short");
1257+
free (utok.value);
12571258
return -1;
12581259
}
12591260
memcpy (header, utok.value, AUDIT_RMW_HEADER_SIZE);
12601261

12611262
if (! AUDIT_RMW_IS_MAGIC (header, AUDIT_RMW_HEADER_SIZE)) {
12621263
sync_error_handler ("bad magic number");
1264+
free (utok.value);
12631265
return -1;
12641266
}
12651267

12661268
AUDIT_RMW_UNPACK_HEADER (header, hver, mver, type, rlen, seq);
12671269

12681270
if (rlen > MAX_AUDIT_MESSAGE_LENGTH) {
12691271
sync_error_handler ("message too long");
1272+
free (utok.value);
12701273
return -1;
12711274
}
12721275

12731276
memcpy (msg, utok.value+AUDIT_RMW_HEADER_SIZE, rlen);
12741277

12751278
*mlen = rlen;
12761279

1280+
free (utok.value);
12771281
return 0;
12781282
}
12791283
#endif

audisp/plugins/zos-remote/zos-remote-plugin.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,8 +572,7 @@ int main(int argc, char *argv[])
572572
alarm(0); /* cancel any pending alarm */
573573
auparse_destroy(au); /* 2 */
574574
plugin_free_config(&conf); /* 1 */
575-
}
576-
while (hup && stop == 0);
575+
} while (hup && stop == 0);
577576

578577
/* destroy queue before leaving */
579578
destroy_queue();

auparse/auditd-config.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,10 @@ static char *get_line(auparse_state_t *au, FILE *f, char *buf, unsigned size,
206206
too_long = 0;
207207
*lineno = *lineno + 1;
208208
} else {
209-
// If a line is too long skip it.
210-
// Only output 1 warning
211-
if (!too_long)
212-
audit_msg(au, LOG_ERR,
209+
// If a line is too long skip it.
210+
// Only output 1 warning
211+
if (!too_long)
212+
audit_msg(au, LOG_ERR,
213213
"Skipping line %d in %s: too long",
214214
*lineno, file);
215215
too_long = 1;

auparse/data_buf.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,12 @@ static int debug = 0;
105105
static inline char *databuf_end(DataBuf *db)
106106
{return (db->alloc_ptr == NULL) ? NULL : db->alloc_ptr+db->offset+db->len;}
107107

108-
static inline char *databuf_alloc_end(DataBuf *db)
109-
{return (db->alloc_ptr == NULL) ? NULL : db->alloc_ptr+db->alloc_size;}
110-
111108
static inline int databuf_tail_size(DataBuf *db)
112109
{return db->alloc_size - (db->offset+db->len);}
113110

114111
static inline int databuf_tail_available(DataBuf *db, size_t append_len)
115112
{return append_len <= databuf_tail_size(db);}
116113

117-
static inline size_t databuf_free_size(DataBuf *db)
118-
{return db->alloc_size-db->len;}
119-
120114
/*****************************************************************************/
121115
/*************************** Internal Functions ****************************/
122116
/*****************************************************************************/

auparse/interpret.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ static const char *print_exit(const char *val)
778778

779779
static char *print_escaped(const char *val)
780780
{
781-
const char *out;
781+
char *out;
782782

783783
if (*val == '"') {
784784
char *term;
@@ -2585,7 +2585,7 @@ static const char *print_list(const char *val)
25852585
if (asprintf(&out, "conversion error(%s)", val) < 0)
25862586
out = NULL;
25872587
} else {
2588-
char *o = audit_flag_to_name(i);
2588+
const char *o = audit_flag_to_name(i);
25892589
if (o != NULL)
25902590
out = strdup(o);
25912591
else if (asprintf(&out, "unknown-list(%s)", val) < 0)

auparse/lru.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ static Hash *create_hash(unsigned int hsize)
6161
return hash;
6262

6363
hash->array = malloc(hsize * sizeof(QNode*));
64+
if (hash->array == NULL) {
65+
free(hash);
66+
return NULL;
67+
}
6468

6569
// Initialize all hash entries as empty
6670
for (i = 0; i < hsize; i++)

auparse/normalize.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ static int normalize_syscall(auparse_state_t *au, const char *syscall, int type)
679679
break;
680680
default:
681681
{
682-
char *k;
682+
const char *k;
683683
rc = auparse_first_record(au);
684684
k = auparse_find_field(au, "key");
685685
if (k && strcmp(k, "(null)")) {

src/auditd-listen.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ static int negotiate_credentials (ev_tcp *io)
369369

370370
context = & io->gss_context;
371371
*context = GSS_C_NO_CONTEXT;
372+
io->remote_name = NULL;
372373

373374
maj_stat = GSS_S_CONTINUE_NEEDED;
374375
do {
@@ -380,8 +381,11 @@ static int negotiate_credentials (ev_tcp *io)
380381
sockaddr_to_addr4(&io->addr));
381382
return -1;
382383
}
383-
if (recv_tok.length == 0)
384+
if (recv_tok.length == 0) {
385+
free(recv_tok.value);
386+
recv_tok.value = NULL;
384387
continue;
388+
}
385389

386390
/* STEP 2 - let GSS process that token. */
387391

@@ -847,6 +851,7 @@ static void auditd_tcp_listen_handler( struct ev_loop *loop,
847851
if (use_gss && negotiate_credentials (client)) {
848852
shutdown(afd, SHUT_RDWR);
849853
close(afd);
854+
free(client->remote_name);
850855
free(client);
851856
return;
852857
}

src/ausearch-checkpt.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ int load_ChkPt(const char *fn)
204204
fn, strerror(errno));
205205
return -2;
206206
}
207+
chkpt_input_levent.node = NULL;
207208
while (fgets(lbuf, MAX_LN, fd) != NULL) {
208209
size_t len = strlen(lbuf);
209210

@@ -229,6 +230,8 @@ int load_ChkPt(const char *fn)
229230
break;
230231
}
231232
} else if (strncmp(lbuf, "output=", 7) == 0) {
233+
free((void *)chkpt_input_levent.node);
234+
chkpt_input_levent.node = NULL;
232235
if (parse_checkpt_event(lbuf, 7, &chkpt_input_levent))
233236
break;
234237
} else {

0 commit comments

Comments
 (0)