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

Re: [PATCH 2/4] write_sha1_file_prepare: fix buffer overrun with extra-long object type

From
Junio C Hamano <gitster@pobox.com>
Date
May 5, 2015, 00:28 UTC
Message-ID
<xmqq4mnrg94p.fsf@gitster.dls.corp.google.com>
In-Reply-To
<CAPig+cS3f2XggxqbvX6Z2Da24QKLOg915Bf-bTVa+4oVzfhA1A@mail.gmail.com>
Eric Sunshine <sunshine@sunshineco.com> writes:
Show 9 quoted lines
>> +extern int hash_sha1_file_literally(struct strbuf *buf, const char
>> *type, unsigned char *return_sha1, unsigned flags);
>
> A few questions:
>
> What's the value of making the first argument of
> hash_sha1_file_literally() a strbuf rather than the two-argument
> buf & len accepted by hash_sha1_file() and write_sha1_file()? Is
> the inconsistency warranted?

I do not care either way, as this is really meant to be a single-purpose wrapper for a single caller.

Show 5 quoted lines
> Would it make sense to name the third argument "sha1" instead of
> "return_sha1" to match the argument name of hash_sha1_file()?
>
> And, as an aside, should your new patch 4/4 rename "return_sha1" to
> "sha1" in the write_sha1_file() prototype also?

Because most of the read-cache.c functions take object name and do something about it, but these small number of functions compute and return object name, I actually think it is a good way to keep "return" in the name to remind those who are writing or reading callers.

Show 8 quoted lines
>> +       /* type string, SP, %lu of the length plus NUL must fit this */
>> +       strbuf_grow(&header, strlen(type) + 20);
>
> A couple comments:
>
> First, given that the largest 64-bit unsigned long value
> (18,446,744,073,709,551,615) is 20 characters, do we want to be really
> pedantic and add 22 instead of 20?
32 is fine ;-)
> Second, is strbuf overkill in this situation when a simple
> xmalloc()/free() would do?

I think underneath the number of xmalloc()/free() calls are the same. The code that uses strbuf abstraction is easier to read, I would think.

Previous: Eric SunshineNext: Junio C Hamano
Message 11 of 15 in “hash-object crash fix and new doc and tests”
  1. 0/3 hash-object crash fix and new doc and testsEric Sunshine, May 4, 2015
  2. 1/3 git-hash-object.txt: document --literally optionEric Sunshine, May 4, 2015
  3. 2/3 t1007: add hash-object --literally testsEric Sunshine, May 4, 2015
  4. 3/3 write_sha1_file_prepare: fix buffer overrun with extra-long object typeEric Sunshine, May 4, 2015
  5. Junio C HamanoMay 4, 2015
  6. Junio C HamanoMay 4, 2015
  7. 0/4 "hash-object --literally" fixesJunio C Hamano, May 4, 2015
  8. 1/4 git-hash-object.txt: document --literally optionJunio C Hamano, May 4, 2015
  9. 2/4 write_sha1_file_prepare: fix buffer overrun with extra-long object typeJunio C Hamano, May 4, 2015
  10. Eric SunshineMay 5, 2015
  11. Junio C HamanoMay 5, 2015
  12. Junio C HamanoMay 5, 2015
  13. Eric SunshineMay 5, 2015
  14. 3/4 t1007: add hash-object --literally testsJunio C Hamano, May 4, 2015
  15. 4/4 write_sha1_file(): do not use a separate sha1[] arrayJunio C Hamano, May 4, 2015

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.