git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] setup_revisions(): do not access outside argv

From
Junio C Hamano <gitster@pobox.com>
Date
May 21, 2009, 01:58 UTC
Message-ID
<7v7i0btdwu.fsf@alter.siamese.dyndns.org>
In-Reply-To
<fcaeb9bf0905200123r3649a7e5vc40ece402379e701@mail.gmail.com>
Nguyen Thai Ngoc Duy <pclouds@gmail.com> writes:
Show 30 quoted lines
> 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.

I would not mind a patch that adds an assertion that protects this function from broken callers, so that we can find them, but your patch makes me feel very uneasy.

Previous: Nguyen Thai Ngoc DuyNext: Miles Bader
Message 4 of 16 in “setup_revisions(): do not access outside argv”
  1. setup_revisions(): do not access outside argvNguyễn Thái Ngọc Duy, May 20, 2009
  2. Johannes SixtMay 20, 2009
  3. Nguyen Thai Ngoc DuyMay 20, 2009
  4. Junio C HamanoMay 21, 2009
  5. Miles BaderMay 21, 2009
  6. Nguyen Thai Ngoc DuyMay 21, 2009
  7. Jeff KingMay 21, 2009
  8. Thomas JaroschMay 21, 2009
  9. Jeff KingMay 22, 2009
  10. Jeff KingMay 22, 2009
  11. Thomas JaroschMay 22, 2009
  12. Brandon CaseyMay 22, 2009
  13. Jeff KingMay 22, 2009
  14. convert bare readlink to strbuf_readlinkJeff King, May 25, 2009
  15. Junio C HamanoMay 25, 2009
  16. Jeff KingJun 2, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.