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

Re: [PATCH 06/20] builtin/receive-pack: convert portions to struct object_id

From
Duy Nguyen <pclouds@gmail.com>
Date
Mar 21, 2017, 10:26 UTC
Message-ID
<CACsJy8Drb8vuL2mqk_NC4w8Z78bx_eDREyG3Xo0KYWXispi3rA@mail.gmail.com>
In-Reply-To
<20170320231752.gzo2uk6d2qob5ovk@genre.crustytoothpaste.net>

On Tue, Mar 21, 2017 at 6:17 AM, brian m. carlson <sandals@crustytoothpaste.net> wrote:

Show 37 quoted lines
> On Mon, Mar 20, 2017 at 07:56:17PM +0700, Duy Nguyen wrote:
>> On Sun, Mar 19, 2017 at 4:19 AM, brian m. carlson
>> <sandals@crustytoothpaste.net> wrote:
>> > @@ -1489,23 +1489,24 @@ static struct command **queue_command(struct command **tail,
>> >                                       const char *line,
>> >                                       int linelen)
>> >  {
>> > -       unsigned char old_sha1[20], new_sha1[20];
>> > +       struct object_id old_oid, new_oid;
>> >         struct command *cmd;
>> >         const char *refname;
>> >         int reflen;
>> > +       const char *p;
>> >
>> > -       if (linelen < 83 ||
>> > -           line[40] != ' ' ||
>> > -           line[81] != ' ' ||
>> > -           get_sha1_hex(line, old_sha1) ||
>> > -           get_sha1_hex(line + 41, new_sha1))
>> > +       if (!linelen ||
>>
>> I think you can skip this. The old code needed "< 83" because of the
>> random accesses to [40] and [81] but you don't do that anymore.
>> parse_oid_hex() can handle empty hex strings fine.
>
> I just realized this looks fishy:
>
>         while (boc < eoc) {
>                 const char *eol = memchr(boc, '\n', eoc - boc);
>                 tail = queue_command(tail, boc, eol ? eol - boc : eoc - eol);
>                 boc = eol ? eol + 1 : eoc;
>         }
>
> If eol is NULL, we subtract it from eoc?  I mean, eol will be zero, so
> we get eoc, which seems like what we want.  I think I'm going to send in
> a separate patch to fix that, because clearly that's bizarre and not at
> all compliant with the C standard.
Eck.. Good eyes!
Show 16 quoted lines
>> > +           parse_oid_hex(line, &old_oid, &p) ||
>> > +           *p++ != ' ' ||
>> > +           parse_oid_hex(p, &new_oid, &p) ||
>> > +           *p++ != ' ')
>>
>> maybe "|| *p)" as well? I think the old code, with "linelen < 83",
>> makes sure reflen is at least one. Not sure what FLEX_ALLOC_MEM would
>> do if reflen is zero.
>
> I don't think that line is actually guaranteed to be NUL-terminated.  It
> may be terminated instead by a newline, such as by
> queue_commands_from_cert.
>
> If we did get an empty reflen, we'd call xcalloc, where we will allocate
> exactly the size of the struct otherwise.  We'd then try to memcpy zero
> bytes into that location, and succeed.

Actually I think we allocate an extra byte for NUL as well, so cmd->ref_name is still valid (as an empty string). Yes we should be fine.

-- 
Duy
Previous: brian m. carlsonNext: brian m. carlson
Message 24 of 31 in “object_id part 7”
  1. 00/20 object_id part 7brian m. carlson, Mar 18, 2017
  2. 14/20 sha1-array: convert internal storage for struct sha1_array to object_idbrian m. carlson, Mar 18, 2017
  3. 13/20 builtin/pull: convert to struct object_idbrian m. carlson, Mar 18, 2017
  4. 17/20 Convert sha1_array_lookup to take struct object_idbrian m. carlson, Mar 18, 2017
  5. 20/20 Documentation: update and rename api-sha1-array.txtbrian m. carlson, Mar 18, 2017
  6. 16/20 Convert remaining callers of sha1_array_lookup to object_idbrian m. carlson, Mar 18, 2017
  7. 18/20 Convert sha1_array_for_each_unique and for_each_abbrev to object_idbrian m. carlson, Mar 18, 2017
  8. 19/20 Rename sha1_array to oid_arraybrian m. carlson, Mar 18, 2017
  9. Duy NguyenMar 20, 2017
  10. brian m. carlsonMar 21, 2017
  11. 15/20 Make sha1_array_append take a struct object_id *brian m. carlson, Mar 18, 2017
  12. 07/20 fsck: convert init_skiplist to struct object_idbrian m. carlson, Mar 18, 2017
  13. 04/20 builtin/diff: convert to struct object_idbrian m. carlson, Mar 18, 2017
  14. 08/20 parse-options-cb: convert sha1_array_append caller to struct object_idbrian m. carlson, Mar 18, 2017
  15. 02/20 Convert GIT_SHA1_HEXSZ used for allocation to GIT_MAX_HEXSZbrian m. carlson, Mar 18, 2017
  16. 03/20 Convert GIT_SHA1_RAWSZ used for allocation to GIT_MAX_RAWSZbrian m. carlson, Mar 18, 2017
  17. 10/20 sha1_name: convert struct disambiguate_state to object_idbrian m. carlson, Mar 18, 2017
  18. Duy NguyenMar 20, 2017
  19. brian m. carlsonMar 20, 2017
  20. Duy NguyenMar 21, 2017
  21. 06/20 builtin/receive-pack: convert portions to struct object_idbrian m. carlson, Mar 18, 2017
  22. Duy NguyenMar 20, 2017
  23. brian m. carlsonMar 20, 2017
  24. Duy NguyenMar 21, 2017
  25. 05/20 builtin/pull: convert portions to struct object_idbrian m. carlson, Mar 18, 2017
  26. 11/20 sha1_name: convert disambiguate_hint_fn to take object_idbrian m. carlson, Mar 18, 2017
  27. 12/20 submodule: convert check_for_new_submodule_commits to object_idbrian m. carlson, Mar 18, 2017
  28. 09/20 test-sha1-array: convert most code to struct object_idbrian m. carlson, Mar 18, 2017
  29. 01/20 Define new hash-size constants for allocating memorybrian m. carlson, Mar 18, 2017
  30. Duy NguyenMar 20, 2017
  31. brian m. carlsonMar 21, 2017

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.