libsemanage: Fix logic in bunzip for uncompressed pp files
PATCH 1/1 libsemanage: Fix logic in bunzip for uncompressed pp files
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.
--- libsemanage/src/direct_api.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-)
libsemanage/src/direct_api.c +6 -9
@@ -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." );
Signature · 1 line
2.1.0
Stephen Smalley
AppliedQuoted 8 lines · Thomas Hurd
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 andmap_filecan mmap it. If the file is compressed then it will go through the BZ2 functions and any errors will be reported correctly.This fixes
0afd5de5c1edb4de2cc5e0e2e2e89551c90534fcso that a bz2 error isn't reported when a uncompressed pp is installed successfully.
Thanks, applied.
Quoted 34 lines
Signed-off-by Thomas Hurd <[email protected]>--- libsemanage/src/direct_api.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-)libsemanage/src/direct_api.c +6
-9@@ -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." );