]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virFileInData: Report an error if unable to reposition file
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 11 Jul 2017 08:56:19 +0000 (10:56 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 19 Jul 2017 07:46:17 +0000 (09:46 +0200)
The purpose of this function is to tell if the current position
in given FD is in data section or a hole and how much bytes there
is remaining until the end of the section. This is achieved by
couple of lseeks(). The most important part is that we reposition
the FD back, so that the position is unchanged from the caller
POV. And until now the final lseek() back to the original
position was done with no check for errors. And I was convinced
that that's okay since nothing can go wrong. However, review
feedback from a related series persuaded me, that it's better to
be safe than sorry. Therefore, lets check if the final lseek()
succeeded and if it doesn't report an error.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
src/util/virfile.c

index d444b32f89358bbcb1eda4d15af94f818b49fa38..2f28e83f442f49c4251e40ae1175fd3df0764972 100644 (file)
@@ -3900,8 +3900,12 @@ virFileInData(int fd,
     ret = 0;
  cleanup:
     /* At any rate, reposition back to where we started. */
-    if (cur != (off_t) -1)
-        ignore_value(lseek(fd, cur, SEEK_SET));
+    if (cur != (off_t) -1 &&
+        lseek(fd, cur, SEEK_SET) == (off_t) -1) {
+        virReportSystemError(errno, "%s",
+                             _("unable to restore position in file"));
+        ret = -1;
+    }
     return ret;
 }