Skip to content

Commit 4afbe3b

Browse files
committed
if-options: fix NULL dereference on missing variable name
strskipwhite() returns NULL when the remainder of a define/define6/ definend line is empty or whitespace-only (e.g. a trailing escaped space protected from the config trim). parse_option() then called strcasecmp(NULL, "reserved") and crashed. Treat a NULL variable name the same as an absent one: error out for types that require a name and accept np == NULL for OT_OPTION. Reproducer: a config line 'define 119 string=x\\ ' (escaped trailing space) segfaults at strcasecmp in parse_option (if-options.c:2120). Fixes #731.
1 parent 42ca579 commit 4afbe3b

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

‎src/if-options.c‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2117,7 +2117,13 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
21172117
fp = strwhite(arg);
21182118
if (fp)
21192119
*fp++ = '\0';
2120-
if (strcasecmp(arg, "reserved")) {
2120+
if (arg == NULL) {
2121+
if (!(t & OT_OPTION)) {
2122+
logerrx("type requires a variable name");
2123+
return -1;
2124+
}
2125+
np = NULL;
2126+
} else if (strcasecmp(arg, "reserved")) {
21212127
np = strdup(arg);
21222128
if (np == NULL) {
21232129
logerr(__func__);

0 commit comments

Comments
 (0)