]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
fortify: Ensure that __glibc_fortify condition is a constant [BZ #29141]
authorSiddhesh Poyarekar <siddhesh@sourceware.org>
Fri, 13 May 2022 04:31:47 +0000 (10:01 +0530)
committerSiddhesh Poyarekar <siddhesh@sourceware.org>
Mon, 16 May 2022 14:40:08 +0000 (20:10 +0530)
The fix c8ee1c85 introduced a -1 check for object size without also
checking that object size is a constant.  Because of this, the tree
optimizer passes in gcc fail to fold away one of the branches in
__glibc_fortify and trips on a spurious Wstringop-overflow.  The warning
itself is incorrect and the branch does go away eventually in DCE in the
rtl passes in gcc, but the constant check is a helpful hint to simplify
code early, so add it in.

Resolves: BZ #29141
Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
misc/sys/cdefs.h

index f1faf8292c449182e073eaecba708d4627dd4c5a..1c2b044a0d27da18709a95f1ccecdf556434b173 100644 (file)
 /* Length is known to be safe at compile time if the __L * __S <= __OBJSZ
    condition can be folded to a constant and if it is true, or unknown (-1) */
 #define __glibc_safe_or_unknown_len(__l, __s, __osz) \
-  ((__osz) == (__SIZE_TYPE__) -1                                             \
+  ((__builtin_constant_p (__osz) && (__osz) == (__SIZE_TYPE__) -1)           \
    || (__glibc_unsigned_or_positive (__l)                                    \
        && __builtin_constant_p (__glibc_safe_len_cond ((__SIZE_TYPE__) (__l), \
                                                       (__s), (__osz)))       \