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>
This commit is contained in:
committed by
Daniel Borkmann
parent
8d13406c02
commit
531b014e7a
@ -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
|
||||
|
||||
|
||||
8
tools/build/feature/test-reallocarray.c
Normal file
8
tools/build/feature/test-reallocarray.c
Normal file
@ -0,0 +1,8 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
#define _GNU_SOURCE
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
return !!reallocarray(NULL, 1, 1);
|
||||
}
|
||||
Reference in New Issue
Block a user