summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZach DeCook <zachdecook@librem.one>2021-01-20 23:46:59 -0500
committerDrew DeVault <sir@cmpwn.com>2021-01-22 08:15:03 -0500
commitea360fa4c10791c3c720c33470c86923424348fe (patch)
tree89e9afb95190d988cf132b26284bdb598e8f58ec
parentfbef1d34a1abd2614f85afee415fe0f417038efe (diff)
downloadgmnisrv-ea360fa4c10791c3c720c33470c86923424348fe.tar.gz
gmnisrv-ea360fa4c10791c3c720c33470c86923424348fe.tar.xz
gmnisrv-ea360fa4c10791c3c720c33470c86923424348fe.zip
Routing: Fix non-ascii paths
-rw-r--r--src/serve.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/serve.c b/src/serve.c
index 9e2a1c2..99f122e 100644
--- a/src/serve.c
+++ b/src/serve.c
@@ -11,6 +11,7 @@
#include <sys/types.h>
#include <unistd.h>
#include "config.h"
+#include "escape.h"
#include "gemini.h"
#include "log.h"
#include "mime.h"
@@ -377,9 +378,10 @@ serve_request(struct gmnisrv_client *client)
struct gmnisrv_route *route = host->routes;
assert(route);
+ char *client_path = curl_unescape(client->path, 0);
char *url_path = NULL;
while (route) {
- if (route_match(route, client->path, &url_path)) {
+ if (route_match(route, client_path, &url_path)) {
break;
}
@@ -389,6 +391,7 @@ serve_request(struct gmnisrv_client *client)
if (!route) {
client_submit_response(client,
GEMINI_STATUS_NOT_FOUND, "Not found", NULL);
+ free(client_path);
free(url_path);
return;
}
@@ -397,7 +400,6 @@ serve_request(struct gmnisrv_client *client)
// Paths on paths on paths on paths
// My apologies to the stack
- char client_path[PATH_MAX + 1] = "";
char real_path[PATH_MAX + 1] = "";
char pathinfo[PATH_MAX + 1] = "";
char temp_path[PATH_MAX + 1] = "";
@@ -405,10 +407,10 @@ serve_request(struct gmnisrv_client *client)
if ((size_t)n >= sizeof(real_path)) {
client_submit_response(client, GEMINI_STATUS_PERMANENT_FAILURE,
"Request path exceeds PATH_MAX", NULL);
+ free(client_path);
free(url_path);
return;
}
- strcpy(client_path, client->path);
int nlinks = 0;
struct stat st;
@@ -455,6 +457,7 @@ serve_request(struct gmnisrv_client *client)
client_submit_response(client,
GEMINI_STATUS_NOT_FOUND, "Not found", NULL);
+ free(client_path);
free(url_path);
return;
}
@@ -462,6 +465,7 @@ serve_request(struct gmnisrv_client *client)
if (S_ISDIR(st.st_mode)) {
if (route->autoindex) {
serve_autoindex(client, real_path);
+ free(client_path);
free(url_path);
return;
} else {
@@ -485,6 +489,7 @@ serve_request(struct gmnisrv_client *client)
client_submit_response(client,
GEMINI_STATUS_NOT_FOUND,
"Not found", NULL);
+ free(client_path);
free(url_path);
return;
}
@@ -503,6 +508,7 @@ serve_request(struct gmnisrv_client *client)
// Don't serve special files
client_submit_response(client,
GEMINI_STATUS_NOT_FOUND, "Not found", NULL);
+ free(client_path);
free(url_path);
return;
}
@@ -514,9 +520,12 @@ serve_request(struct gmnisrv_client *client)
serve_cgi(client, real_path,
(const char *)client_path,
(const char *)pathinfo);
+ free(client_path);
return;
}
+ free(client_path);
+
FILE *body = fopen(real_path, "r");
if (!body) {
if (errno == ENOENT) {