diff options
| author | Mark Wielaard <[email protected]> | 2015-05-17 18:49:10 +0200 |
|---|---|---|
| committer | Mark Wielaard <[email protected]> | 2015-05-27 23:04:31 +0200 |
| commit | df1708a2d69dc3e58f10ed06a6475bb63bf21dcf (patch) | |
| tree | ffa91fff7b2931102b09a72c571cb4ae60c52f82 /libebl/eblopenbackend.c | |
| parent | e6261005eaa1cf19107fb8963f8cb55e2c1367a7 (diff) | |
libebl: Use static number for array stack allocation in openbackend.
Help the compiler see we stack allocate a small array. Add assert to check
no machine prefix is ever larger than 16. Current maximum number is 7.
This prevents gcc warning about possible unbounded stack usage with
-Wstack-usage.
Signed-off-by: Mark Wielaard <[email protected]>
Diffstat (limited to 'libebl/eblopenbackend.c')
| -rw-r--r-- | libebl/eblopenbackend.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/libebl/eblopenbackend.c b/libebl/eblopenbackend.c index 3a22f53d..2766e7b0 100644 --- a/libebl/eblopenbackend.c +++ b/libebl/eblopenbackend.c @@ -1,5 +1,5 @@ /* Generate ELF backend handle. - Copyright (C) 2000-2014 Red Hat, Inc. + Copyright (C) 2000-2015 Red Hat, Inc. This file is part of elfutils. This file is free software; you can redistribute it and/or modify @@ -135,6 +135,8 @@ static const struct }; #define nmachines (sizeof (machines) / sizeof (machines[0])) +/* No machine prefix should be larger than this. */ +#define MAX_PREFIX_LEN 16 /* Default callbacks. Mostly they just return the error value. */ static const char *default_object_type_name (int ignore, char *buf, @@ -343,7 +345,11 @@ openbackend (elf, emulation, machine) static const char version[] = MODVERSION; const char *modversion; ebl_bhinit_t initp; - char symname[machines[cnt].prefix_len + sizeof "_init"]; + + // We use a static number to help the compiler see we don't + // overflow the stack with an arbitrary number. + assert (machines[cnt].prefix_len <= MAX_PREFIX_LEN); + char symname[MAX_PREFIX_LEN + sizeof "_init"]; strcpy (mempcpy (symname, machines[cnt].prefix, machines[cnt].prefix_len), "_init"); |
