git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Fix off-by-one error: don't read the byte before a malloc'd buffer.

From
Jim Meyering <jim@meyering.net>
Date
Dec 8, 2007, 15:48 UTC
Message-ID
<87hcitgpca.fsf@rho.meyering.net>
* 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
Next: Junio C Hamano
Message 1 of 3 in “Fix off-by-one error: don't read the byte before a malloc'd buffer.”
  1. Fix off-by-one error: don't read the byte before a malloc'd buffer.Jim Meyering, Dec 8, 2007
  2. Junio C HamanoDec 9, 2007
  3. Brian GernhardtDec 9, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.