Skip to content

Commit 9d0d266

Browse files
HONG Yifanmasahir0y
authored andcommitted
kconfig: recursive checks drop file/lineno
This prevents segfault when getting filename and lineno in recursive checks. If the following snippet is found in Kconfig: [Test code 1] config FOO bool depends on BAR select BAR ... without BAR defined; then there is a segfault. Kconfig:34:error: recursive dependency detected! Kconfig:34: symbol FOO depends on BAR make[4]: *** [scripts/kconfig/Makefile:85: allnoconfig] Segmentation fault This is because of the following. BAR is a fake entry created by sym_lookup() with prop being NULL. In the recursive check, there is a NULL check for prop to fall back to stack->sym->prop if stack->prop is NULL. However, in this case, stack->sym points to the fake BAR entry created by sym_lookup(), so prop is still NULL. prop was then referenced without additional NULL checks, causing segfault. As the previous email thread suggests, the file and lineno for select is also wrong: [Test code 2] config FOO bool config BAR bool config FOO bool "FOO" depends on BAR select BAR $ make defconfig *** Default configuration is based on 'x86_64_defconfig' Kconfig:1:error: recursive dependency detected! Kconfig:1: symbol FOO depends on BAR Kconfig:4: symbol BAR is selected by FOO [...] Kconfig:4 should be Kconfig:10. This patch deletes the wrong and segfault-prone filename/lineno inference completely. With this patch, Test code 1 yields: error: recursive dependency detected! symbol FOO depends on BAR symbol BAR is selected by FOO Signed-off-by: HONG Yifan <[email protected]> Signed-off-by: Masahiro Yamada <[email protected]>
1 parent 301c109 commit 9d0d266

File tree

2 files changed

+30
-48
lines changed

2 files changed

+30
-48
lines changed

scripts/kconfig/symbol.c

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,10 +1074,9 @@ static void sym_check_print_recursive(struct symbol *last_sym)
10741074
{
10751075
struct dep_stack *stack;
10761076
struct symbol *sym, *next_sym;
1077-
struct menu *menu = NULL;
10781077
struct menu *choice;
1079-
struct property *prop;
10801078
struct dep_stack cv_stack;
1079+
enum prop_type type;
10811080

10821081
choice = sym_get_choice_menu(last_sym);
10831082
if (choice) {
@@ -1096,53 +1095,36 @@ static void sym_check_print_recursive(struct symbol *last_sym)
10961095
for (; stack; stack = stack->next) {
10971096
sym = stack->sym;
10981097
next_sym = stack->next ? stack->next->sym : last_sym;
1099-
prop = stack->prop;
1100-
if (prop == NULL)
1101-
prop = stack->sym->prop;
1102-
1103-
/* for choice values find the menu entry (used below) */
1104-
if (sym_is_choice(sym) || sym_is_choice_value(sym)) {
1105-
for (prop = sym->prop; prop; prop = prop->next) {
1106-
menu = prop->menu;
1107-
if (prop->menu)
1108-
break;
1109-
}
1110-
}
1098+
type = stack->prop ? stack->prop->type : P_UNKNOWN;
1099+
11111100
if (stack->sym == last_sym)
1112-
fprintf(stderr, "%s:%d:error: recursive dependency detected!\n",
1113-
prop->filename, prop->lineno);
1101+
fprintf(stderr, "error: recursive dependency detected!\n");
11141102

11151103
if (sym_is_choice(next_sym)) {
11161104
choice = list_first_entry(&next_sym->menus, struct menu, link);
11171105

1118-
fprintf(stderr, "%s:%d:\tsymbol %s is part of choice block at %s:%d\n",
1119-
menu->filename, menu->lineno,
1106+
fprintf(stderr, "\tsymbol %s is part of choice block at %s:%d\n",
11201107
sym->name ? sym->name : "<choice>",
11211108
choice->filename, choice->lineno);
11221109
} else if (stack->expr == &sym->dir_dep.expr) {
1123-
fprintf(stderr, "%s:%d:\tsymbol %s depends on %s\n",
1124-
prop->filename, prop->lineno,
1110+
fprintf(stderr, "\tsymbol %s depends on %s\n",
11251111
sym->name ? sym->name : "<choice>",
11261112
next_sym->name);
11271113
} else if (stack->expr == &sym->rev_dep.expr) {
1128-
fprintf(stderr, "%s:%d:\tsymbol %s is selected by %s\n",
1129-
prop->filename, prop->lineno,
1114+
fprintf(stderr, "\tsymbol %s is selected by %s\n",
11301115
sym->name, next_sym->name);
11311116
} else if (stack->expr == &sym->implied.expr) {
1132-
fprintf(stderr, "%s:%d:\tsymbol %s is implied by %s\n",
1133-
prop->filename, prop->lineno,
1117+
fprintf(stderr, "\tsymbol %s is implied by %s\n",
11341118
sym->name, next_sym->name);
11351119
} else if (stack->expr) {
1136-
fprintf(stderr, "%s:%d:\tsymbol %s %s value contains %s\n",
1137-
prop->filename, prop->lineno,
1120+
fprintf(stderr, "\tsymbol %s %s value contains %s\n",
11381121
sym->name ? sym->name : "<choice>",
1139-
prop_get_type_name(prop->type),
1122+
prop_get_type_name(type),
11401123
next_sym->name);
11411124
} else {
1142-
fprintf(stderr, "%s:%d:\tsymbol %s %s is visible depending on %s\n",
1143-
prop->filename, prop->lineno,
1125+
fprintf(stderr, "\tsymbol %s %s is visible depending on %s\n",
11441126
sym->name ? sym->name : "<choice>",
1145-
prop_get_type_name(prop->type),
1127+
prop_get_type_name(type),
11461128
next_sym->name);
11471129
}
11481130
}
Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
1-
Kconfig:5:error: recursive dependency detected!
2-
Kconfig:5: symbol A depends on A
1+
error: recursive dependency detected!
2+
symbol A depends on A
33
For a resolution refer to Documentation/kbuild/kconfig-language.rst
44
subsection "Kconfig recursive dependency limitations"
55

6-
Kconfig:11:error: recursive dependency detected!
7-
Kconfig:11: symbol B is selected by B
6+
error: recursive dependency detected!
7+
symbol B is selected by B
88
For a resolution refer to Documentation/kbuild/kconfig-language.rst
99
subsection "Kconfig recursive dependency limitations"
1010

11-
Kconfig:17:error: recursive dependency detected!
12-
Kconfig:17: symbol C1 depends on C2
13-
Kconfig:21: symbol C2 depends on C1
11+
error: recursive dependency detected!
12+
symbol C1 depends on C2
13+
symbol C2 depends on C1
1414
For a resolution refer to Documentation/kbuild/kconfig-language.rst
1515
subsection "Kconfig recursive dependency limitations"
1616

17-
Kconfig:27:error: recursive dependency detected!
18-
Kconfig:27: symbol D1 depends on D2
19-
Kconfig:32: symbol D2 is selected by D1
17+
error: recursive dependency detected!
18+
symbol D1 depends on D2
19+
symbol D2 is selected by D1
2020
For a resolution refer to Documentation/kbuild/kconfig-language.rst
2121
subsection "Kconfig recursive dependency limitations"
2222

23-
Kconfig:37:error: recursive dependency detected!
24-
Kconfig:37: symbol E1 depends on E2
25-
Kconfig:42: symbol E2 is implied by E1
23+
error: recursive dependency detected!
24+
symbol E1 depends on E2
25+
symbol E2 is implied by E1
2626
For a resolution refer to Documentation/kbuild/kconfig-language.rst
2727
subsection "Kconfig recursive dependency limitations"
2828

29-
Kconfig:49:error: recursive dependency detected!
30-
Kconfig:49: symbol F1 default value contains F2
31-
Kconfig:51: symbol F2 depends on F1
29+
error: recursive dependency detected!
30+
symbol F1 default value contains F2
31+
symbol F2 depends on F1
3232
For a resolution refer to Documentation/kbuild/kconfig-language.rst
3333
subsection "Kconfig recursive dependency limitations"
3434

35-
Kconfig:60:error: recursive dependency detected!
36-
Kconfig:60: symbol G depends on G
35+
error: recursive dependency detected!
36+
symbol G depends on G
3737
For a resolution refer to Documentation/kbuild/kconfig-language.rst
3838
subsection "Kconfig recursive dependency limitations"

0 commit comments

Comments
 (0)