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

Re: [PATCH] Fix unterminated string in set_work_tree and improve error handling

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 3, 2007, 06:29 UTC
Message-ID
<7v7iodqgg9.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<81b0412b0708022247s1116f66al1e8751f33bcae581@mail.gmail.com>
"Alex Riesen" <raa.lkml@gmail.com> writes:
Show 11 quoted lines
>> >> Consolidating two of your patches, would this be Ok?
>> >
>> > Yes, but you may consider replacing strncpy with strlcpy:
>> >
>> >> +            memcpy(dir_buffer, dir, len - suffix_len);
>> >> +            dir_buffer[len - suffix_len] = '\0';
>> >
>> > strlcpy(dir_buffer, dir, len - suffix_len + 1);
>>
>> Does that buy us that much?  Before going to that codepath, we
>> have made sure the result fits, haven't we?

I sense you haven't read my replacement patch (Dscho Acked it). I am talking about this part:

+ if (len > suffix_len && + !strcmp(dir + len - suffix_len, "/" DEFAULT_GIT_DIR_ENVIRONMENT)) { + if ((len - suffix_len) >= sizeof(dir_buffer)) + die("directory name too long"); + memcpy(dir_buffer, dir, len - suffix_len); + dir_buffer[len - suffix_len] = '\0';

Previous: Alex RiesenNext: Alex Riesen
Message 2 of 3 in “Fix unterminated string in set_work_tree and improve error handling”
  1. Fix unterminated string in set_work_tree and improve error handlingAlex Riesen, Aug 3, 2007
  2. Junio C HamanoAug 3, 2007
  3. Alex RiesenAug 3, 2007

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.