From 25383d76d93d1b8b67b2b54acc8bff476f3fd61e Mon Sep 17 00:00:00 2001 From: mathewmarcus Date: Mon, 16 Jul 2018 07:41:21 -0500 Subject: [PATCH] modified parse_options function --- hydra-http-form.c | 19 +++++++++---------- hydra-http.c | 5 +++-- hydra-http.h | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/hydra-http-form.c b/hydra-http-form.c index 5d719b9..4b02483 100644 --- a/hydra-http-form.c +++ b/hydra-http-form.c @@ -388,8 +388,7 @@ char *stringify_headers(ptr_header_node *ptr_head) { return headers_str; } -ptr_header_node parse_options(char *miscptr) { - ptr_header_node ptr_head = NULL; +int32_t parse_options(char *miscptr, ptr_header_node *ptr_head) { char *ptr, *ptr2; /* @@ -429,14 +428,14 @@ ptr_header_node parse_options(char *miscptr) { * - (optional1 + 2) contains the header's name * - ptr contains the header's value */ - if (add_header(&ptr_head, miscptr + 2, hydra_strrep(ptr, "\\:", ":"), HEADER_TYPE_USERHEADER)) { + if (add_header(ptr_head, miscptr + 2, hydra_strrep(ptr, "\\:", ":"), HEADER_TYPE_USERHEADER)) { // Success: break the switch and go ahead miscptr = ptr2; break; } // Error: abort execution hydra_report(stderr, "[ERROR] Out of memory for HTTP headers (h)."); - return NULL; + return 0; case 'H': // add a new header, or replace an existing one's value ptr = miscptr + 2; @@ -460,19 +459,18 @@ ptr_header_node parse_options(char *miscptr) { * - (optional1 + 2) contains the header's name * - ptr contains the header's value */ - if (add_header(&ptr_head, miscptr + 2, hydra_strrep(ptr, "\\:", ":"), HEADER_TYPE_USERHEADER_REPL)) { + if (add_header(ptr_head, miscptr + 2, hydra_strrep(ptr, "\\:", ":"), HEADER_TYPE_USERHEADER_REPL)) { // Success: break the switch and go ahead miscptr = ptr2; break; } // Error: abort execution hydra_report(stderr, "[ERROR] Out of memory for HTTP headers (H)."); - return NULL; + return 0; // no default } } - - return ptr_head; + return 1; } char *prepare_http_request(char *type, char *path, char *params, char *headers) { @@ -1178,7 +1176,7 @@ int32_t service_http_form_init(char *ip, int32_t sp, unsigned char options, char } ptr_header_node initialize(char *ip, unsigned char options, char *miscptr) { - ptr_header_node ptr_head; + ptr_header_node ptr_head = NULL; char *ptr, *ptr2, *proxy_string; if (use_proxy > 0 && proxy_count > 0) @@ -1278,7 +1276,8 @@ ptr_header_node initialize(char *ip, unsigned char options, char *miscptr) { * Parse the user-supplied options. * Beware of the backslashes (\)! */ - ptr_head = parse_options(optional1); + if (!parse_options(optional1, &ptr_head)) + return NULL; /* again: no snprintf to be portable. don't worry, buffer can't overflow */ if (use_proxy == 1 && proxy_authentication[selected_proxy] != NULL) { diff --git a/hydra-http.c b/hydra-http.c index bfdfc27..db9b500 100644 --- a/hydra-http.c +++ b/hydra-http.c @@ -267,7 +267,7 @@ void service_http(char *ip, int32_t sp, unsigned char options, char *miscptr, FI int32_t run = 1, next_run = 1, sock = -1; int32_t myport = PORT_HTTP, mysslport = PORT_HTTP_SSL; char *ptr, *ptr2; - ptr_header_node ptr_head; + ptr_header_node ptr_head = NULL; hydra_register_socket(sp); if (memcmp(hydra_get_next_pair(), &HYDRA_EXIT, sizeof(HYDRA_EXIT)) == 0) @@ -310,7 +310,8 @@ void service_http(char *ip, int32_t sp, unsigned char options, char *miscptr, FI *ptr++ = 0; optional1 = ptr; - ptr_head = parse_options(optional1); + if (!parse_options(optional1, &ptr_head)) + run = 4; while (1) { next_run = 0; diff --git a/hydra-http.h b/hydra-http.h index 1679ccb..b6b4c2b 100644 --- a/hydra-http.h +++ b/hydra-http.h @@ -15,7 +15,7 @@ extern char *webtarget; extern char *slash; extern char *optional1; -extern ptr_header_node parse_options(char *miscptr); +extern int32_t parse_options(char *miscptr, ptr_header_node * ptr_head); extern int32_t add_header(ptr_header_node * ptr_head, char *header, char *value, char type); extern char *stringify_headers(ptr_header_node *ptr_head); #endif