git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nguyen Thai Ngoc Duy <pclouds@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Johannes Sixt <j.sixt@viscovery.net>, git@vger.kernel.org
Subject: Re: [PATCH] setup_revisions(): do not access outside argv
Date: Thu, 21 May 2009 12:41:54 +1000	[thread overview]
Message-ID: <fcaeb9bf0905201941u2480e102jd1925593e288b608@mail.gmail.com> (raw)
In-Reply-To: <7v7i0btdwu.fsf@alter.siamese.dyndns.org>

On Thu, May 21, 2009 at 11:58 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Nguyen Thai Ngoc Duy <pclouds@gmail.com> writes:
>
>> 2009/5/20 Johannes Sixt <j.sixt@viscovery.net>:
>>> Nguyễn Thái Ngọc Duy schrieb:
>>>> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
>>>> ---
>>>>  revision.c |    4 ++--
>>>>  1 files changed, 2 insertions(+), 2 deletions(-)
>>>>
>>>> diff --git a/revision.c b/revision.c
>>>> index 18b7ebb..be1e307 100644
>>>> --- a/revision.c
>>>> +++ b/revision.c
>>>> @@ -1241,9 +1241,9 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
>>>>               if (strcmp(arg, "--"))
>>>>                       continue;
>>>>               argv[i] = NULL;
>>>> -             argc = i;
>>>> -             if (argv[i + 1])
>>>> +             if (i + 1 < argc && argv[i + 1])
>>>>                       revs->prune_data = get_pathspec(revs->prefix, argv + i + 1);
>>>> +             argc = i;
>>>>               seen_dashdash = 1;
>>>>               break;
>>>>       }
>>>
>>> Why is this necessary? I'd expect that argv arrays have NULL at the end.
>>
>> I have no idea. I hit this "bug" in my builtin-rebase.c and had that
>> question too. But I grepped through and saw that
>> at least verify_bundle() does not terminate argv with NULL. So I
>> assume that setup_revisions() does not expect NULL at the end.
>
> If a function takes (int ac, char **av), then people should be able to
> depend on the usual convention of
>
>  (1) for any i < ac, av[i] is not NULL; and
>  (2) av[ac] is NULL.
>
> With your patch, a broken caller's wish is simply discarded and nobody
> will notice.  Without your patch, at least you will know that the caller
> passed an inconsistent pair of ac and av to this function by seeing a
> coalmine canary segfault.

OK. I will send another patch for verify_bundle() then :-) just to
make sure no one goes down the same way.
-- 
Duy

  parent reply	other threads:[~2009-05-21  2:42 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-20  8:08 [PATCH] setup_revisions(): do not access outside argv Nguyễn Thái Ngọc Duy
2009-05-20  8:15 ` Johannes Sixt
2009-05-20  8:23   ` Nguyen Thai Ngoc Duy
2009-05-21  1:58     ` Junio C Hamano
2009-05-21  2:38       ` Miles Bader
2009-05-21  2:41       ` Nguyen Thai Ngoc Duy [this message]
2009-05-21  4:18       ` Jeff King
2009-05-21 18:02         ` Thomas Jarosch
2009-05-22  7:56           ` Jeff King
2009-05-22  8:02             ` Jeff King
2009-05-22 14:23               ` Thomas Jarosch
2009-05-22 15:33               ` Brandon Casey
2009-05-22 15:34                 ` Jeff King
2009-05-25 10:46                   ` [PATCH] convert bare readlink to strbuf_readlink Jeff King
2009-05-25 22:23                     ` Junio C Hamano
     [not found]               ` <20090602195605.6117@nanako3.lavabit.com>
2009-06-02 13:57                 ` [PATCH] setup_revisions(): do not access outside argv 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=fcaeb9bf0905201941u2480e102jd1925593e288b608@mail.gmail.com \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j.sixt@viscovery.net \
    /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).