Skip to content

Commit 0467606

Browse files
committed
http: disallow repeated headers from servers
Don't allow servers to send us multiple Content-Type, Content-Length or Location headers.
1 parent 3a2e483 commit 0467606

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

src/transports/http.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -306,16 +306,22 @@ static int on_header_ready(http_subtransport *t)
306306
git_buf *value = &t->parse_header_value;
307307

308308
if (!strcasecmp("Content-Type", git_buf_cstr(name))) {
309-
if (!t->content_type) {
310-
t->content_type = git__strdup(git_buf_cstr(value));
311-
GITERR_CHECK_ALLOC(t->content_type);
309+
if (t->content_type) {
310+
giterr_set(GITERR_NET, "multiple Content-Type headers");
311+
return -1;
312312
}
313+
314+
t->content_type = git__strdup(git_buf_cstr(value));
315+
GITERR_CHECK_ALLOC(t->content_type);
313316
}
314317
else if (!strcasecmp("Content-Length", git_buf_cstr(name))) {
315-
if (!t->content_length) {
316-
t->content_length = git__strdup(git_buf_cstr(value));
317-
GITERR_CHECK_ALLOC(t->content_length);
318+
if (t->content_length) {
319+
giterr_set(GITERR_NET, "multiple Content-Length headers");
320+
return -1;
318321
}
322+
323+
t->content_length = git__strdup(git_buf_cstr(value));
324+
GITERR_CHECK_ALLOC(t->content_length);
319325
}
320326
else if (!strcasecmp("Proxy-Authenticate", git_buf_cstr(name))) {
321327
char *dup = git__strdup(git_buf_cstr(value));
@@ -332,10 +338,13 @@ static int on_header_ready(http_subtransport *t)
332338
return -1;
333339
}
334340
else if (!strcasecmp("Location", git_buf_cstr(name))) {
335-
if (!t->location) {
336-
t->location = git__strdup(git_buf_cstr(value));
337-
GITERR_CHECK_ALLOC(t->location);
341+
if (t->location) {
342+
giterr_set(GITERR_NET, "multiple Location headers");
343+
return -1;
338344
}
345+
346+
t->location = git__strdup(git_buf_cstr(value));
347+
GITERR_CHECK_ALLOC(t->location);
339348
}
340349

341350
return 0;

0 commit comments

Comments
 (0)