From: Junio C Hamano <gitster@pobox.com>
To: Phillip Wood <phillip.wood123@gmail.com>
Cc: "Phillip Wood via GitGitGadget" <gitgitgadget@gmail.com>,
git@vger.kernel.org, "René Scharfe" <l.s.r@web.de>,
"Jeff King" <peff@peff.net>
Subject: Re: [PATCH 2/3] config: require at least one digit when parsing numbers
Date: Tue, 25 Oct 2022 09:08:55 -0700 [thread overview]
Message-ID: <xmqqh6zropgo.fsf@gitster.g> (raw)
In-Reply-To: <cb034574-8753-d641-c166-ae2c34b1c589@dunelm.org.uk> (Phillip Wood's message of "Tue, 25 Oct 2022 10:54:24 +0100")
Phillip Wood <phillip.wood123@gmail.com> writes:
> On 21/10/2022 19:19, Junio C Hamano wrote:
>> "Phillip Wood via GitGitGadget" <gitgitgadget@gmail.com> writes:
>>> @@ -1167,6 +1167,10 @@ static int git_parse_signed(const char *value, intmax_t *ret, intmax_t max)
>>> val = strtoimax(value, &end, 0);
>>> if (errno == ERANGE)
>>> return 0;
>>> + if (end == value) {
>>> + errno = EINVAL;
>>> + return 0;
>>> + }
>> This means well, but doesn't strto*() family of functions silently
>> ignore leading blanks, e.g.
>> l = strtol(" 432k", &end, 0);
>> ... l == 432, *end = k ...
>> If you really want to reject a string with no number before the
>> optional unit, end at this point may not match value. With " k" as
>> input, value would point at the space at the beginning, and end
>> would point at 'k'.
>
> It only skips the space if it sees a digit, if it does not find
> anything to convert it sets *end = start.
Yeah, thanks. Yes, my earlier observation was based on a faulty
experiments, and the code posted as-is would be OK.
next prev parent reply other threads:[~2022-10-25 16:09 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-21 13:45 [PATCH 0/3] a few config integer parsing fixes Phillip Wood via GitGitGadget
2022-10-21 13:45 ` [PATCH 1/3] git_parse_unsigned: reject negative values Phillip Wood via GitGitGadget
2022-10-21 18:09 ` Junio C Hamano
2022-10-21 20:13 ` Jeff King
2022-10-22 17:54 ` Junio C Hamano
2022-10-21 13:45 ` [PATCH 2/3] config: require at least one digit when parsing numbers Phillip Wood via GitGitGadget
2022-10-21 18:19 ` Junio C Hamano
2022-10-25 9:54 ` Phillip Wood
2022-10-25 16:08 ` Junio C Hamano [this message]
2022-10-21 20:17 ` Jeff King
2022-10-22 17:51 ` Junio C Hamano
2022-10-22 20:25 ` Jeff King
2022-10-22 21:00 ` Junio C Hamano
2022-10-25 9:55 ` Phillip Wood
2022-10-21 13:45 ` [PATCH 3/3] git_parse_signed(): avoid integer overflow Phillip Wood via GitGitGadget
2022-10-21 18:31 ` Junio C Hamano
2022-10-22 8:09 ` René Scharfe
2022-10-22 16:51 ` Junio C Hamano
2022-10-23 5:57 ` René Scharfe
2022-10-25 10:00 ` Phillip Wood
2022-10-26 11:01 ` René Scharfe
2022-11-09 14:16 ` [PATCH v2 0/3] a few config integer parsing fixes Phillip Wood via GitGitGadget
2022-11-09 14:16 ` [PATCH v2 1/3] git_parse_unsigned: reject negative values Phillip Wood via GitGitGadget
2022-11-09 15:57 ` Ævar Arnfjörð Bjarmason
2022-11-09 14:16 ` [PATCH v2 2/3] config: require at least one digit when parsing numbers Phillip Wood via GitGitGadget
2022-11-09 14:16 ` [PATCH v2 3/3] git_parse_signed(): avoid integer overflow Phillip Wood via GitGitGadget
2022-11-10 2:35 ` [PATCH v2 0/3] a few config integer parsing fixes Taylor Blau
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqh6zropgo.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=l.s.r@web.de \
--cc=peff@peff.net \
--cc=phillip.wood123@gmail.com \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).