git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Fix off-by-one error: don't read the byte before a malloc'd buffer.
@ 2007-12-08 15:48 Jim Meyering
  2007-12-09 18:15 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Jim Meyering @ 2007-12-08 15:48 UTC (permalink / raw)
  To: git list


* config.c (store_write_pair): Don't read value[-1].

Signed-off-by: Jim Meyering <meyering@redhat.com>
---
 config.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/config.c b/config.c
index ed96213..6031b38 100644
--- a/config.c
+++ b/config.c
@@ -652,7 +652,7 @@ static int store_write_pair(int fd, const char* key, const char* value)
 	for (i = 0; value[i]; i++)
 		if (value[i] == ';' || value[i] == '#')
 			quote = 1;
-	if (value[i-1] == ' ')
+	if (i && value[i-1] == ' ')
 		quote = 1;

 	if (write_in_full(fd, "\t", 1) != 1 ||
--
1.5.3.7.1116.gae2a9

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] Fix off-by-one error: don't read the byte before a malloc'd buffer.
  2007-12-08 15:48 [PATCH] Fix off-by-one error: don't read the byte before a malloc'd buffer Jim Meyering
@ 2007-12-09 18:15 ` Junio C Hamano
  2007-12-09 19:24   ` Brian Gernhardt
  0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2007-12-09 18:15 UTC (permalink / raw)
  To: Jim Meyering; +Cc: git list, Brian Gernhardt

Jim Meyering <jim@meyering.net> writes:

> * config.c (store_write_pair): Don't read value[-1].
>
> Signed-off-by: Jim Meyering <meyering@redhat.com>
> ---
>  config.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/config.c b/config.c
> index ed96213..6031b38 100644
> --- a/config.c
> +++ b/config.c
> @@ -652,7 +652,7 @@ static int store_write_pair(int fd, const char* key, const char* value)
>  	for (i = 0; value[i]; i++)
>  		if (value[i] == ';' || value[i] == '#')
>  			quote = 1;
> -	if (value[i-1] == ' ')
> +	if (i && value[i-1] == ' ')
>  		quote = 1;
>
>  	if (write_in_full(fd, "\t", 1) != 1 ||

Thanks.

The fix may be correct but the comment above the part the patch fixes is
very misleading and I wasted a few minutes checking to see what it is
doing is correct.

The "quote" variable does not really control quoting; the quoting with
backslash is always done for the value, and this check is about adding a
dq pair around it, so that the parser does not lose leading or trailing
SP or string after start-of-comment marker characters.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Fix off-by-one error: don't read the byte before a malloc'd buffer.
  2007-12-09 18:15 ` Junio C Hamano
@ 2007-12-09 19:24   ` Brian Gernhardt
  0 siblings, 0 replies; 3+ messages in thread
From: Brian Gernhardt @ 2007-12-09 19:24 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Jim Meyering, git list


On Dec 9, 2007, at 1:15 PM, Junio C Hamano wrote:

> The fix may be correct but the comment above the part the patch  
> fixes is
> very misleading and I wasted a few minutes checking to see what it is
> doing is correct.

The fix is correct.  I did not anticipate empty strings when I wrote  
the loop in question.  Although I wonder if that should be expanded to  
use isspace instead of checking for just ' '.  I'm less familiar with  
the config parsing than I was.

> The "quote" variable does not really control quoting; the quoting with
> backslash is always done for the value, and this check is about  
> adding a
> dq pair around it, so that the parser does not lose leading or  
> trailing
> SP or string after start-of-comment marker characters.

It's for adding quotes, which made the comment make sense to me.  But  
your expanded description is correct and matches the commit message I  
wrote.  Thanks for clarifying it in the code.

~~ Brian

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-12-09 19:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-08 15:48 [PATCH] Fix off-by-one error: don't read the byte before a malloc'd buffer Jim Meyering
2007-12-09 18:15 ` Junio C Hamano
2007-12-09 19:24   ` Brian Gernhardt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).