PERFORCE change 108430 for review

Todd Miller millert at FreeBSD.org
Wed Oct 25 13:58:05 PDT 2006


http://perforce.freebsd.org/chv.cgi?CH=108430

Change 108430 by millert at millert_macbook on 2006/10/25 20:51:46

	No need to allocate memory and read in the migscs file, just mmap it.

Affected files ...

.. //depot/projects/trustedbsd/sedarwin8/policies/sedarwin/libselinux/src/load_migscs.c#3 edit

Differences ...

==== //depot/projects/trustedbsd/sedarwin8/policies/sedarwin/libselinux/src/load_migscs.c#3 (text+ko) ====

@@ -1,28 +1,33 @@
+#include <sys/param.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
 #include <errno.h>
 #include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
+#include <limits.h>
 #include <security/mac.h>
 #include <sedarwin/sebsd_syscalls.h>
 
 int
 selinux_load_migscs(const char *path)
 {
-        FILE           *fp;
+	struct stat	sb;
+	int		fd;
 	void	       *data;
         struct lp_args  la;
 
-        fp = fopen (path, "rb");
-        if (fp == NULL)
-                return errno;
+        fd = open(path, O_RDONLY, 0644);
+        if (fd == -1 || fstat(fd, &sb) == -1)
+                return (-1);
+
+	if (sb.st_size > SIZE_MAX) {
+		errno = EFBIG;
+		return (-1);
+	}
+        la.len = sb.st_size;
 
-        fseek(fp, 0, SEEK_END);
-        la.len = ftell(fp);
-        fseek(fp, 0, SEEK_SET);
-        if ((data = malloc(la.len)) == NULL)
-                return (ENOMEM);
-        if (fread(data, la.len, 1, fp) != 1)
-                return (EIO);
+        data = mmap(NULL, la.len, PROT_READ, MAP_FILE, fd, 0);
+	if (data == MAP_FAILED)
+                return (-1);
 
 	la.data = CAST_USER_ADDR_T(data);
         return (mac_syscall("sebsd", SEBSDCALL_LOAD_MIGSCS, &la));


More information about the trustedbsd-cvs mailing list