Re: [PATCH v9 6/8] convert: check for detectable errors in UTF encodings
- From
Lars Schneider <larsxschneider@gmail.com>
- Date
- Mar 5, 2018, 23:45 UTC
- Message-ID
- <55633B6F-EB6E-42D6-8E58-79158A99774A@gmail.com>
- In-Reply-To
- <xmqqfu5e8a53.fsf@gitster-ct.c.googlers.com>
Show 11 quoted lines
> On 05 Mar 2018, at 22:50, Junio C Hamano <gitster@pobox.com> wrote:
>
> lars.schneider@autodesk.com writes:
>
>> +static int validate_encoding(const char *path, const char *enc,
>> + const char *data, size_t len, int die_on_error)
>> +{
>> + if (!memcmp("UTF-", enc, 4)) {
>
> Does the caller already know that enc is sufficiently long that
> using memcmp is safe?No :-(
Would you be willing to squash that in?
if (strlen(enc) > 4 && !memcmp("UTF-", enc, 4)) {I deliberately used "> 4" as plain "UTF-" is not even valid.
Thanks for spotting this, Lars