Skip to content

Commit

Permalink
lookup tables: fix static analyzer issue
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rgerhards committed Aug 2, 2023
1 parent b6b4f25 commit 8d36cbd
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions runtime/lookup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down

0 comments on commit 8d36cbd

Please sign in to comment.