summaryrefslogtreecommitdiff
path: root/src/config_parse.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2019-05-21 14:39:55 +0100
committerEdward Thomson <ethomson@edwardthomson.com>2019-06-24 15:00:41 +0100
commitb11eb08f59181a83cf3091a62fd434db911914a6 (patch)
tree9545f0e7406b6411a12e1416588fc60744b1a3dd /src/config_parse.c
parent6b349ecc49e8de8870e285770536d287511e5b3d (diff)
downloadlibgit2-b11eb08f59181a83cf3091a62fd434db911914a6.tar.gz
config parse: safely cast to int
Diffstat (limited to 'src/config_parse.c')
-rw-r--r--src/config_parse.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/config_parse.c b/src/config_parse.c
index 64d9a698b..46dce4038 100644
--- a/src/config_parse.c
+++ b/src/config_parse.c
@@ -88,6 +88,11 @@ static int parse_subsection_header(git_config_parser *reader, const char *line,
last_quote = strrchr(line, '"');
quoted_len = last_quote - first_quote;
+ if ((last_quote - line) > INT_MAX) {
+ set_parse_error(reader, 0, "invalid section header, line too long");
+ goto end_error;
+ }
+
if (quoted_len == 0) {
set_parse_error(reader, 0, "missing closing quotation mark in section header");
goto end_error;
@@ -146,7 +151,7 @@ end_parse:
}
*section_name = git_buf_detach(&buf);
- return &line[rpos + 2] - line_start; /* rpos is at the closing quote */
+ return (int)(&line[rpos + 2] - line_start); /* rpos is at the closing quote */
end_error:
git_buf_dispose(&buf);