Util-Linux package development
 help / color / mirror / Atom feed
From: Tobias Stoeckmann <tobias@stoeckmann.org>
To: Karel Zak <kzak@redhat.com>
Cc: util-linux@vger.kernel.org
Subject: [PATCH] Fix previously adjusted segfault patch
Date: Thu, 14 Jul 2016 21:28:34 +0200	[thread overview]
Message-ID: <20160714192834.GA3861@localhost> (raw)
In-Reply-To: <20160714101215.ckr3tl22fmpcumwa@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. One possibility is to do a "binary and" operation with the
value SIZE_MAX. If the original value and the and-operated value differ,
it means that a higher bit was set and therefore the file was too large.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
---
 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..5ddbee9 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 && st.st_size == (st.st_size & SIZE_MAX))
 		tailf(filename, lines, &st);
 
 #ifdef HAVE_INOTIFY_INIT
-- 
2.9.0


  reply	other threads:[~2016-07-14 19:28 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   ` Tobias Stoeckmann [this message]
2016-07-15 11:16     ` [PATCH] Fix previously adjusted segfault patch Karel Zak
2016-07-16 10:51       ` Tobias Stoeckmann
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=20160714192834.GA3861@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