comparison src/http/ngx_http_request.c @ 3098:d41c740f55ce stable-0.7

merge r3076, r3077, r3080: fix invalid header logging: *) fix segfault when a header starts with "\rX" and logging is set to info or debug level *) use %*s instead of %V
author Igor Sysoev <igor@sysoev.ru>
date Mon, 07 Sep 2009 11:11:24 +0000
parents 501fd3ae3188
children 2efa8d2fcde1
comparison
equal deleted inserted replaced
3097:8393cadef25d 3098:d41c740f55ce
883 883
884 884
885 static void 885 static void
886 ngx_http_process_request_headers(ngx_event_t *rev) 886 ngx_http_process_request_headers(ngx_event_t *rev)
887 { 887 {
888 u_char *p;
889 size_t len;
888 ssize_t n; 890 ssize_t n;
889 ngx_int_t rc, rv; 891 ngx_int_t rc, rv;
890 ngx_str_t header;
891 ngx_table_elt_t *h; 892 ngx_table_elt_t *h;
892 ngx_connection_t *c; 893 ngx_connection_t *c;
893 ngx_http_header_t *hh; 894 ngx_http_header_t *hh;
894 ngx_http_request_t *r; 895 ngx_http_request_t *r;
895 ngx_http_core_srv_conf_t *cscf; 896 ngx_http_core_srv_conf_t *cscf;
925 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); 926 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
926 return; 927 return;
927 } 928 }
928 929
929 if (rv == NGX_DECLINED) { 930 if (rv == NGX_DECLINED) {
930 header.len = r->header_in->end - r->header_name_start; 931 len = r->header_in->end - r->header_name_start;
931 header.data = r->header_name_start; 932 p = r->header_name_start;
932 933
933 if (header.len > NGX_MAX_ERROR_STR - 300) { 934 if (len > NGX_MAX_ERROR_STR - 300) {
934 header.len = NGX_MAX_ERROR_STR - 300; 935 len = NGX_MAX_ERROR_STR - 300;
935 header.data[header.len++] = '.'; 936 p[len++] = '.'; p[len++] = '.'; p[len++] = '.';
936 header.data[header.len++] = '.';
937 header.data[header.len++] = '.';
938 } 937 }
939 938
940 ngx_log_error(NGX_LOG_INFO, c->log, 0, 939 ngx_log_error(NGX_LOG_INFO, c->log, 0,
941 "client sent too long header line: \"%V\"", 940 "client sent too long header line: \"%*s\"",
942 &header); 941 len, r->header_name_start);
943 ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST); 942 ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
944 return; 943 return;
945 } 944 }
946 } 945 }
947 946
959 958
960 if (r->invalid_header && cscf->ignore_invalid_headers) { 959 if (r->invalid_header && cscf->ignore_invalid_headers) {
961 960
962 /* there was error while a header line parsing */ 961 /* there was error while a header line parsing */
963 962
964 header.len = r->header_end - r->header_name_start;
965 header.data = r->header_name_start;
966
967 ngx_log_error(NGX_LOG_INFO, c->log, 0, 963 ngx_log_error(NGX_LOG_INFO, c->log, 0,
968 "client sent invalid header line: \"%V\"", 964 "client sent invalid header line: \"%*s\"",
969 &header); 965 r->header_end - r->header_name_start,
966 r->header_name_start);
970 continue; 967 continue;
971 } 968 }
972 969
973 /* a header line has been parsed successfully */ 970 /* a header line has been parsed successfully */
974 971
1044 continue; 1041 continue;
1045 } 1042 }
1046 1043
1047 /* rc == NGX_HTTP_PARSE_INVALID_HEADER: "\r" is not followed by "\n" */ 1044 /* rc == NGX_HTTP_PARSE_INVALID_HEADER: "\r" is not followed by "\n" */
1048 1045
1049 header.len = r->header_end - r->header_name_start;
1050 header.data = r->header_name_start;
1051 ngx_log_error(NGX_LOG_INFO, c->log, 0, 1046 ngx_log_error(NGX_LOG_INFO, c->log, 0,
1052 "client sent invalid header line: \"%V\\r...\"", 1047 "client sent invalid header line: \"%*s\\r...\"",
1053 &header); 1048 r->header_end - r->header_name_start,
1049 r->header_name_start);
1054 ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST); 1050 ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
1055 return; 1051 return;
1056 } 1052 }
1057 } 1053 }
1058 1054