Skip to content

Commit

Permalink
kallsyms: avoid hardcoding buffer size
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Boqun Feng authored and Miguel Ojeda committed Sep 28, 2022
1 parent b66c874 commit b471927
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions scripts/kallsyms.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,14 @@

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

#define _stringify_1(x) #x
#define _stringify(x) _stringify_1(x)

#define KSYM_NAME_LEN 128

/* A substantially bigger size than the current maximum. */
#define KSYM_NAME_LEN_BUFFER 499

struct sym_entry {
unsigned long long addr;
unsigned int len;
Expand Down Expand Up @@ -198,13 +204,13 @@ static void check_symbol_range(const char *sym, unsigned long long addr,

static struct sym_entry *read_symbol(FILE *in)
{
char name[500], type;
char name[KSYM_NAME_LEN_BUFFER+1], type;
unsigned long long addr;
unsigned int len;
struct sym_entry *sym;
int rc;

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

0 comments on commit b471927

Please sign in to comment.