Skip to content

Commit d895436

Browse files
committed
script: kallsyms: Use the correct buffer size for symbols
The buffered name size should be larger than KSYM_NAME_LEN, otherwise we cannot tell whether the size of a symbol name is too long. Signed-off-by: Boqun Feng <[email protected]>
1 parent 7dff751 commit d895436

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

scripts/kallsyms.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727

2828
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
2929

30+
#define _stringify_1(x) #x
31+
#define _stringify(x) _stringify_1(x)
32+
3033
#define KSYM_NAME_LEN 512
3134

3235
struct sym_entry {
@@ -197,15 +200,15 @@ static void check_symbol_range(const char *sym, unsigned long long addr,
197200

198201
static struct sym_entry *read_symbol(FILE *in)
199202
{
200-
char name[500], type;
203+
char name[KSYM_NAME_LEN+1], type;
201204
unsigned long long addr;
202205
unsigned int len;
203206
struct sym_entry *sym;
204207
int rc;
205208

206-
rc = fscanf(in, "%llx %c %499s\n", &addr, &type, name);
209+
rc = fscanf(in, "%llx %c %" _stringify(KSYM_NAME_LEN) "s\n", &addr, &type, name);
207210
if (rc != 3) {
208-
if (rc != EOF && fgets(name, 500, in) == NULL)
211+
if (rc != EOF && fgets(name, KSYM_NAME_LEN + 1, in) == NULL)
209212
fprintf(stderr, "Read error or end of file.\n");
210213
return NULL;
211214
}

0 commit comments

Comments
 (0)