==================
/* foo.c */
typedef int (*foo)(int);
int test(void) { return 0; }
EXPORT_SYMBOL(test);
static int __init foo_init(void) { return 0; }
static void __exit foo_exit(void) { return; }
module_init(foo_init);
module_exit(foo_exit);
/* foo.h */
typedef int (*foo)(int);
==================
When compiling, we could get a segmentation fault. We can also reproduce
this error by compiling a userspace program like the following:
==================
/* foo.c */
typedef int (*foo)(int);
int main() { return 0; }
/* foo.h */
typedef int (*foo)(int);
$ $ gcc -E -D__GENKSYMS__ foo.c | ./scripts/genksyms/genksyms
Segmentation fault
==================
So before generating crc32 value, check whether `name' is NULL. If so,
report the location and error message.
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
---
scripts/genksyms/genksyms.c | 6 ++++++
1 file changed, 6 insertions(+)
@@ -238,6 +238,12 @@ static struct symbol *__add_symbol(const char *name, enum symbol_type type,
return NULL;
}
+ if (!name) {
+ print_location();
+ fprintf(stderr, "Unexpected symbol with NULL name\n");
+ return NULL;
+ }
+
h = crc32(name) % HASH_BUCKETS;
for (sym = symtab[h]; sym; sym = sym->hash_next) {
if (map_to_ns(sym->type) == map_to_ns(type) &&