From: Paul Mundt Date: Tue, 22 Sep 2009 23:44:12 +0000 (-0700) Subject: kallsyms: fix segfault in prefix_underscores_count() X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=a9ece53c4089ef23d4002d34c4c7148d94622a40;p=GitHub%2FLineageOS%2FG12%2Fandroid_kernel_amlogic_linux-4.9.git kallsyms: fix segfault in prefix_underscores_count() Commit b478b782e110fdb4135caa3062b6d687e989d994 "kallsyms, tracing: output more proper symbol name" introduces a "bugfix" that introduces a segfault in kallsyms in my configurations. The cause is the introduction of prefix_underscores_count() which attempts to count underscores, even in symbols that do not have them. As a result, it just uselessly runs past the end of the buffer until it crashes: CC init/version.o LD init/built-in.o LD .tmp_vmlinux1 KSYM .tmp_kallsyms1.S /bin/sh: line 1: 16934 Done sh-linux-gnu-nm -n .tmp_vmlinux1 16935 Segmentation fault | scripts/kallsyms > .tmp_kallsyms1.S make: *** [.tmp_kallsyms1.S] Error 139 This simplifies the logic and just does a straightforward count. Signed-off-by: Paul Mundt Reviewed-by: Li Zefan Cc: Lai Jiangshan Cc: Sam Ravnborg Cc: Paulo Marques Cc: Ingo Molnar Cc: [2.6.30.x, 2.6.31.x] Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c index 64343cc084b4..86c3896a1e01 100644 --- a/scripts/kallsyms.c +++ b/scripts/kallsyms.c @@ -585,7 +585,7 @@ static int prefix_underscores_count(const char *str) { const char *tail = str; - while (*tail != '_') + while (*tail == '_') tail++; return tail - str;