From 85c9d36497fc3a6e82932e1cb46df2670a0b9e64 Mon Sep 17 00:00:00 2001 From: Brooks Davis Date: Wed, 3 Jan 2024 16:34:39 +0000 Subject: [PATCH] acl_equiv_mode_np: zero mode on just inited ACL You can't return 0 and not write the mode if mode_p is non-NULL. That violates the API contract and in common usage leaves stack trash in *mode_p. The acl_equiv_mode_test test passed by accident. Reviewed by: kevans, markj Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D43278 --- lib/libc/posix1e/acl_equiv_mode_np.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/libc/posix1e/acl_equiv_mode_np.c b/lib/libc/posix1e/acl_equiv_mode_np.c index b3bf5280493..333b010541e 100644 --- a/lib/libc/posix1e/acl_equiv_mode_np.c +++ b/lib/libc/posix1e/acl_equiv_mode_np.c @@ -49,7 +49,7 @@ acl_equiv_mode_np(acl_t acl, mode_t *mode_p) /* Linux returns 0 for ACL returned by acl_init() */ if (_acl_brand(acl) == ACL_BRAND_UNKNOWN && acl->ats_acl.acl_cnt == 0) - return (0); + goto done; // TODO: Do we want to handle ACL_BRAND_NFS4 in this function? */ if (_acl_brand(acl) != ACL_BRAND_POSIX) @@ -91,6 +91,7 @@ acl_equiv_mode_np(acl_t acl, mode_t *mode_p) } } +done: if (mode_p != NULL) *mode_p = ret_mode;