]> git.pld-linux.org Git - packages/zabbix.git/blob - http_poller_crash.patch
patch for http poller added
[packages/zabbix.git] / http_poller_crash.patch
1 From 459ee438244f7d1b7907e44738c40bdc8f23660d Mon Sep 17 00:00:00 2001
2 From: Aleksejs Sestakovs <aleksejs.sestakovs@zabbix.com>
3 Date: Mon, 29 Apr 2019 15:09:07 +0300
4 Subject: [PATCH] .......PS. [ZBX-16050] fixed HTTP poller crashes
5
6 ---
7  src/zabbix_server/httppoller/httptest.c | 64 +++++++++----------------
8  1 file changed, 23 insertions(+), 41 deletions(-)
9
10 diff --git a/src/zabbix_server/httppoller/httptest.c b/src/zabbix_server/httppoller/httptest.c
11 index b0a833bad86..bd1ca503643 100644
12 --- a/src/zabbix_server/httppoller/httptest.c
13 +++ b/src/zabbix_server/httppoller/httptest.c
14 @@ -507,58 +507,30 @@ static int        httpstep_load_pairs(DC_HOST *host, zbx_httpstep_t *httpstep)
15   *                                                                            *
16   * Function: add_http_headers                                                 *
17   *                                                                            *
18 - * Purpose: add http headers and cookies to CURL handle                       *
19 + * Purpose: adds HTTP headers to curl_slist and prepares cookie header string *
20   *                                                                            *
21 - * Parameters: easyhandle      - [IN] host to be used in macro expansion      *
22 - *             headers         - [IN] HTTP headers as string                  *
23 - *             headers_slist   - [IN/OUT] empty curl_slist to be freed after  *
24 - *                                        curl_easy_perform is called         *
25 - *             error           - [OUT] error string (if any)                  *
26 - *                                                                            *
27 - * Return value: SUCCEED if headers (and cookies) were set without errors.    *
28 - *               FAIL on error.                                               *
29 + * Parameters: headers         - [IN] HTTP headers as string                  *
30 + *             headers_slist   - [IN/OUT] curl_slist                          *
31 + *             header_cookie   - [IN/OUT] cookie header as string             *
32   *                                                                            *
33   ******************************************************************************/
34 -static int     add_http_headers(CURL *easyhandle, char *headers, struct curl_slist **headers_slist, char **error)
35 +static void    add_http_headers(char *headers, struct curl_slist **headers_slist, char **header_cookie)
36  {
37  #define COOKIE_HEADER_STR      "Cookie:"
38  #define COOKIE_HEADER_STR_LEN  ZBX_CONST_STRLEN(COOKIE_HEADER_STR)
39 -       CURLcode        err;
40 -       char            *line;
41 -       int             ret = SUCCEED;
42 +
43 +       char    *line;
44  
45         while (NULL != (line = zbx_http_get_header(&headers)))
46         {
47                 if (0 == strncmp(COOKIE_HEADER_STR, line, COOKIE_HEADER_STR_LEN))
48 -               {
49 -                       if (CURLE_OK != (err = curl_easy_setopt(easyhandle, CURLOPT_COOKIE, (line +
50 -                                                               COOKIE_HEADER_STR_LEN * sizeof(char)))))
51 -                       {
52 -                               ret = FAIL;
53 -
54 -                               if (NULL != error)
55 -                                       *error = zbx_strdup(*error, curl_easy_strerror(err));
56 -
57 -                               zbx_free(line);
58 -                               goto out;
59 -                       }
60 -               }
61 +                       *header_cookie = zbx_strdup(*header_cookie, line + COOKIE_HEADER_STR_LEN);
62                 else
63                         *headers_slist = curl_slist_append(*headers_slist, line);
64  
65                 zbx_free(line);
66         }
67  
68 -       if (CURLE_OK != (err = curl_easy_setopt(easyhandle, CURLOPT_HTTPHEADER, *headers_slist)))
69 -       {
70 -               ret = FAIL;
71 -
72 -               if (NULL != error)
73 -                       *error = zbx_strdup(*error, curl_easy_strerror(err));
74 -       }
75 -
76 -out:
77 -       return ret;
78  #undef COOKIE_HEADER_STR
79  #undef COOKIE_HEADER_STR_LEN
80  }
81 @@ -746,6 +718,7 @@ static void process_httptest(DC_HOST *host, zbx_httptest_t *httptest)
82         while (NULL != (row = DBfetch(result)))
83         {
84                 struct curl_slist       *headers_slist = NULL;
85 +               char                    *header_cookie = NULL;
86  
87                 /* NOTE: do not break or return from this block! */
88                 /*       process_step_data() call is required! */
89 @@ -840,14 +813,23 @@ static void       process_httptest(DC_HOST *host, zbx_httptest_t *httptest)
90  
91                 /* headers defined in a step overwrite headers defined in scenario */
92                 if (NULL != httpstep.headers && '\0' != *httpstep.headers)
93 +                       add_http_headers(httpstep.headers, &headers_slist, &header_cookie);
94 +               else if (NULL != httptest->headers && '\0' != *httptest->headers)
95 +                       add_http_headers(httptest->headers, &headers_slist, &header_cookie);
96 +
97 +               err = curl_easy_setopt(easyhandle, CURLOPT_COOKIE, header_cookie);
98 +               zbx_free(header_cookie);
99 +
100 +               if (CURLE_OK != err)
101                 {
102 -                       if (FAIL == add_http_headers(easyhandle, httpstep.headers, &headers_slist, &err_str))
103 -                               goto httpstep_error;
104 +                       err_str = zbx_strdup(err_str, curl_easy_strerror(err));
105 +                       goto httpstep_error;
106                 }
107 -               else if (NULL != httptest->headers && '\0' != *httptest->headers)
108 +
109 +               if (CURLE_OK != (err = curl_easy_setopt(easyhandle, CURLOPT_HTTPHEADER, headers_slist)))
110                 {
111 -                       if (FAIL == add_http_headers(easyhandle, httptest->headers, &headers_slist, &err_str))
112 -                               goto httpstep_error;
113 +                       err_str = zbx_strdup(err_str, curl_easy_strerror(err));
114 +                       goto httpstep_error;
115                 }
116  
117                 /* enable/disable fetching the body */
This page took 0.070049 seconds and 3 git commands to generate.