Skip to content

Commit a67cb13

Browse files
sravnborgSam Ravnborg
authored andcommitted
kconfig: fix segv fault in menuconfig
With specific configurations requesting help for certain menu lines caused menuconfig to crash. This was tracked down to a null pointer bug. Thanks to "Miles Lane" <miles.lane@gmail.com> for inital reporting and to Gabriel C <nix.or.die@googlemail.com> for the backtrace that helped me locating the bug. Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
1 parent 4887407 commit a67cb13

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

‎scripts/kconfig/mconf.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,9 @@ static void get_symbol_str(struct gstr *r, struct symbol *sym)
357357
bool hit;
358358
struct property *prop;
359359

360-
str_printf(r, "Symbol: %s [=%s]\n", sym->name,
361-
sym_get_string_value(sym));
360+
if (sym && sym->name)
361+
str_printf(r, "Symbol: %s [=%s]\n", sym->name,
362+
sym_get_string_value(sym));
362363
for_all_prompts(sym, prop)
363364
get_prompt_str(r, prop);
364365
hit = false;

‎scripts/kconfig/util.c‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,15 @@ void str_free(struct gstr *gs)
8484
/* Append to growable string */
8585
void str_append(struct gstr *gs, const char *s)
8686
{
87-
size_t l = strlen(gs->s) + strlen(s) + 1;
88-
if (l > gs->len) {
89-
gs->s = realloc(gs->s, l);
90-
gs->len = l;
87+
size_t l;
88+
if (s) {
89+
l = strlen(gs->s) + strlen(s) + 1;
90+
if (l > gs->len) {
91+
gs->s = realloc(gs->s, l);
92+
gs->len = l;
93+
}
94+
strcat(gs->s, s);
9195
}
92-
strcat(gs->s, s);
9396
}
9497

9598
/* Append printf formatted string to growable string */

0 commit comments

Comments
 (0)