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

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

 



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.

Chris





[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