Skip to contentSkip to conversation

libsemanage: Fix logic in bunzip for uncompressed pp files

PATCH Applied Thomas Hurd 2 participants 2 messages Mar 19, 2015 SELinux security module

lore
Share & tools
lore
#0 lore raw

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
index 5922fcc..e4f168e 100644
@@ -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
#1 lore raw
Quoted 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 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.

Quoted 34 lines
---
 libsemanage/src/direct_api.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
libsemanage/src/direct_api.c +6 -9
index 5922fcc..e4f168e 100644
@@ -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.");