Blame SOURCES/0017-Check-lseek-for-errors.patch

5fb29d
From 3cdcc7ef32e90c411d7f4e14a896f9bf7afa4f29 Mon Sep 17 00:00:00 2001
5fb29d
From: Peter Jones <pjones@redhat.com>
5fb29d
Date: Wed, 10 Sep 2014 16:56:49 -0400
5fb29d
Subject: [PATCH 17/18] Check lseek() for errors.
5fb29d
5fb29d
Covscan.
5fb29d
5fb29d
Signed-off-by: Peter Jones <pjones@redhat.com>
5fb29d
---
5fb29d
 src/lib/gpt.c | 8 ++++++--
5fb29d
 1 file changed, 6 insertions(+), 2 deletions(-)
5fb29d
5fb29d
diff --git a/src/lib/gpt.c b/src/lib/gpt.c
5fb29d
index 67a8c41..fc2acf3 100644
5fb29d
--- a/src/lib/gpt.c
5fb29d
+++ b/src/lib/gpt.c
5fb29d
@@ -221,6 +221,7 @@ read_lba(int fd, uint64_t lba, void *buffer, size_t bytes)
5fb29d
         void *iobuf;
5fb29d
         size_t iobuf_size;
5fb29d
         int rc;
5fb29d
+	off_t new_offset;
5fb29d
 
5fb29d
         iobuf_size = lcm(bytes, sector_size);
5fb29d
         rc = posix_memalign(&iobuf, sector_size, iobuf_size);
5fb29d
@@ -228,8 +229,11 @@ read_lba(int fd, uint64_t lba, void *buffer, size_t bytes)
5fb29d
                 return rc;
5fb29d
         memset(iobuf, 0, bytes);
5fb29d
 
5fb29d
-
5fb29d
-        lseek(fd, offset, SEEK_SET);
5fb29d
+        new_offset = lseek(fd, offset, SEEK_SET);
5fb29d
+	if (new_offset == (off_t)-1) {
5fb29d
+		free(iobuf);
5fb29d
+		return 0;
5fb29d
+	}
5fb29d
         bytesread = read(fd, iobuf, iobuf_size);
5fb29d
         memcpy(buffer, iobuf, bytes);
5fb29d
         free(iobuf);
5fb29d
-- 
5fb29d
1.9.3
5fb29d