audit/backport-second-part-of-NULL-pointer-checks.patch
2024-07-23 11:08:29 +08:00

189 lines
5.7 KiB
Diff

From 15d29a145ebe67cae52316871fcdedb5a19ce628 Mon Sep 17 00:00:00 2001
From: Yugend <jugendd@mail.ru>
Date: Fri, 15 Mar 2024 18:00:54 +0300
Subject: [PATCH] second part of NULL pointer checks
Reference:https://github.com/linux-audit/audit-userspace/commit/15d29a145ebe67cae52316871fcdedb5a19ce628
Conflict:src/ausearch-nvpair.c
---
audisp/plugins/zos-remote/zos-remote-queue.c | 5 +++++
audisp/queue.c | 5 +++++
auparse/normalize-llist.c | 3 +++
auparse/normalize.c | 9 +++++++++
lib/gen_tables.c | 10 ++++++++--
src/ausearch-lol.c | 12 ++++++++++++
src/ausearch-nvpair.c | 3 +++
src/ausearch-string.c | 3 +++
8 files changed, 48 insertions(+), 2 deletions(-)
diff --git a/audisp/plugins/zos-remote/zos-remote-queue.c b/audisp/plugins/zos-remote/zos-remote-queue.c
index 37d91bd..47dd006 100644
--- a/audisp/plugins/zos-remote/zos-remote-queue.c
+++ b/audisp/plugins/zos-remote/zos-remote-queue.c
@@ -130,6 +130,11 @@ void increase_queue_depth(unsigned int size)
void *tmp_q;
tmp_q = realloc(q, size * sizeof(BerElement *));
+ if (tmp_q == NULL) {
+ log_err("Memory allocation error");;
+ pthread_mutex_unlock(&queue_lock);
+ return;
+ }
q = tmp_q;
for (i=q_depth; i<size; i++)
q[i] = NULL;
diff --git a/audisp/queue.c b/audisp/queue.c
index b759693..bf60600 100644
--- a/audisp/queue.c
+++ b/audisp/queue.c
@@ -221,6 +221,11 @@ void increase_queue_depth(unsigned int size)
void *tmp_q;
tmp_q = realloc(q, size * sizeof(event_t *));
+ if (tmp_q == NULL) {
+ fprintf(stderr, "Memory allocation error");
+ pthread_mutex_unlock(&queue_lock);
+ return;
+ }
q = tmp_q;
for (i=q_depth; i<size; i++)
q[i] = NULL;
diff --git a/auparse/normalize-llist.c b/auparse/normalize-llist.c
index fd9d6cc..32d5f12 100644
--- a/auparse/normalize-llist.c
+++ b/auparse/normalize-llist.c
@@ -66,6 +66,9 @@ void cllist_append(cllist *l, uint32_t num, void *data)
data_node *newnode;
newnode = malloc(sizeof(data_node));
+ if (newnode == NULL) {
+ return;
+ }
newnode->num = num;
newnode->data = data;
diff --git a/auparse/normalize.c b/auparse/normalize.c
index 07c369a..eb06f6d 100644
--- a/auparse/normalize.c
+++ b/auparse/normalize.c
@@ -1061,6 +1061,11 @@ static int normalize_compound(auparse_state_t *au)
if (f) {
const char *exe = auparse_interpret_field(au);
D.how = strdup(exe);
+ if (D.how == NULL) {
+ fprintf(stderr, "Memory allocation error");
+ free((void *)syscall);
+ return 1;
+ }
if ((strncmp(D.how, "/usr/bin/python", 15) == 0) ||
(strncmp(D.how, "/usr/bin/sh", 11) == 0) ||
(strncmp(D.how, "/usr/bin/bash", 13) == 0) ||
@@ -1721,6 +1726,10 @@ map:
if (f) {
const char *exe = auparse_interpret_field(au);
D.how = strdup(exe);
+ if (D.how == NULL) {
+ fprintf(stderr, "Memory allocation error");
+ return 1;
+ }
if ((strncmp(D.how, "/usr/bin/python", 15) == 0) ||
(strncmp(D.how, "/usr/bin/sh", 11) == 0) ||
(strncmp(D.how, "/usr/bin/bash", 13) == 0) ||
diff --git a/lib/gen_tables.c b/lib/gen_tables.c
index 3326759..4ff233d 100644
--- a/lib/gen_tables.c
+++ b/lib/gen_tables.c
@@ -271,7 +271,10 @@ output_i2s(const char *prefix)
}
unique_values = malloc(NUM_VALUES * sizeof(*unique_values));
- assert(unique_values != NULL);
+ if (unique_values == NULL) {
+ fprintf(stderr, "Memory allocation error");
+ abort();
+ }
n = 0;
for (i = 0; i < NUM_VALUES; i++) {
if (n == 0 || unique_values[n - 1].val != values[i].val) {
@@ -351,7 +354,10 @@ output_i2s_transtab(const char *prefix)
printf("{%d,%zu},", values[i].val, values[i].s_offset);
}
uc_prefix = strdup(prefix);
- assert(uc_prefix != NULL);
+ if (uc_prefix == NULL) {
+ fprintf(stderr, "Memory allocation error");
+ abort();
+ }
for (i = 0; uc_prefix[i] != '\0'; i++)
uc_prefix[i] = toupper((unsigned char)uc_prefix[i]);
printf("\n"
diff --git a/src/ausearch-lol.c b/src/ausearch-lol.c
index 60fd490..97f58a1 100644
--- a/src/ausearch-lol.c
+++ b/src/ausearch-lol.c
@@ -42,6 +42,10 @@ void lol_create(lol *lo)
lo->maxi = -1;
lo->limit = ARRAY_LIMIT;
lo->array = (lolnode *)malloc(size);
+ if (lo->array == NULL) {
+ fprintf(stderr, "Memory allocation error");
+ return;
+ }
memset(lo->array, 0, size);
}
@@ -299,6 +303,10 @@ int lol_add_record(lol *lo, char *buff)
n.a1 = 0L;
n.type = e.type;
n.message = strdup(buff);
+ if(n.message == NULL) {
+ fprintf(stderr, "Memory allocation error");
+ return 0;
+ }
ptr = strchr(n.message, AUDIT_INTERP_SEPARATOR);
if (ptr) {
n.mlen = ptr - n.message;
@@ -353,6 +361,10 @@ int lol_add_record(lol *lo, char *buff)
// Create new event and fill it in
l = malloc(sizeof(llist));
+ if (l == NULL) {
+ fprintf(stderr, "Memory allocation error");
+ return 0;
+ }
list_create(l);
l->e.milli = e.milli;
l->e.sec = e.sec;
diff --git a/src/ausearch-nvpair.c b/src/ausearch-nvpair.c
index e14b16b..52a14c7 100644
--- a/src/ausearch-nvpair.c
+++ b/src/ausearch-nvpair.c
@@ -45,6 +45,9 @@ nvnode *nvlist_next(nvlist *l)
void nvlist_append(nvlist *l, nvnode *node)
{
nvnode* newnode = malloc(sizeof(nvnode));
+ if (newnode == NULL) {
+ return;
+ }
newnode->name = node->name;
newnode->val = node->val;
diff --git a/src/ausearch-string.c b/src/ausearch-string.c
index 8dbec53..bbac7be 100644
--- a/src/ausearch-string.c
+++ b/src/ausearch-string.c
@@ -66,6 +66,9 @@ void slist_append(slist *l, snode *node)
snode* newnode;
newnode = malloc(sizeof(snode));
+ if (newnode == NULL) {
+ return;
+ }
if (node->str)
newnode->str = node->str;
--
2.33.0