summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Stoeckmann2016-07-16 12:51:42 +0200
committerKarel Zak2016-07-19 11:01:18 +0200
commit3f0e7f371a398a5b8ef23ff94651de13f4f987d3 (patch)
treef8a8b7d3099d5d59bf9f4292d5e9044b7ad28231
parenttests: fix ttyutils test (diff)
downloadkernel-qcow2-util-linux-3f0e7f371a398a5b8ef23ff94651de13f4f987d3.tar.gz
kernel-qcow2-util-linux-3f0e7f371a398a5b8ef23ff94651de13f4f987d3.tar.xz
kernel-qcow2-util-linux-3f0e7f371a398a5b8ef23ff94651de13f4f987d3.zip
tailf: Fix previously adjusted segfault patch
Casting the value to be checked to size_t renders the check useless. If st_size is SIZE_MAX+1, it will be truncated to 0 and the check succeeds. In fact, this check can never be false because every value stored in a size_t is smaller or equal to SIZE_MAX. I think this adjustment was meant to fix a compiler warning for 64 bit systems for which sizeof(off_t) is sizeof(size_t), but the signedness differs. Going unconditionally to the greatest possible unsigned int type if st_size is positive (off_t is signed) will fix this issue. Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
-rw-r--r--text-utils/tailf.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/text-utils/tailf.c b/text-utils/tailf.c
index 6219aa218..34d0cd53b 100644
--- a/text-utils/tailf.c
+++ b/text-utils/tailf.c
@@ -284,7 +284,7 @@ int main(int argc, char **argv)
errx(EXIT_FAILURE, _("%s: is not a file"), filename);
/* mmap is based on size_t */
- if (st.st_size && (size_t) st.st_size <= SIZE_MAX)
+ if (st.st_size > 0 && (uintmax_t) st.st_size <= (uintmax_t) SIZE_MAX)
tailf(filename, lines, &st);
#ifdef HAVE_INOTIFY_INIT