summaryrefslogtreecommitdiff
path: root/src/config.c
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@elego.de>2011-04-04 16:17:39 +0200
committerCarlos Martín Nieto <cmn@elego.de>2011-04-04 16:17:39 +0200
commit9b7a6a99807862778706c455d6ba361a3b1f8f7b (patch)
tree3fd6fa93021e0ea13a51e7ddca9f8d52b2e0edc2 /src/config.c
parent72946881b598c133ff1d522d06c083690e260947 (diff)
downloadlibgit2-9b7a6a99807862778706c455d6ba361a3b1f8f7b.tar.gz
config: check for EOF before newline
If a line ends at EOF there is no need to check for the newline character and doing so will cause us to read memory beyond the allocatd memory as we check for the Windows-style new-line, which is two bytes long. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Diffstat (limited to 'src/config.c')
-rw-r--r--src/config.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/config.c b/src/config.c
index 0052c659c..93f15fb08 100644
--- a/src/config.c
+++ b/src/config.c
@@ -537,12 +537,13 @@ static char *cfg_readline(git_config *cfg)
line_src = cfg->reader.read_ptr;
line_end = strchr(line_src, '\n');
- while (is_linebreak(line_end))
- line_end = strchr(line_end + 1, '\n');
-
/* no newline at EOF */
if (line_end == NULL)
line_end = strchr(line_src, 0);
+ else
+ while (is_linebreak(line_end))
+ line_end = strchr(line_end + 1, '\n');
+
while (line_src < line_end && isspace(*line_src))
line_src++;