From: Max Kirillov <max@max630.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: Max Kirillov <max@max630.net>,
git@vger.kernel.org, Karthik Nayak <karthik.188@gmail.com>,
Christian Couder <christian.couder@gmail.com>,
Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Subject: [PATCH] strtoul_ui: actually report error in case of negative input
Date: Mon, 14 Sep 2015 01:00:36 +0300 [thread overview]
Message-ID: <1442181636-27821-1-git-send-email-max@max630.net> (raw)
If s == "-1" and CPU is i386, then none of the checks is triggered, including
the last "(unsigned int) ul != ul", because ul == 2**32 - 1, which fits into
"unsigned int".
Fix it by changing the last check to trigger earlier, as soon as it
becomes bigger than INT_MAX.
Signed-off-by: Max Kirillov <max@max630.net>
---
This caused failure of "%(contents:lines=-1)` should fail" case from
t6302-for-each-ref-filter.sh for me in pu. Don't know why nobody has noticed
it. It did not trigger errno, instead wrapping the value. I have libc6 2.13
(debian wheezy)
Still can be fooled with carefully chosen negative input. For i386 it's
between INT_MIN and something like -UINT_MIN
Adding people from the commit which uses the function.
git-compat-util.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/git-compat-util.h b/git-compat-util.h
index f649e81..1c0229b 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -815,7 +815,7 @@ static inline int strtoul_ui(char const *s, int base, unsigned int *result)
errno = 0;
ul = strtoul(s, &p, base);
- if (errno || *p || p == s || (unsigned int) ul != ul)
+ if (errno || *p || p == s || ul > (unsigned long) INT_MAX)
return -1;
*result = ul;
return 0;
--
2.3.4.2801.g3d0809b
next reply other threads:[~2015-09-13 22:08 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-13 22:00 Max Kirillov [this message]
2015-09-14 6:30 ` [PATCH] strtoul_ui: actually report error in case of negative input Matthieu Moy
2015-09-14 20:26 ` Max Kirillov
2015-09-15 6:50 ` Matthieu Moy
2015-09-16 1:17 ` Junio C Hamano
2015-09-16 4:20 ` Max Kirillov
2015-09-16 6:08 ` Matthieu Moy
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=1442181636-27821-1-git-send-email-max@max630.net \
--to=max@max630.net \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=karthik.188@gmail.com \
--cc=matthieu.moy@grenoble-inp.fr \
/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;
as well as URLs for NNTP newsgroup(s).