rsyslog/backport-lookup-tables-fix-static-analyzer-issue.patch
Qiumiao Zhang b83e0b1c2a backport patches from upstream
Signed-off-by: Qiumiao Zhang <zhangqiumiao1@huawei.com>
2024-03-21 03:38:16 +00:00

58 lines
2.3 KiB
Diff

From 8d36cbd29d8db7091e13dd8d720b744c7399acf2 Mon Sep 17 00:00:00 2001
From: Rainer Gerhards <rgerhards@adiscon.com>
Date: Wed, 2 Aug 2023 13:20:47 +0200
Subject: [PATCH] lookup tables: fix static analyzer issue
If something goes really wrong, a lookup table's name would not
be set. That could lead to a NULL pointer access. HOWEVER, this
would require serious bugs in config parameter parsing, as the
lookup table name is a required parameter and the parser will
error out if not set.
So the bug is mostly cosmetic - but it does not hurt to handle
this case, of course.
Reference:https://github.com/rsyslog/rsyslog/commit/8d36cbd29d8db7091e13dd8d720b744c7399acf2
Conflict:NA
---
runtime/lookup.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/runtime/lookup.c b/runtime/lookup.c
index d9ee53b7ad..44085818c2 100644
--- a/runtime/lookup.c
+++ b/runtime/lookup.c
@@ -1037,11 +1037,18 @@ lookupTableDefProcessCnf(struct cnfobj *o)
"param '%s'\n", modpblk.descr[i].name);
}
}
+ const uchar *const lu_name = lu->name; /* we need a const to keep TSAN happy :-( */
+ const uchar *const lu_filename = lu->filename; /* we need a const to keep TSAN happy :-( */
+ if(lu_name == NULL || lu_filename == NULL) {
+ iRet = RS_RET_INTERNAL_ERROR;
+ LogError(0, iRet, "internal error: lookup table name not set albeit being mandatory");
+ ABORT_FINALIZE(iRet);
+ }
#ifdef HAVE_PTHREAD_SETNAME_NP
- thd_name_len = ustrlen(lu->name) + strlen(reloader_prefix) + 1;
+ thd_name_len = ustrlen(lu_name) + strlen(reloader_prefix) + 1;
CHKmalloc(reloader_thd_name = malloc(thd_name_len));
strcpy(reloader_thd_name, reloader_prefix);
- strcpy(reloader_thd_name + strlen(reloader_prefix), (char*) lu->name);
+ strcpy(reloader_thd_name + strlen(reloader_prefix), (char*) lu_name);
reloader_thd_name[thd_name_len - 1] = '\0';
#if defined(__NetBSD__)
pthread_setname_np(lu->reloader, "%s", reloader_thd_name);
@@ -1051,9 +1058,9 @@ lookupTableDefProcessCnf(struct cnfobj *o)
pthread_setname_np(lu->reloader, reloader_thd_name);
#endif
#endif
- CHKiRet(lookupReadFile(lu->self, lu->name, lu->filename));
+ CHKiRet(lookupReadFile(lu->self, lu_name, lu_filename));
LogMsg(0, RS_RET_OK, LOG_INFO, "lookup table '%s' loaded from file '%s'",
- lu->name, lu->filename);
+ lu_name, lu->filename);
finalize_it:
#ifdef HAVE_PTHREAD_SETNAME_NP