Blame SOURCES/0246-coverity-Check-return-value-of-fstat-call-def31.patch

28bab8
From 29f2027d3ac1cc26d1e21fb91bcc0714d1bec12a Mon Sep 17 00:00:00 2001
28bab8
From: Martin Kutlak <mkutlak@redhat.com>
28bab8
Date: Mon, 20 Aug 2018 15:08:33 +0000
28bab8
Subject: [PATCH] coverity: Check return value of fstat call #def31
28bab8
28bab8
Signed-off-by: Martin Kutlak <mkutlak@redhat.com>
28bab8
28bab8
28bab8
(cherry picked from commit 78e0ba4ce8d2e31c67e026f32279ad9f46a387f5)
28bab8
---
28bab8
 src/lib/read_write.c | 4 ++--
28bab8
 1 file changed, 2 insertions(+), 2 deletions(-)
28bab8
28bab8
diff --git a/src/lib/read_write.c b/src/lib/read_write.c
28bab8
index 7ce2097..bd8bbe8 100644
28bab8
--- a/src/lib/read_write.c
28bab8
+++ b/src/lib/read_write.c
28bab8
@@ -133,8 +133,8 @@ void* xmalloc_read(int fd, size_t *maxsz_p)
28bab8
     /* Estimate file size */
28bab8
     {
28bab8
         struct stat st;
28bab8
-        st.st_size = 0; /* in case fstat fails, assume 0 */
28bab8
-        fstat(fd, &st);
28bab8
+        if (fstat(fd, &st) != 0)
28bab8
+            st.st_size = 0; /* in case fstat fails, assume 0 */
28bab8
         /* /proc/N/stat files report st_size 0 */
28bab8
         /* In order to make such files readable, we add small const (4k) */
28bab8
         size = (st.st_size | 0xfff) + 1;
28bab8
-- 
28bab8
2.21.0
28bab8