Skip to content

Commit 9b433e4

Browse files
committed
Merge branch 'maint'
* maint: config.c:store_write_pair(): don't read the byte before a malloc'd buffer.
2 parents 774751a + 6281f39 commit 9b433e4

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
@@ -646,13 +646,19 @@ static int store_write_pair(int fd, const char* key, const char* value)
646646
int length = strlen(key+store.baselen+1);
647647
int quote = 0;
648648

649-
/* Check to see if the value needs to be quoted. */
649+
/*
650+
* Check to see if the value needs to be surrounded with a dq pair.
651+
* Note that problematic characters are always backslash-quoted; this
652+
* check is about not losing leading or trailing SP and strings that
653+
* follow beginning-of-comment characters (i.e. ';' and '#') by the
654+
* configuration parser.
655+
*/
650656
if (value[0] == ' ')
651657
quote = 1;
652658
for (i = 0; value[i]; i++)
653659
if (value[i] == ';' || value[i] == '#')
654660
quote = 1;
655-
if (value[i-1] == ' ')
661+
if (i && value[i-1] == ' ')
656662
quote = 1;
657663

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

0 commit comments

Comments
 (0)