diff mbox series

[3/4] libsemanage: check for rewind(3) failure

Message ID 20241018151300.445618-3-cgoettsche@seltendoof.de (mailing list archive)
State Accepted
Commit c76b27385591
Headers show
Series [1/4] libselinux: avoid errno modification by fclose(3) | expand

Commit Message

Christian Göttsche Oct. 18, 2024, 3:12 p.m. UTC
From: Christian Göttsche <cgzones@googlemail.com>

Use fseek(3) instead of rewind(3) to detect failures.

Reported-by: clang-analyzer
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
---
 libsemanage/src/compressed_file.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/libsemanage/src/compressed_file.c b/libsemanage/src/compressed_file.c
index 5546b830..e230a70b 100644
--- a/libsemanage/src/compressed_file.c
+++ b/libsemanage/src/compressed_file.c
@@ -114,7 +114,12 @@  static ssize_t bunzip(semanage_handle_t *sh, FILE *f, void **data)
 
 	/* Check if the file is bzipped */
 	bzerror = fread(buf, 1, BZ2_MAGICLEN, f);
-	rewind(f);
+
+	if (fseek(f, 0L, SEEK_SET) == -1) {
+		ERR(sh, "Failure rewinding file.");
+		goto exit;
+	}
+
 	if ((bzerror != BZ2_MAGICLEN) || memcmp(buf, BZ2_MAGICSTR, BZ2_MAGICLEN)) {
 		goto exit;
 	}