Re: [PATCH v2 1/8] fast-import: tighten path unquoting
- From
Chris Torek <chris.torek@gmail.com>
- Date
- Apr 10, 2024, 08:18 UTC
- Message-ID
- <CAPx1GvfgC46n_5fk3dHxg7dn393UVMi0CtHKqQ_GAaqnV_ECCQ@mail.gmail.com>
- In-Reply-To
- <ZhYxNYR33ftEfcPk@tanuki>
On Tue, Apr 9, 2024 at 11:30 PM Patrick Steinhardt <ps@pks.im> wrote:
Show 9 quoted lines
> > + 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