@matheusbsbs / matheus-bagliano / commits / 6281f39467
Fork 0

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>

Jim Meyering committed Dec 8, 2007 at 16:48 UTC 6281f394674bf2db861967da6c2215cfc3fc78af
1 file changed +8 -2
config.c
+8 -2
@@ -630,13 +630,19 @@ static int store_write_pair(int fd, const char* key, const char* value)
630 int length = strlen(key+store.baselen+1);
631 int quote = 0;
632
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 + */
640 if (value[0] == ' ')
641 quote = 1;
642 for (i = 0; value[i]; i++)
643 if (value[i] == ';' || value[i] == '#')
644 quote = 1;
639 - if (value[i-1] == ' ')
645 + if (i && value[i-1] == ' ')
646 quote = 1;
647
648 if (write_in_full(fd, "\t", 1) != 1 ||