Re: [PATCH v5 16/16] reftable: be more paranoid about 0-length memcpy calls
- From
Han-Wen Nienhuys <hanwen@google.com>
- Date
- Dec 23, 2021, 15:58 UTC
- Message-ID
- <CAFQ2z_OXPw9-hLsaD+E1nGESS7eJH5o5sRrr_R_vW1Oa-vvZoA@mail.gmail.com>
- In-Reply-To
- <xmqq1r24gsph.fsf@gitster.g>
On Wed, Dec 22, 2021 at 11:50 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 8 quoted lines
> > - memcpy(r->hash_prefix, key.buf, key.len);
> > + if (key.len)
> > + memcpy(r->hash_prefix, key.buf, key.len);
> > r->hash_prefix_len = key.len;
> >
> > if (val_type == 0) {
>
> I am not sure why any of these are needed.I'm not sure they are needed, but IMO it's not worth spending brain cycles on deciding either way. Checking the length is always a safe alternative.
I would support having a safe_memcpy() that does this check centrally (note how our array_copy() array function also does this check, even if it's not always needed.)
-- Han-Wen Nienhuys - Google Munich I work 80%. Don't expect answers from me on Fridays. -- Google Germany GmbH, Erika-Mann-Strasse 33, 80636 Munich Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Geschäftsführer: Paul Manicle, Halimah DeLaine Prado