mirror of
https://github.com/SELinuxProject/selinux
synced 2025-02-21 20:16:51 +00:00
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@redhat.com> Acked-by: Dan Walsh <dwalsh@redhat.com>
This commit is contained in:
parent
6064f9672c
commit
761881c947
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user