Re: [PATCH] diff: avoid stack-buffer-read-overrun for very long name

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

On Thu, Apr 26, 2012 at 18:13, Junio C Hamano <gitster@xxxxxxxxx> wrote:
> Jim Meyering <jim@xxxxxxxxxxxx> writes:
>> What do you think about replacing those two append-if-needed two-liners:
>>     if (buffer2.len && buffer2.buf[buffer2.len - 1] != '/')
>>             strbuf_addch(&buffer2, '/');
>> by something that readably encapsulates the idiom:
>>     strbuf_append_if_absent (&buffer2, '/');
>> (though the name isn't particularly apt, because you might
>> take "absent" to mean "not anywhere in the string," so maybe
>>   strbuf_append_if_not_already_at_end (ugly) or
>>   strbuf_append_uniq
>> )
> I am not good at names, but strbuf_terminate_with(&buffer2, '/')
> perhaps?

strbuf_ensure_terminator(struct strbuf* buf, int term, int always)?

>> There are several other uses that would benefit from such a transformation:
>> To find the easy ones, I ran this:
>>   git grep -B1 "strbuf_addch.*'"|grep -A1 '!='
>> I've manually marked/separated the ones that don't apply.
>> ------------------------------------
>> builtin/branch.c-     if (!buf.len || buf.buf[buf.len-1] != '\n')
>> builtin/branch.c:             strbuf_addch(&buf, '\n');
>> --
>> strbuf.h-     if (sb->len && sb->buf[sb->len - 1] != '\n')
>> strbuf.h:             strbuf_addch(sb, '\n');

Please note, that while they are checking the .len, they both behave
differently if .len == 0 or not.
The first always append a '\n', the latter only, if the string isn't empty.

To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at

[Newbies FAQ]     [Linux Kernel Development]     [Free Online Dating]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Free Online Dating]     [Photo]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]     [Linux Resources]

Add to Google