Commit 098f1e6e by Matt Burke

Use an array of forbidden custom headers

parent d29c5412
...@@ -66,14 +66,20 @@ static int git_smart__set_callbacks( ...@@ -66,14 +66,20 @@ static int git_smart__set_callbacks(
return 0; return 0;
} }
#define forbid_custom_header(disallowed_name) \ static char *forbidden_custom_headers[] = {
if (strncmp(disallowed_name, custom_header, name_len) == 0) \ "User-Agent",
return false "Host",
"Accept",
"Content-Type",
"Transfer-Encoding",
"Content-Length",
};
bool is_valid_custom_header(const char *custom_header) bool is_valid_custom_header(const char *custom_header)
{ {
const char *c; const char *c;
int name_len; int name_len;
unsigned long i;
if (custom_header == NULL) if (custom_header == NULL)
return true; return true;
...@@ -95,12 +101,9 @@ bool is_valid_custom_header(const char *custom_header) ...@@ -95,12 +101,9 @@ bool is_valid_custom_header(const char *custom_header)
return false; return false;
// Disallow headers that we set // Disallow headers that we set
forbid_custom_header("User-Agent"); for (i = 0; i < ARRAY_SIZE(forbidden_custom_headers); i++)
forbid_custom_header("Host"); if (strncmp(forbidden_custom_headers[i], custom_header, name_len) == 0)
forbid_custom_header("Accept"); return false;
forbid_custom_header("Content-Type");
forbid_custom_header("Transfer-Encoding");
forbid_custom_header("Content-Length");
return true; return true;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment