diff options
author | Jakub Kicinski <jakub.kicinski@netronome.com> | 2018-07-10 23:43:05 +0200 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2018-07-11 22:13:34 +0200 |
commit | 531b014e7a2fedaeff0b19b2934d830cd4b35dc0 (patch) | |
tree | 0de8355e9d533b4f6f90c3b389f58c992e75bb14 /tools/build | |
parent | tools: libbpf: move library error code into a separate file (diff) | |
download | linux-531b014e7a2fedaeff0b19b2934d830cd4b35dc0.tar.xz linux-531b014e7a2fedaeff0b19b2934d830cd4b35dc0.zip |
tools: bpf: make use of reallocarray
reallocarray() is a safer variant of realloc which checks for
multiplication overflow in case of array allocation. Since it's
not available in Glibc < 2.26 import kernel's overflow.h and
add a static inline implementation when needed. Use feature
detection to probe for existence of reallocarray.
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com>
Reviewed-by: Jiong Wang <jiong.wang@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'tools/build')
-rw-r--r-- | tools/build/feature/Makefile | 4 | ||||
-rw-r--r-- | tools/build/feature/test-reallocarray.c | 8 |
2 files changed, 12 insertions, 0 deletions
diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile index dac9563b5470..0516259be70f 100644 --- a/tools/build/feature/Makefile +++ b/tools/build/feature/Makefile @@ -14,6 +14,7 @@ FILES= \ test-libaudit.bin \ test-libbfd.bin \ test-disassembler-four-args.bin \ + test-reallocarray.bin \ test-liberty.bin \ test-liberty-z.bin \ test-cplus-demangle.bin \ @@ -204,6 +205,9 @@ $(OUTPUT)test-libbfd.bin: $(OUTPUT)test-disassembler-four-args.bin: $(BUILD) -DPACKAGE='"perf"' -lbfd -lopcodes +$(OUTPUT)test-reallocarray.bin: + $(BUILD) + $(OUTPUT)test-liberty.bin: $(CC) $(CFLAGS) -Wall -Werror -o $@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty diff --git a/tools/build/feature/test-reallocarray.c b/tools/build/feature/test-reallocarray.c new file mode 100644 index 000000000000..8170de35150d --- /dev/null +++ b/tools/build/feature/test-reallocarray.c @@ -0,0 +1,8 @@ +// SPDX-License-Identifier: GPL-2.0 +#define _GNU_SOURCE +#include <stdlib.h> + +int main(void) +{ + return !!reallocarray(NULL, 1, 1); +} |