Skip to content

Commit c9d2301

Browse files
committed
Harden against a couple memory issues
Hardened plist_append to free the freshly allocated node when duplicating the plugin configuration fails, avoiding a dangling pointer assignment. Updated cleanup_event to respect the optional event_is_prealloc hook before freeing events, preventing accidental frees of pooled objects. Ensured client messages are NUL-terminated within buffer bounds by clamping the termination index before modifying the header buffer.
1 parent 8062a3a commit c9d2301

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

audisp/audispd-llist.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,13 @@ int plist_append(conf_llist *l, plugin_conf_t *p)
7979

8080
if (p) {
8181
void *pp = malloc(sizeof(struct plugin_conf));
82-
if (pp)
82+
if (pp) {
8383
memcpy(pp, p, sizeof(struct plugin_conf));
84-
newnode->p = pp;
84+
newnode->p = pp;
85+
} else {
86+
free(newnode);
87+
return 1;
88+
}
8589
} else
8690
newnode->p = NULL;
8791

src/auditd-event.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,9 @@ void cleanup_event(struct auditd_event *e)
580580
// into the middle of the reply allocation. Check for it.
581581
if (e->reply.message != e->reply.msg.data)
582582
free((void *)e->reply.message);
583-
if (!event_is_prealloc || !event_is_prealloc(e))
583+
if (!event_is_prealloc)
584+
free(e);
585+
else if (!event_is_prealloc(e))
584586
free(e);
585587
}
586588

src/auditd-listen.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -564,10 +564,17 @@ static void client_message (struct ev_tcp *io, unsigned int length,
564564
if (AUDIT_RMW_IS_MAGIC (header, length)) {
565565
AUDIT_RMW_UNPACK_HEADER (header, hver, mver, type, mlen, seq)
566566

567-
ch = header[length];
568-
header[length] = 0;
569-
if (length > 1 && header[length-1] == '\n')
570-
header[length-1] = 0;
567+
size_t term_idx;
568+
569+
if (length >= MAX_AUDIT_MESSAGE_LENGTH)
570+
term_idx = MAX_AUDIT_MESSAGE_LENGTH - 1;
571+
else
572+
term_idx = length;
573+
574+
ch = header[term_idx];
575+
header[term_idx] = 0;
576+
if (term_idx > 1 && header[term_idx-1] == '\n')
577+
header[term_idx-1] = 0;
571578
if (type == AUDIT_RMW_TYPE_HEARTBEAT) {
572579
unsigned char ack[AUDIT_RMW_HEADER_SIZE];
573580
AUDIT_RMW_PACK_HEADER (ack, 0, AUDIT_RMW_TYPE_ACK,
@@ -580,7 +587,7 @@ static void client_message (struct ev_tcp *io, unsigned int length,
580587
if (e)
581588
distribute_event(e);
582589
}
583-
header[length] = ch;
590+
header[term_idx] = ch;
584591
}
585592
}
586593

0 commit comments

Comments
 (0)