From owner-p4-projects@FreeBSD.ORG Wed Oct 25 20:53:23 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 719D616A4CA; Wed, 25 Oct 2006 20:53:23 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 2CC7616A4C8 for ; Wed, 25 Oct 2006 20:53:23 +0000 (UTC) (envelope-from millert@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8F13243DEF for ; Wed, 25 Oct 2006 20:52:11 +0000 (GMT) (envelope-from millert@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id k9PKqBZK081307 for ; Wed, 25 Oct 2006 20:52:11 GMT (envelope-from millert@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id k9PKqBgj081303 for perforce@freebsd.org; Wed, 25 Oct 2006 20:52:11 GMT (envelope-from millert@freebsd.org) Date: Wed, 25 Oct 2006 20:52:11 GMT Message-Id: <200610252052.k9PKqBgj081303@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to millert@freebsd.org using -f From: Todd Miller To: Perforce Change Reviews Cc: Subject: PERFORCE change 108430 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Oct 2006 20:53:23 -0000 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 +#include +#include #include #include -#include -#include +#include #include #include 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));