[PATCH 66/84] libselinux: selinux_status_open: handle error from

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


   This patch looks good to me. acked.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.13 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAlD+qIAACgkQrlYvE4MpobODbACgv63ix1VFIihVgIJ6j/qNXxTZ
AOUAn05ZBxuhsgn8IINUz9rZlpTIFKCS
=aXlb
-----END PGP SIGNATURE-----
>From 5ab66baf36e2158fb374dd04e39e5f61f77aa417 Mon Sep 17 00:00:00 2001
From: Eric Paris <eparis@xxxxxxxxxx>
Date: Wed, 12 Dec 2012 10:19:52 -0500
Subject: [PATCH 66/84] libselinux: selinux_status_open: handle error from
 sysconf

We didn't handle sysconf(_SC_PAGESIZE) returning an error.  It should be
very rare, obviously, be we should handle it.

Signed-off-by: Eric Paris <eparis@xxxxxxxxxx>
---
 libselinux/src/sestatus.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/libselinux/src/sestatus.c b/libselinux/src/sestatus.c
index 10a6495..3a4e658 100644
--- a/libselinux/src/sestatus.c
+++ b/libselinux/src/sestatus.c
@@ -256,19 +256,23 @@ int selinux_status_open(int fallback)
 {
 	int	fd;
 	char	path[PATH_MAX];
+	long	pagesize;
 
 	if (!selinux_mnt) {
 		errno = ENOENT;
 		return -1;
 	}
 
+	pagesize = sysconf(_SC_PAGESIZE);
+	if (pagesize < 0)
+		return -1;
+
 	snprintf(path, sizeof(path), "%s/status", selinux_mnt);
 	fd = open(path, O_RDONLY);
 	if (fd < 0)
 		goto error;
 
-	selinux_status = mmap(NULL, sysconf(_SC_PAGESIZE),
-			      PROT_READ, MAP_SHARED, fd, 0);
+	selinux_status = mmap(NULL, pagesize, PROT_READ, MAP_SHARED, fd, 0);
 	if (selinux_status == MAP_FAILED) {
 		close(fd);
 		goto error;
@@ -318,6 +322,8 @@ error:
  */
 void selinux_status_close(void)
 {
+	long pagesize;
+
 	/* not opened */
 	if (selinux_status == NULL)
 		return;
@@ -331,7 +337,10 @@ void selinux_status_close(void)
 		return;
 	}
 
-	munmap(selinux_status, sysconf(_SC_PAGESIZE));
+	pagesize = sysconf(_SC_PAGESIZE);
+	/* not much we can do other than leak memory */
+	if (pagesize > 0)
+		munmap(selinux_status, pagesize);
 	selinux_status = NULL;
 
 	close(selinux_status_fd);
-- 
1.8.1


[Index of Archives]     [Selinux Refpolicy]     [Linux SGX]     [Fedora Users]     [Fedora Desktop]     [Yosemite Photos]     [Yosemite Camping]     [Yosemite Campsites]     [KDE Users]     [Gnome Users]

  Powered by Linux