Skip to content

Commit b471927

Browse files
fbqojeda
authored andcommitted
kallsyms: avoid hardcoding buffer size
This introduces `KSYM_NAME_LEN_BUFFER` in place of the previously hardcoded size of the input buffer. It will also make it easier to update the size in a single place in a later patch. Reviewed-by: Kees Cook <keescook@chromium.org> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Boqun Feng <boqun.feng@gmail.com> Co-developed-by: Miguel Ojeda <ojeda@kernel.org> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
1 parent b66c874 commit b471927

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

scripts/kallsyms.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,14 @@
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 128
3134

35+
/* A substantially bigger size than the current maximum. */
36+
#define KSYM_NAME_LEN_BUFFER 499
37+
3238
struct sym_entry {
3339
unsigned long long addr;
3440
unsigned int len;
@@ -198,13 +204,13 @@ static void check_symbol_range(const char *sym, unsigned long long addr,
198204

199205
static struct sym_entry *read_symbol(FILE *in)
200206
{
201-
char name[500], type;
207+
char name[KSYM_NAME_LEN_BUFFER+1], type;
202208
unsigned long long addr;
203209
unsigned int len;
204210
struct sym_entry *sym;
205211
int rc;
206212

207-
rc = fscanf(in, "%llx %c %499s\n", &addr, &type, name);
213+
rc = fscanf(in, "%llx %c %" _stringify(KSYM_NAME_LEN_BUFFER) "s\n", &addr, &type, name);
208214
if (rc != 3) {
209215
if (rc != EOF && fgets(name, ARRAY_SIZE(name), in) == NULL)
210216
fprintf(stderr, "Read error or end of file.\n");

0 commit comments

Comments
 (0)