Skip to content

Commit b11eb08

Browse files
committed
config parse: safely cast to int
1 parent 6b349ec commit b11eb08

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/config_parse.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ static int parse_subsection_header(git_config_parser *reader, const char *line,
8888
last_quote = strrchr(line, '"');
8989
quoted_len = last_quote - first_quote;
9090

91+
if ((last_quote - line) > INT_MAX) {
92+
set_parse_error(reader, 0, "invalid section header, line too long");
93+
goto end_error;
94+
}
95+
9196
if (quoted_len == 0) {
9297
set_parse_error(reader, 0, "missing closing quotation mark in section header");
9398
goto end_error;
@@ -146,7 +151,7 @@ static int parse_subsection_header(git_config_parser *reader, const char *line,
146151
}
147152

148153
*section_name = git_buf_detach(&buf);
149-
return &line[rpos + 2] - line_start; /* rpos is at the closing quote */
154+
return (int)(&line[rpos + 2] - line_start); /* rpos is at the closing quote */
150155

151156
end_error:
152157
git_buf_dispose(&buf);

0 commit comments

Comments
 (0)