]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-http: message parser: Don't create the connection_options array, unless it is...
authorStephan Bosch <stephan.bosch@dovecot.fi>
Sat, 4 Feb 2017 13:03:25 +0000 (14:03 +0100)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 17 Feb 2017 09:32:32 +0000 (11:32 +0200)
src/lib-http/http-message-parser.c
src/lib-http/http-request.c

index b0e626292bc05b6062c41fc8325b3e99686ff76e..073b23d83313be1a1ab434bb6eaf146144abecfe 100644 (file)
@@ -62,7 +62,6 @@ void http_message_parser_restart(struct http_message_parser *parser,
        }
        parser->msg.date = (time_t)-1;
        parser->msg.header = http_header_create(parser->msg.pool, 32);
-       p_array_init(&parser->msg.connection_options, parser->msg.pool, 4);
 }
 
 int http_message_parse_version(struct http_message_parser *parser)
@@ -165,6 +164,8 @@ http_message_parse_header(struct http_message_parser *parser,
                                num_tokens++;
                                if (strcasecmp(option, "close") == 0)
                                        parser->msg.connection_close = TRUE;
+                               if (!array_is_created(&parser->msg.connection_options))
+                                       p_array_init(&parser->msg.connection_options, parser->msg.pool, 4);
                                opt_idx = array_append_space(&parser->msg.connection_options);
                                *opt_idx = p_strdup(parser->msg.pool, option);
                        }
@@ -360,13 +361,15 @@ int http_message_parse_headers(struct http_message_parser *parser)
                                !msg->connection_close) {
                                const char *const *option;
 
-                               msg->connection_close = TRUE;   
-                               array_foreach(&msg->connection_options, option) {
-                                       if (strcasecmp(*option, "Keep-Alive") == 0) {
-                                               msg->connection_close = FALSE;
-                                               break;
+                               msg->connection_close = TRUE;
+                               if (array_is_created(&parser->msg.connection_options)) {
+                                       array_foreach(&msg->connection_options, option) {
+                                               if (strcasecmp(*option, "Keep-Alive") == 0) {
+                                                       msg->connection_close = FALSE;
+                                                       break;
+                                               }
                                        }
-                               }                       
+                               }
                        }
                        return 1;
                }
index 06d5b2e4e8a7d44acd595fa8c78a5a4395a1d647..836bc001f015afbb28a43f81db4e11dff3f42ea8 100644 (file)
@@ -11,6 +11,8 @@ bool http_request_has_connection_option(const struct http_request *req,
 {
        const char *const *opt_idx;
 
+       if (!array_is_created(&req->connection_options))
+               return FALSE;
        array_foreach(&req->connection_options, opt_idx) {
                if (strcasecmp(*opt_idx, option) == 0)
                        return TRUE;