summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAndrey Smirnov <andrew.smirnov@gmail.com>2019-01-28 22:55:49 -0800
committerSascha Hauer <s.hauer@pengutronix.de>2019-02-06 08:31:13 +0100
commitcd4f8f89d3f71ba3a0a29fa212f5cc2cb8793c7f (patch)
tree59d56ea7edde4c2b882785afa1b66d1b699229ed /lib
parent684a457ea462707380b9ef6cc5659835f62122ab (diff)
downloadbarebox-cd4f8f89d3f71ba3a0a29fa212f5cc2cb8793c7f.tar.gz
barebox-cd4f8f89d3f71ba3a0a29fa212f5cc2cb8793c7f.tar.xz
libfile: Fix incorrect lseek check in open_and_lseek()
We can't use "int" to capture output of lseek which is "loff_t", since former does not cover all of the range of the values of the latter and any pos >= 0xffff_ffff will result in a false positive "failure". To avoid that replace the check to check that new position matches what was requested. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/libfile.c3
1 files changed, 1 insertions, 2 deletions
diff --git a/lib/libfile.c b/lib/libfile.c
index 8f2aed2309..9a223d2328 100644
--- a/lib/libfile.c
+++ b/lib/libfile.c
@@ -556,8 +556,7 @@ int open_and_lseek(const char *filename, int mode, loff_t pos)
}
}
- ret = lseek(fd, pos, SEEK_SET);
- if (ret == -1) {
+ if (lseek(fd, pos, SEEK_SET) != pos) {
perror("lseek");
close(fd);
return -errno;