Fix NULL-dereference crash with some command line options (#1567)

It is possible to crash freshclam and probably other programs like this:
```
freshclam --datadir /any/path
```

CLAM-2860
This commit is contained in:
Val S. 2025-09-15 18:16:09 -04:00 committed by GitHub
parent bae86fd272
commit 1d158c13d4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1253,15 +1253,17 @@ struct optstruct *optparse(const char *cfgfile, int argc, char **argv, int verbo
}
}
/* Find and remove inline comments. */
numarg = -1;
inlinecomment = strchr(arg, '#');
if (inlinecomment != NULL) {
/* Found a '#', indicating an inline comment. Strip it off along with any leading spaces or tabs. */
arg = strtok(arg, "#");
trim_comment = arg + strlen(arg) - 1;
while (trim_comment >= arg && (*trim_comment == ' ' || *trim_comment == '\t')) {
*(trim_comment--) = '\0';
if (NULL != arg) {
/* Find and remove inline comments. */
numarg = -1;
inlinecomment = strchr(arg, '#');
if (inlinecomment != NULL) {
/* Found a '#', indicating an inline comment. Strip it off along with any leading spaces or tabs. */
arg = strtok(arg, "#");
trim_comment = arg + strlen(arg) - 1;
while (trim_comment >= arg && (*trim_comment == ' ' || *trim_comment == '\t')) {
*(trim_comment--) = '\0';
}
}
}