From: Junio C Hamano <gitster@pobox.com>
To: "SZEDER Gábor" <szeder.dev@gmail.com>
Cc: "Øystein Walle" <oystwa@gmail.com>, git@vger.kernel.org, ingy@ingy.net
Subject: Re: [PATCH] rev-parse: Detect missing opt-spec
Date: Fri, 02 Sep 2022 09:27:56 -0700 [thread overview]
Message-ID: <xmqq5yi5aghf.fsf@gitster.g> (raw)
In-Reply-To: <20220902064727.GA3606@szeder.dev> ("SZEDER Gábor"'s message of "Fri, 2 Sep 2022 08:47:27 +0200")
SZEDER Gábor <szeder.dev@gmail.com> writes:
> On Fri, Sep 02, 2022 at 07:06:21AM +0200, Øystein Walle wrote:
>> If a line in parseopts's input starts with one of the flag characters it
>> is erroneously parsed as a opt-spec where the short name of the option
>> is the flag character itself and the long name is after the end of the
>> string. This makes Git want to allocate SIZE_MAX bytes of memory at this
>> line:
>>
>> o->long_name = xmemdupz(sb.buf + 2, s - sb.buf - 2);
>>
>> Since s and sb.buf are equal the second argument is -2 (except unsigned)
>> and xmemdupz allocates len + 1 bytes, ie. -1 meaning SIZE_MAX.
>
> I suspect (but didn't actually check) that this bug was added in
> 2d893dff4c (rev-parse --parseopt: allow [*=?!] in argument hints,
> 2015-07-14).
Good thing to add to the proposed log message. Thanks.
Also, Øystein "Detect" -> "detect" on the title (you can see the
convention in the output from "git shortlog --no-merges").
>> if (!s)
>> s = help;
>>
>> + if (s == sb.buf)
>> + die(_("Missing opt-spec before option flags"));
>> +
OK.
>> +test_expect_success 'test --parseopt invalid opt-spec' '
>> + test_write_lines x -- "=, x" >spec &&
>> + echo "fatal: Missing opt-spec before option flags" >expect &&
>> + test_must_fail git rev-parse --parseopt -- >out <spec >actual 2>&1 &&
>
> When checking an error message please don't look for it on standard
> output; i.e. the redirection at the end should be '2>actual', or
> perheps even better '2>err'.
Again, very good point.
Thanks.
next prev parent reply other threads:[~2022-09-02 16:28 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-01 21:15 [BUG] git crashes on simple rev-parse incantation Ingy dot Net
2022-09-02 4:28 ` Øystein Walle
2022-09-02 5:06 ` [PATCH] rev-parse: Detect missing opt-spec Øystein Walle
2022-09-02 5:46 ` Eric Sunshine
2022-09-02 6:39 ` [PATCH v2] " Øystein Walle
2022-09-02 7:15 ` Eric Sunshine
2022-09-02 6:47 ` [PATCH] " SZEDER Gábor
2022-09-02 16:27 ` Junio C Hamano [this message]
2022-09-02 17:59 ` [PATCH] rev-parse --parseopt: detect " Øystein Walle
2022-09-02 18:01 ` Øystein Walle
2022-09-02 18:45 ` Junio C Hamano
2022-09-02 21:00 ` SZEDER Gábor
2022-09-02 21:29 ` Junio C Hamano
2022-09-02 17:13 ` [PATCH] rev-parse: Detect " Jeff King
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=xmqq5yi5aghf.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=ingy@ingy.net \
--cc=oystwa@gmail.com \
--cc=szeder.dev@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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.