Message-ID: <550B015B.3080409@tycho.nsa.gov> Date: Thu, 19 Mar 2015 13:03:23 -0400 From: Stephen Smalley MIME-Version: 1.0 To: Thomas Hurd , selinux@tycho.nsa.gov Subject: Re: [PATCH] libsemanage: Fix logic in bunzip for uncompressed pp files References: <1426777204-9627-1-git-send-email-thurd@tresys.com> In-Reply-To: <1426777204-9627-1-git-send-email-thurd@tresys.com> Content-Type: text/plain; charset=windows-1252 List-Id: "Security-Enhanced Linux \(SELinux\) mailing list" List-Post: List-Help: On 03/19/2015 11:00 AM, Thomas Hurd wrote: > Unconditionally check the magic number before BZ2_bzReadOpen() > instead of only when bzip_blocksize=0, since it falls through. > That way if the file is not compressed it will return immediately > and map_file can mmap it. If the file is compressed then it will > go through the BZ2 functions and any errors will be reported correctly. > > This fixes 0afd5de5c1edb4de2cc5e0e2e2e89551c90534fc so that a bz2 error > isn't reported when a uncompressed pp is installed successfully. Thanks, applied. > > Signed-off-by: Thomas Hurd > --- > libsemanage/src/direct_api.c | 15 ++++++--------- > 1 file changed, 6 insertions(+), 9 deletions(-) > > diff --git a/libsemanage/src/direct_api.c b/libsemanage/src/direct_api.c > index 5922fcc..e4f168e 100644 > --- a/libsemanage/src/direct_api.c > +++ b/libsemanage/src/direct_api.c > @@ -445,16 +445,13 @@ ssize_t bunzip(semanage_handle_t *sh, FILE *f, char **data) > goto exit; > } > > - if (!sh->conf->bzip_blocksize) { > - bzerror = fread(buf, 1, BZ2_MAGICLEN, f); > - rewind(f); > - if ((bzerror != BZ2_MAGICLEN) || memcmp(buf, BZ2_MAGICSTR, BZ2_MAGICLEN)) { > - ERR(sh, "bz2 magic number not found."); > - goto exit; > - } > - /* fall through */ > + /* Check if the file is bzipped */ > + bzerror = fread(buf, 1, BZ2_MAGICLEN, f); > + rewind(f); > + if ((bzerror != BZ2_MAGICLEN) || memcmp(buf, BZ2_MAGICSTR, BZ2_MAGICLEN)) { > + goto exit; > } > - > + > b = BZ2_bzReadOpen ( &bzerror, f, 0, sh->conf->bzip_small, NULL, 0 ); > if ( bzerror != BZ_OK ) { > ERR(sh, "Failure opening bz2 archive."); >