summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatt Burke <spraints@gmail.com>2015-09-10 13:18:26 -0400
committerMatt Burke <spraints@gmail.com>2015-09-10 13:18:26 -0400
commit3245896bb7527cb42d48faf68f33858c887f2b3d (patch)
treed951c8378890a3441d46e9f5d7456d3be8d79cc9 /src
parent66d90e7098ee2da76ff3351a305a17a38fb9282b (diff)
downloadlibgit2-3245896bb7527cb42d48faf68f33858c887f2b3d.tar.gz
Add a test for custom header validation
Also, *some* custom headers actually are valid.
Diffstat (limited to 'src')
-rw-r--r--src/transports/smart.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/transports/smart.c b/src/transports/smart.c
index b4f8578db..8388d9dc5 100644
--- a/src/transports/smart.c
+++ b/src/transports/smart.c
@@ -66,6 +66,10 @@ static int git_smart__set_callbacks(
return 0;
}
+#define forbid_custom_header(disallowed_name) \
+ if (strncmp(disallowed_name, custom_header, name_len) == 0) \
+ return false
+
bool is_valid_custom_header(const char *custom_header)
{
const char *c;
@@ -91,12 +95,14 @@ bool is_valid_custom_header(const char *custom_header)
return false;
// Disallow headers that we set
- return git__strncmp("User-Agent", custom_header, name_len) == 0 &&
- git__strncmp("Host", custom_header, name_len) == 0 &&
- git__strncmp("Accept", custom_header, name_len) == 0 &&
- git__strncmp("Content-Type", custom_header, name_len) == 0 &&
- git__strncmp("Transfer-Encoding", custom_header, name_len) == 0 &&
- git__strncmp("Content-Length", custom_header, name_len) == 0;
+ forbid_custom_header("User-Agent");
+ forbid_custom_header("Host");
+ forbid_custom_header("Accept");
+ forbid_custom_header("Content-Type");
+ forbid_custom_header("Transfer-Encoding");
+ forbid_custom_header("Content-Length");
+
+ return true;
}
const char *find_invalid_custom_header(const git_strarray *custom_headers)