From: Tobias Stoeckmann <tobias@stoeckmann.org>
To: Karel Zak <kzak@redhat.com>
Cc: util-linux@vger.kernel.org
Subject: Re: [PATCH] Fix previously adjusted segfault patch
Date: Sat, 16 Jul 2016 12:51:42 +0200 [thread overview]
Message-ID: <20160716105142.GA2436@localhost> (raw)
In-Reply-To: <20160715111626.levjhzetw7cvldri@ws.net.home>
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>
---
This should be an easy fix without adding too much boiler-plate code.
Your macros also imply that every value would be allowed as upper limit,
but in fact it would have to be a 2^x-1 value, otherwise the bit pattern
check would turn out to be invalid.
---
text-utils/tailf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/text-utils/tailf.c b/text-utils/tailf.c
index 6219aa2..5937f73 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
--
2.9.1
next prev parent reply other threads:[~2016-07-16 10:51 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-10 14:14 [PATCH] Fix segmentation fault in tailf on 32 bit Tobias Stoeckmann
2016-07-14 10:12 ` Karel Zak
2016-07-14 19:28 ` [PATCH] Fix previously adjusted segfault patch Tobias Stoeckmann
2016-07-15 11:16 ` Karel Zak
2016-07-16 10:51 ` Tobias Stoeckmann [this message]
2016-07-19 9:05 ` Karel Zak
2016-07-19 9:49 ` [PATCH] Fix segmentation fault in tailf on 32 bit Ruediger Meier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160716105142.GA2436@localhost \
--to=tobias@stoeckmann.org \
--cc=kzak@redhat.com \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox