Skip to content

Commit 6281f39

Browse files
meyeringgitster
authored andcommitted
config.c:store_write_pair(): don't read the byte before a malloc'd buffer.
Signed-off-by: Jim Meyering <meyering@redhat.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 8e7425d commit 6281f39

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

config.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,13 +630,19 @@ static int store_write_pair(int fd, const char* key, const char* value)
630630
int length = strlen(key+store.baselen+1);
631631
int quote = 0;
632632

633-
/* Check to see if the value needs to be quoted. */
633+
/*
634+
* Check to see if the value needs to be surrounded with a dq pair.
635+
* Note that problematic characters are always backslash-quoted; this
636+
* check is about not losing leading or trailing SP and strings that
637+
* follow beginning-of-comment characters (i.e. ';' and '#') by the
638+
* configuration parser.
639+
*/
634640
if (value[0] == ' ')
635641
quote = 1;
636642
for (i = 0; value[i]; i++)
637643
if (value[i] == ';' || value[i] == '#')
638644
quote = 1;
639-
if (value[i-1] == ' ')
645+
if (i && value[i-1] == ' ')
640646
quote = 1;
641647

642648
if (write_in_full(fd, "\t", 1) != 1 ||

0 commit comments

Comments
 (0)