Date: Wed, 25 Oct 2006 20:52:11 GMT From: Todd Miller <millert@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 108430 for review Message-ID: <200610252052.k9PKqBgj081303@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=108430 Change 108430 by millert@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));
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200610252052.k9PKqBgj081303>