Skip to content

Commit 657b015

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 b207507 commit 657b015

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

scripts/kallsyms.c

Lines changed: 12 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 {
@@ -195,17 +198,23 @@ static void check_symbol_range(const char *sym, unsigned long long addr,
195198
}
196199
}
197200

201+
/*
202+
* Must be larger than KSYM_NAME_LEN, so that we know whehter a symbol is too
203+
* long.
204+
*/
205+
#define BUF_NAME_SIZE 513
206+
198207
static struct sym_entry *read_symbol(FILE *in)
199208
{
200-
char name[500], type;
209+
char name[BUF_NAME_SIZE+1], type;
201210
unsigned long long addr;
202211
unsigned int len;
203212
struct sym_entry *sym;
204213
int rc;
205214

206-
rc = fscanf(in, "%llx %c %499s\n", &addr, &type, name);
215+
rc = fscanf(in, "%llx %c %" _stringify(BUF_NAME_SIZE) "s\n", &addr, &type, name);
207216
if (rc != 3) {
208-
if (rc != EOF && fgets(name, 500, in) == NULL)
217+
if (rc != EOF && fgets(name, BUF_NAME_SIZE + 1, in) == NULL)
209218
fprintf(stderr, "Read error or end of file.\n");
210219
return NULL;
211220
}

0 commit comments

Comments
 (0)