libsepol: harden availability check against user CFLAGS
PATCH 1/2 libsepol: harden availability check against user CFLAGS
From: Christian Göttsche <[email protected]>
If CFLAGS set by the user contains the warnings override -Wno-error=implicit-function-declaration the availability check does not work properly. Explicitly enable and treat this warnings as failure by appending the appropriate flag.
Also include CPPFLAGS in the check.
--- libsepol/src/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libsepol/src/Makefile +1 -1
@@ -31,7 +31,7 @@ endif # check for reallocarray(3) availability H := \# -ifeq (yes,$(shell printf '${H}include <stdlib.h>\nint main(void){return reallocarray(NULL,0,0)==NULL;}' | $(CC) $(CFLAGS) $(LDFLAGS) -x c -o /dev/null - >/dev/null 2>&1 && echo yes)) +ifeq (yes,$(shell printf '${H}include <stdlib.h>\nint main(void){return reallocarray(NULL,0,0)==NULL;}' | $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -Werror=implicit-function-declaration -x c -o /dev/null - >/dev/null 2>&1 && echo yes)) override CFLAGS += -DHAVE_REALLOCARRAY endif
Signature · 1 line
2.45.2
PATCH 2/2 libselinux: harden availability check against user CFLAGS
From: Christian Göttsche <[email protected]>
If CFLAGS set by the user contains the warnings override -Wno-error=implicit-function-declaration the availability check does not work properly. Explicitly enable and treat this warnings as failure by appending the appropriate flag.
Also include CPPFLAGS in the check.
---
Triggered by oss-fuzz which uses
afl-clang-fast -O1 -fno-omit-frame-pointer -gline-tables-only -Wno-error=enum-constexpr-conversion -Wno-error=incompatible-function-pointer-types -Wno-error=int-conversion -Wno-error=deprecated-declarations -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=vla-cxx-extension -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=address -fsanitize-address-use-after-scope
Build log:
https://oss-fuzz-build-logs.storage.googleapis.com/log-88d68963-9439-4745-9541-840f6e1f7307.txt
--- libselinux/src/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
libselinux/src/Makefile +2 -2
@@ -104,13 +104,13 @@ override CFLAGS += -I../include -D_GNU_SOURCE $(DISABLE_FLAGS) $(PCRE_CFLAGS) # check for strlcpy(3) availability H := \# -ifeq (yes,$(shell printf '${H}include <string.h>\nint main(void){char d[2];const char *s="a";return (size_t)strlcpy(d,s,sizeof(d))>=sizeof(d);}' | $(CC) $(CFLAGS) $(LDFLAGS) -x c -o /dev/null - >/dev/null 2>&1 && echo yes)) +ifeq (yes,$(shell printf '${H}include <string.h>\nint main(void){char d[2];const char *s="a";return (size_t)strlcpy(d,s,sizeof(d))>=sizeof(d);}' | $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -Werror=implicit-function-declaration -x c -o /dev/null - >/dev/null 2>&1 && echo yes)) override CFLAGS += -DHAVE_STRLCPY endif # check for reallocarray(3) availability H := \# -ifeq (yes,$(shell printf '${H}include <stdlib.h>\nint main(void){return reallocarray(NULL,0,0)==NULL;}' | $(CC) $(CFLAGS) $(LDFLAGS) -x c -o /dev/null - >/dev/null 2>&1 && echo yes)) +ifeq (yes,$(shell printf '${H}include <stdlib.h>\nint main(void){return reallocarray(NULL,0,0)==NULL;}' | $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -Werror=implicit-function-declaration -x c -o /dev/null - >/dev/null 2>&1 && echo yes)) override CFLAGS += -DHAVE_REALLOCARRAY endif
Signature · 1 line
2.45.2
Quoted 11 lines · Christian Göttsche
From: Christian Göttsche <[email protected]>
If CFLAGS set by the user contains the warnings override
-Wno-error=implicit-function-declarationthe availability check does not work properly. Explicitly enable and treat this warnings as failure by appending the appropriate flag.Also include CPPFLAGS in the check.
Signed-off-by Christian Göttsche <[email protected]>
For these two patches:
Quoted 21 lines
--- libsepol/src/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)libsepol/src/Makefile +1
-2@@ -31,7 +31,7 @@ endif # check for reallocarray(3) availability H := \# -ifeq (yes,$(shell printf '${H}include <stdlib.h>\nint main(void){return reallocarray(NULL,0,0)==NULL;}' | $(CC) $(CFLAGS) $(LDFLAGS) -x c -o /dev/null - >/dev/null 2>&1 && echo yes)) +ifeq (yes,$(shell printf '${H}include <stdlib.h>\nint main(void){return reallocarray(NULL,0,0)==NULL;}' | $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -Werror=implicit-function-declaration -x c -o /dev/null - >/dev/null 2>&1 && echo yes)) override CFLAGS += -DHAVE_REALLOCARRAY endif --2.45.2
Quoted 11 lines · James Carter
Quoted 8 lines · Christian Göttsche
From: Christian Göttsche <[email protected]>
If CFLAGS set by the user contains the warnings override
-Wno-error=implicit-function-declarationthe availability check does not work properly. Explicitly enable and treat this warnings as failure by appending the appropriate flag.
Quoted 7 lines
Quoted 3 lines
Also include CPPFLAGS in the check.
Signed-off-by Christian Göttsche <[email protected]>For these two patches:
Acked-by James Carter <[email protected]>
These two patches have been merged.
Thanks,
Jim
Quoted 21 lines
Quoted 21 lines
--- libsepol/src/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)libsepol/src/Makefile +1
-2@@ -31,7 +31,7 @@ endif # check for reallocarray(3) availability H := \# -ifeq (yes,$(shell printf '${H}include <stdlib.h>\nint main(void){return reallocarray(NULL,0,0)==NULL;}' | $(CC) $(CFLAGS) $(LDFLAGS) -x c -o /dev/null - >/dev/null 2>&1 && echo yes)) +ifeq (yes,$(shell printf '${H}include <stdlib.h>\nint main(void){return reallocarray(NULL,0,0)==NULL;}' | $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -Werror=implicit-function-declaration -x c -o /dev/null - >/dev/null 2>&1 && echo yes)) override CFLAGS += -DHAVE_REALLOCARRAY endif --2.45.2