]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Fix parsing of urls with numeric password
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 5 Jun 2018 12:42:36 +0000 (13:42 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 5 Jun 2018 12:42:36 +0000 (13:42 +0100)
src/libserver/url.c

index 23826d51b39ebf74cbeaab128f9fae2665b05afd..8e4cb21332d5598bd071f6e82fcc0853d275c358 100644 (file)
@@ -1012,13 +1012,45 @@ rspamd_web_parse (struct http_parser_url *u, const gchar *str, gsize len,
                                break;
                        case parse_port_password:
                                if (g_ascii_isdigit (t)) {
-                                       /* XXX: that breaks urls with passwords starting with number */
-                                       st = parse_port;
-                                       c = slash;
-                                       p--;
-                                       SET_U (u, UF_HOST);
-                                       p++;
-                                       c = p;
+                                       const gchar *tmp = p;
+
+                                       while (tmp < last) {
+                                               if (!g_ascii_isdigit (*tmp)) {
+                                                       if (*tmp == '/' || *tmp == '#' || *tmp == '?') {
+                                                               /* Port + something */
+                                                               st = parse_port;
+                                                               c = slash;
+                                                               p--;
+                                                               SET_U (u, UF_HOST);
+                                                               p++;
+                                                               c = p;
+                                                               break;
+                                                       }
+                                                       else {
+                                                               /* Not a port, bad character at the end */
+                                                               break;
+                                                       }
+                                               }
+                                               tmp ++;
+                                       }
+
+                                       if (tmp == last) {
+                                               /* Host + port only */
+                                               st = parse_port;
+                                               c = slash;
+                                               p--;
+                                               SET_U (u, UF_HOST);
+                                               p++;
+                                               c = p;
+                                       }
+
+                                       if (st != parse_port) {
+                                               /* Fallback to user:password */
+                                               p = slash;
+                                               c = slash;
+                                               user_seen = TRUE;
+                                               st = parse_user;
+                                       }
                                }
                                else {
                                        /* Rewind back */