git: 155541825168 - stable/13 - libcasper: Neuter false positive -Wuse-after-free warnings from GCC 13

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Sat, 30 Nov 2024 19:09:04 UTC
The branch stable/13 has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=15554182516806b79859b867151f4d4fe58ae6e2

commit 15554182516806b79859b867151f4d4fe58ae6e2
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2023-11-15 02:34:01 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2024-11-30 17:40:08 +0000

    libcasper: Neuter false positive -Wuse-after-free warnings from GCC 13
    
    GCC 13 incorrectly thinks a call to free after a failed realloc is a
    use after free.
    
    lib/libcasper/services/cap_grp/cap_grp.c: In function 'group_resize':
    lib/libcasper/services/cap_grp/cap_grp.c:65:17: error: pointer 'buf' may be used after 'realloc' [-Werror=use-after-free]
       65 |                 free(buf);
          |                 ^~~~~~~~~
    lib/libcasper/services/cap_grp/cap_grp.c:63:19: note: call to 'realloc' here
       63 |         gbuffer = realloc(buf, gbufsize);
          |                   ^~~~~~~~~~~~~~~~~~~~~~
    
    Reviewed by:    imp, emaste
    Differential Revision:  https://reviews.freebsd.org/D42576
    
    (cherry picked from commit b7f7cc25c01aeacaafb86ebcffdeb258b7933b08)
---
 lib/libcasper/services/cap_grp/Makefile | 3 +++
 lib/libcasper/services/cap_pwd/Makefile | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/lib/libcasper/services/cap_grp/Makefile b/lib/libcasper/services/cap_grp/Makefile
index ee3bdd491895..107be5d7cb46 100644
--- a/lib/libcasper/services/cap_grp/Makefile
+++ b/lib/libcasper/services/cap_grp/Makefile
@@ -40,3 +40,6 @@ MLINKS+=cap_grp.3 cap_grp_limit_fields.3
 MLINKS+=cap_grp.3 cap_grp_limit_groups.3
 
 .include <bsd.lib.mk>
+
+# GCC 13 complains incorrectly about free after failed realloc: GCC bug #110501
+CFLAGS.cap_grp.c+= ${NO_WUSE_AFTER_FREE}
diff --git a/lib/libcasper/services/cap_pwd/Makefile b/lib/libcasper/services/cap_pwd/Makefile
index 9aaaeb071ca0..bd488bcb42fe 100644
--- a/lib/libcasper/services/cap_pwd/Makefile
+++ b/lib/libcasper/services/cap_pwd/Makefile
@@ -40,3 +40,6 @@ MLINKS+=cap_pwd.3 cap_pwd_limit_fields.3
 MLINKS+=cap_pwd.3 cap_pwd_limit_users.3
 
 .include <bsd.lib.mk>
+
+# GCC 13 complains incorrectly about free after failed realloc: GCC bug #110501
+CFLAGS.cap_pwd.c+= ${NO_WUSE_AFTER_FREE}