Re: [PATCH] off-by-one bugs found by valgrind

3 messages, 3 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH] off-by-one bugs found by valgrind

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:42:15

Pavel Roskin [off-list ref] writes:
Insufficient memory is allocated in index-pack.c to hold the *.idx name.
One more byte should be allocated to hold the terminating 0.
Thanks.
quote_c_style_counted() in quote.c uses a dangerous construct, when a
variable is incremented once and used twice in the same expression.
Sorry, I do not follow you.  Isn't && a sequence point?
-	for (sp = name; (ch = *sp++) && (sp - name) <= namelen; ) {
-
+	for (sp = name; sp < name + namelen; sp++) {

Re: [PATCH] off-by-one bugs found by valgrind

From: "H. Peter Anvin" <hpa@zytor.com>
Date: 2016-06-15 22:42:15

Junio C Hamano wrote:
Pavel Roskin [off-list ref] writes:

quoted
Insufficient memory is allocated in index-pack.c to hold the *.idx name.
One more byte should be allocated to hold the terminating 0.
Thanks.

quoted
quote_c_style_counted() in quote.c uses a dangerous construct, when a
variable is incremented once and used twice in the same expression.
Sorry, I do not follow you.  Isn't && a sequence point?
&& is a sequence point.  The code is techically fine, but it's harder 
than necessary to read.

	-hpa

Re: [PATCH] off-by-one bugs found by valgrind

From: Pavel Roskin <hidden>
Date: 2016-06-15 22:42:15

On Wed, 2005-12-21 at 13:17 -0800, H. Peter Anvin wrote:
quoted
quoted
quote_c_style_counted() in quote.c uses a dangerous construct, when a
variable is incremented once and used twice in the same expression.
Sorry, I do not follow you.  Isn't && a sequence point?
The patch is right, but my comment was wrong, sorry.

The actual problem detected by valgrind is that sp is dereferenced
before it's checked for the upper boundary.  So, if e.g. namelen is 6,
the code reads name[6] into ch and then leaves the loop.
&& is a sequence point.  The code is techically fine, but it's harder 
than necessary to read.
That alone should be a good reason to apply this patch.

-- 
Regards,
Pavel Roskin
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help