selinux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] libselinux: selinux_getenforcemode: remove out2 label
@ 2025-07-27 15:44 Rahul Sandhu
  2025-07-27 15:55 ` [PATCH v2] libselinux: remove out2 labels Rahul Sandhu
  0 siblings, 1 reply; 4+ messages in thread
From: Rahul Sandhu @ 2025-07-27 15:44 UTC (permalink / raw)
  To: selinux; +Cc: Rahul Sandhu

The out2 label previously only existed such that free(buf) isn't called
if malloc(3) fails to allocate buf. However, posix says[1] that calling
free(3) with a nullptr is valid:

> If ptr is a null pointer, no action shall occur.

Hence, remove the extra label to simplify the logic.

[1] https://pubs.opengroup.org/onlinepubs/009604499/functions/free.html

Signed-off-by: Rahul Sandhu <nvraxn@gmail.com>
---
 libselinux/src/compute_create.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/libselinux/src/compute_create.c b/libselinux/src/compute_create.c
index ff8553bc..b0c6ea34 100644
--- a/libselinux/src/compute_create.c
+++ b/libselinux/src/compute_create.c
@@ -81,34 +81,33 @@ int security_compute_create_name_raw(const char * scon,
 	if (len < 0 || (size_t)len >= size) {
 		errno = EOVERFLOW;
 		ret = -1;
-		goto out2;
+		goto out;
 	}
 
 	if (objname &&
 	    object_name_encode(objname, buf + len, size - len) < 0) {
 		errno = ENAMETOOLONG;
 		ret = -1;
-		goto out2;
+		goto out;
 	}
 
 	ret = write(fd, buf, strlen(buf));
 	if (ret < 0)
-		goto out2;
+		goto out;
 
 	memset(buf, 0, size);
 	ret = read(fd, buf, size - 1);
 	if (ret < 0)
-		goto out2;
+		goto out;
 
 	*newcon = strdup(buf);
 	if (!(*newcon)) {
 		ret = -1;
-		goto out2;
+		goto out;
 	}
 	ret = 0;
-      out2:
-	free(buf);
       out:
+	free(buf);
 	close(fd);
 	return ret;
 }
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-07-31 14:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-27 15:44 [PATCH] libselinux: selinux_getenforcemode: remove out2 label Rahul Sandhu
2025-07-27 15:55 ` [PATCH v2] libselinux: remove out2 labels Rahul Sandhu
2025-07-29 14:51   ` Stephen Smalley
2025-07-31 14:16     ` Stephen Smalley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).