phroxy

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.z3bra.org/phroxy.git
Log | Files | Refs | LICENSE

commit 1ae65b7b2d472fd5236139bb8a6f1ed96ac55ef9
parent 65b08e3fe1928eb217aa59c7f936d13b9a6a5031
Author: Willy Goiffon <dev@z3bra.org>
Date:   Mon, 14 Sep 2020 16:10:37 +0200

Add checks to original URL parsing

Diffstat:
Mphroxy.c | 35+++++++++++++++++++++--------------
1 file changed, 21 insertions(+), 14 deletions(-)

diff --git a/phroxy.c b/phroxy.c @@ -343,24 +343,31 @@ phroxy(char *url) { int sock; size_t len; - char item = 0; - char *hole, *path, *host, *port; - char *data = NULL; + char *hole, *item, *path, *host, *port; + char *data = NULL, *srch = NULL; - hole = url + 1; - hole = strsep(&hole, "/"); - item = hole[strlen(hole) + 1]; - path = hole + strlen(hole) + 2; + url++; + hole = strsep(&url, "/"); + if (!hole) { + print404(); + return 1; + } - host = strtok(hole, ":"); - port = strtok(NULL, "\0"); + host = strsep(&hole, ":"); + port = strsep(&hole, "\0"); if (!port) port = "70"; - if (!hole || !item) { - print404(); - return 1; - } + item = strsep(&url, "/"); + if (!item) + item = "1"; + + path = strsep(&url, "\0"); + if (!path) + path = "/"; + + if((srch = strchr(path, '?'))) + *srch = '\t'; sock = connectto(host, port); if (!sendselector(sock, path)) @@ -371,7 +378,7 @@ phroxy(char *url) if (!data) return 1; - serveitem(item, data, len); + serveitem(*item, data, len); return 0; }