c5d972
commit 61a87530108ec9181e1b18a9b727ec3cc3ba7532
c5d972
Author: Siddhesh Poyarekar <siddhesh@sourceware.org>
c5d972
Date:   Fri May 13 10:01:47 2022 +0530
c5d972
c5d972
    fortify: Ensure that __glibc_fortify condition is a constant [BZ #29141]
c5d972
    
c5d972
    The fix c8ee1c85 introduced a -1 check for object size without also
c5d972
    checking that object size is a constant.  Because of this, the tree
c5d972
    optimizer passes in gcc fail to fold away one of the branches in
c5d972
    __glibc_fortify and trips on a spurious Wstringop-overflow.  The warning
c5d972
    itself is incorrect and the branch does go away eventually in DCE in the
c5d972
    rtl passes in gcc, but the constant check is a helpful hint to simplify
c5d972
    code early, so add it in.
c5d972
    
c5d972
    Resolves: BZ #29141
c5d972
    Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
c5d972
c5d972
diff --git a/misc/sys/cdefs.h b/misc/sys/cdefs.h
c5d972
index 404496c7d6da4fb3..f3d7efdd2a9320f7 100644
c5d972
--- a/misc/sys/cdefs.h
c5d972
+++ b/misc/sys/cdefs.h
c5d972
@@ -145,7 +145,7 @@
c5d972
 /* Length is known to be safe at compile time if the __L * __S <= __OBJSZ
c5d972
    condition can be folded to a constant and if it is true, or unknown (-1) */
c5d972
 #define __glibc_safe_or_unknown_len(__l, __s, __osz) \
c5d972
-  ((__osz) == (__SIZE_TYPE__) -1					      \
c5d972
+  ((__builtin_constant_p (__osz) && (__osz) == (__SIZE_TYPE__) -1)	      \
c5d972
    || (__glibc_unsigned_or_positive (__l)				      \
c5d972
        && __builtin_constant_p (__glibc_safe_len_cond ((__SIZE_TYPE__) (__l), \
c5d972
 						       (__s), (__osz)))	      \