Re: [PATCH v2 1/8] fast-import: tighten path unquoting

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Apr 10, 2024, at 01:18, Chris Torek <chris.torek@xxxxxxxxx> wrote:
> On Tue, Apr 9, 2024 at 11:30 PM Patrick Steinhardt <ps@xxxxxx> wrote:
>>> +             if (include_spaces)
>>> +                     *endp = p + strlen(p);
>>> +             else
>>> +                     *endp = strchr(p, ' ');
>>> +             strbuf_add(sb, p, *endp - p);
>> 
>> strchr(3P) may return a NULL pointer in case there is no space, which
>> would make us segfault here when dereferencing `*endp`. We should
>> probably add a testcase that would hit this edge case.
> 
> Note that you can do:
> 
>    *endp = p + strcspn(p, " ");
> 
> (though `strcspn` is a fundamentally harder operation since it
> takes a string argument). Everything depends on whether you
> want to test for an explicit "there was no space at all" case of
> course; performance considerations are secondary.

I thought strchr returned a pointer to the terminating NUL byte if the needle
was not found. Turns out it does return NULL in that case, as you say. strchrnul
does what I want here and I’ve replaced it with that.

I’ve added a test covering this case.

Thalia







[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux