httpd: extract query string only after proxying check
authorDenys Vlasenko <vda.linux@googlemail.com>
Tue, 16 Apr 2019 11:35:56 +0000 (13:35 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Tue, 16 Apr 2019 11:35:56 +0000 (13:35 +0200)
function                                             old     new   delta
handle_incoming_and_exit                            2398    2370     -28

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
networking/httpd.c

index 7cbf9afefb80d6e9e5945013660e8b201a944380..2b0acd7dc165621910882087628b97892325f350 100644 (file)
@@ -411,7 +411,7 @@ struct globals {
        char *rmt_ip_str;       /* for $REMOTE_ADDR and $REMOTE_PORT */
        const char *bind_addr_or_port;
 
-       const char *g_query;
+       char *g_query;
        const char *opt_c_configFile;
        const char *home_httpd;
        const char *index_page;
@@ -2166,14 +2166,6 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr)
        strcpy(urlcopy, urlp);
        /* NB: urlcopy ptr is never changed after this */
 
-       /* Extract url args if present */
-       /* g_query = NULL; - already is */
-       tptr = strchr(urlcopy, '?');
-       if (tptr) {
-               *tptr++ = '\0';
-               g_query = tptr;
-       }
-
 #if ENABLE_FEATURE_HTTPD_PROXY
        {
                int proxy_fd;
@@ -2194,12 +2186,10 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr)
                         * When /urlSFX is requested, reverse proxy it
                         * to http://hostname[:port]/new/pathSFX
                         */
-                       fdprintf(proxy_fd, "%s %s%s%s%s %s\r\n",
+                       fdprintf(proxy_fd, "%s %s%s %s\r\n",
                                        prequest, /* "GET" or "POST" */
                                        proxy_entry->url_to, /* "/new/path" */
                                        urlcopy + strlen(proxy_entry->url_from), /* "SFX" */
-                                       (g_query ? "?" : ""), /* "?" (maybe) */
-                                       (g_query ? g_query : ""), /* query string (maybe) */
                                        HTTP_slash /* HTTP/xyz" or "" */
                        );
                        cgi_io_loop_and_exit(proxy_fd, proxy_fd, /*max POST length:*/ INT_MAX);
@@ -2207,6 +2197,11 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr)
        }
 #endif
 
+       /* Extract url args if present */
+       g_query = strchr(urlcopy, '?');
+       if (g_query)
+               *g_query++ = '\0';
+
        /* Decode URL escape sequences */
        tptr = percent_decode_in_place(urlcopy, /*strict:*/ 1);
        if (tptr == NULL)