Skip to content

Commit

Permalink
waf: fix negative value size when header value is empty
Browse files Browse the repository at this point in the history
The headers parser considers that all headers have a value.

That is producing a backtrace when it is sent -1 as value
size in modsecurity api function msc_add_n_request_header().

Apr 10 05:40:39 zva6k1 pound: ReverseProxy, - waf_add_req_head() msc_add_n_request_header key X-Requested-With:
Apr 10 05:40:39 zva6k1 pound: ReverseProxy, - waf_add_req_head() msc_add_n_request_header key_size 16
Apr 10 05:40:39 zva6k1 pound: ReverseProxy, - waf_add_req_head() msc_add_n_request_header value
Apr 10 05:40:39 zva6k1 pound: ReverseProxy, - waf_add_req_head() msc_add_n_request_header value_size -1
Apr 10 05:40:39 zva6k1 pound: ReverseProxy, Error: signal 6
Apr 10 05:40:39 zva6k1 pound: ReverseProxy, Backtrace_symbol: /usr/local/zevenet/app/pound/sbin/pound(zcu_bt_print+0x1d) [0x55ba91e7b07d]
Mar 26 18:53:28 zva6k1 pound: ReverseProxy, Backtrace_symbol: /usr/local/zevenet/app/pound/sbin/pound(handler+0x1e) [0x5586c534d12e]
Mar 26 18:53:28 zva6k1 pound: ReverseProxy, Backtrace_symbol: /lib/x86_64-linux-gnu/libc.so.6(+0x3bd60) [0x7f1d7b499d60]
Mar 26 18:53:28 zva6k1 pound: ReverseProxy, Backtrace_symbol: /lib/x86_64-linux-gnu/libc.so.6(gsignal+0x141) [0x7f1d7b499ce1]
Mar 26 18:53:28 zva6k1 pound: ReverseProxy, Backtrace_symbol: /lib/x86_64-linux-gnu/libc.so.6(abort+0x123) [0x7f1d7b483537]
Mar 26 18:53:28 zva6k1 pound: ReverseProxy, Backtrace_symbol: /lib/x86_64-linux-gnu/libstdc++.so.6(+0x8c983) [0x7f1d7b064983]
Mar 26 18:53:28 zva6k1 pound: ReverseProxy, Backtrace_symbol: /lib/x86_64-linux-gnu/libstdc++.so.6(+0x928c6) [0x7f1d7b06a8c6]
Mar 26 18:53:28 zva6k1 pound: ReverseProxy, Backtrace_symbol: /lib/x86_64-linux-gnu/libstdc++.so.6(+0x92901) [0x7f1d7b06a901]
Mar 26 18:53:28 zva6k1 pound: ReverseProxy, Backtrace_symbol: /lib/x86_64-linux-gnu/libstdc++.so.6(+0x92b34) [0x7f1d7b06ab34]
Mar 26 18:53:28 zva6k1 pound: ReverseProxy, Backtrace_symbol: /lib/x86_64-linux-gnu/libstdc++.so.6(+0x8e845) [0x7f1d7b066845]
Mar 26 18:53:28 zva6k1 pound: ReverseProxy, Backtrace_symbol: /lib/x86_64-linux-gnu/libstdc++.so.6(+0x11ed8e) [0x7f1d7b0f6d8e]
Mar 26 18:53:28 zva6k1 pound: ReverseProxy, Backtrace_symbol: /lib/libmodsecurity.so.3(_ZN11modsecurity11Transaction16addRequestHeaderEPKhmS2_m+0x81) [0x7f1d7b764dd1]
Mar 26 18:53:28 zva6k1 pound: ReverseProxy, Backtrace_symbol: /usr/local/zevenet/app/pound/sbin/pound(waf_add_req_head+0xbe) [0x5586c53655de]
Mar 26 18:53:28 zva6k1 pound: ReverseProxy, Backtrace_symbol: /usr/local/zevenet/app/pound/sbin/pound(do_http+0x108e) [0x5586c534f26e]
Mar 26 18:53:28 zva6k1 pound: ReverseProxy, Backtrace_symbol: /usr/local/zevenet/app/pound/sbin/pound(thr_http_pool+0x22) [0x5586c5356b72]
Mar 26 18:53:28 zva6k1 pound: ReverseProxy, Backtrace_symbol: /lib/x86_64-linux-gnu/libpthread.so.0(+0x8ea7) [0x7f1d7b62bea7]
Mar 26 18:53:28 zva6k1 pound: ReverseProxy, Backtrace_symbol: /lib/x86_64-linux-gnu/libc.so.6(clone+0x3f) [0x7f1d7b55bdef]
Mar 26 18:53:28 zva6k1 pound: ReverseProxy, MONITOR: worker exited normally 1, restarting...

Signed-off-by: nevola <[email protected]>
  • Loading branch information
nevola committed Apr 14, 2023
1 parent 03109ec commit 4bc8ae9
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions waf.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ parse_headers(const char *header, char **key, int *key_size, char **value,
*key_size = i;
*value = (char *) header + i + 2;
*value_size = strlen(header) - 2 - *key_size; // rest size of " :
if (*value_size < 0)
*value_size = 0;
}

return fin;
Expand Down Expand Up @@ -320,7 +322,7 @@ int waf_add_req_head(Transaction * t, const char **headers, int num_headers)
char *key;
int key_size;
char *value;
int value_size;
int value_size = 0;
int ret = 1;
int cont = 1;
int i;
Expand Down Expand Up @@ -349,7 +351,7 @@ int waf_add_resp_head(Transaction * t, const char **headers, int num_headers)
char *key;
int key_size;
char *value;
int value_size;
int value_size = 0;
int ret = 1;
int cont = 1;
int http_code;
Expand Down

0 comments on commit 4bc8ae9

Please sign in to comment.