From c76b273855915be6d11f1845b638ffd95eed5173 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Fri, 18 Oct 2024 17:12:59 +0200 Subject: [PATCH] libsemanage: check for rewind(3) failure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use fseek(3) instead of rewind(3) to detect failures. Reported-by: clang-analyzer Signed-off-by: Christian Göttsche Acked-by: James Carter --- libsemanage/src/compressed_file.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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; }