Permalink
Browse files

optimized the previous commit for padding header value strings with '…

…\0'.
  • Loading branch information...
1 parent 7a719b8 commit 87595f74450c94e5be9b409c4835f6066eb302c4 @agentzh agentzh committed Dec 24, 2011
@@ -117,7 +117,6 @@ ngx_http_headers_more_exec_input_cmd(ngx_http_request_t *r,
ngx_str_t value;
ngx_http_headers_more_header_val_t *h;
ngx_uint_t i;
- u_char *p;
if (!cmd->headers) {
return NGX_OK;
@@ -136,20 +135,11 @@ ngx_http_headers_more_exec_input_cmd(ngx_http_request_t *r,
return NGX_ERROR;
}
-#if 1
- /* Nginx request header value requires to be a null-terminated
- * C string */
-
- p = ngx_palloc(r->pool, value.len + 1);
- if (p == NULL) {
- return NGX_ERROR;
+ if (value.len) {
+ value.len--; /* remove the trailing '\0' added by
+ ngx_http_headers_more_parse_header */
}
- ngx_memcpy(p, value.data, value.len);
- p[value.len] = '\0';
- value.data = p;
-#endif
-
if (h[i].handler(r, &h[i], &value) != NGX_OK) {
return NGX_ERROR;
}
@@ -133,6 +133,11 @@ ngx_http_headers_more_exec_cmd(ngx_http_request_t *r,
return NGX_ERROR;
}
+ if (value.len) {
+ value.len--; /* remove the trailing '\0' added by
+ ngx_http_headers_more_parse_header */
+ }
+
if (h[i].handler(r, &h[i], &value) != NGX_OK) {
return NGX_ERROR;
}
@@ -18,6 +18,7 @@ ngx_http_headers_more_parse_header(ngx_conf_t *cf, ngx_str_t *cmd_name,
ngx_str_t value = ngx_null_string;
ngx_flag_t seen_end_of_key;
ngx_http_compile_complex_value_t ccv;
+ u_char *p;
hv = ngx_array_push(headers);
if (hv == NULL) {
@@ -117,6 +118,19 @@ ngx_http_headers_more_parse_header(ngx_conf_t *cf, ngx_str_t *cmd_name,
}
+ /* Nginx request header value requires to be a null-terminated
+ * C string */
+
+ p = ngx_palloc(cf->pool, value.len + 1);
+ if (p == NULL) {
+ return NGX_ERROR;
+ }
+
+ ngx_memcpy(p, value.data, value.len);
+ p[value.len] = '\0';
+ value.data = p;
+ value.len++; /* we should also compile the trailing '\0' */
+
/* compile the header value as a complex value */
ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));

0 comments on commit 87595f7

Please sign in to comment.