gmnisrv: "freeze" when a cgi-enabled URI is accessed with missing index file

gmnisrv "freezes" when you access a route with cgi=on, no index specified in the config and the called URI does not contain a path to a cgi script.

E.g. you only have a script.sh in the root dir and call gemini://gemini.capsule (instead of gemini://gemini.capsule/script.sh).

Expected behaviour is to return a 51 NOT FOUND.

I assume currently it gets stuck in serve_request and does not respond to any request (no matter which route is accessed).

Assigned to
7 months ago
7 months ago
No labels applied.

~rwa 7 months ago

I tracked it down to the special handling of cgi-enabled routes, when the requested file does not exist. But to be honest: i currently don't get behind the idea of this special handling, but there's a strange feeling it might be there for a reason.

diff --git a/src/serve.c b/src/serve.c
index 74bb979..11bcb0c 100644
--- a/src/serve.c
+++ b/src/serve.c
@@ -398,32 +398,6 @@ serve_request(struct gmnisrv_client *client)
        struct stat st;
        while (true) {
                if ((n = stat(real_path, &st)) != 0) {
-                       if (route->cgi) {
-                               const char *new;
-                               strcpy(temp_path, client_path);
-                               new = basename((char *)temp_path);
-                               size_t l = strlen(new), q = strlen(pathinfo);
-                               memmove(&pathinfo[l + 1], pathinfo, q);
-                               pathinfo[0] = '/';
-                               memcpy(&pathinfo[1], new, l);
-                               strcpy(temp_path, client_path);
-                               new = dirname((char *)temp_path);
-                               strcpy(client_path, new);
-                               strcpy(temp_path, real_path);
-                               new = dirname((char *)temp_path);
-                               strcpy(real_path, new);
-                               if (route_match(route, client_path, &url_path)) {
-                                       n = snprintf(real_path, sizeof(real_path),
-                                               "%s%s", route->root, url_path);
-                                       assert((size_t)n < sizeof(real_path));
-                                       continue;
-                               }
-                       }
                                GEMINI_STATUS_NOT_FOUND, "Not found", NULL);

~sircmpwn REPORTED FIXED 7 months ago

~rwa 7 months ago

Not fixed for me as of 02a386b5

~rwa FIXED REPORTED 7 months ago

~ecs 7 months ago

Fixed in cb042d6263a0f6800b298373b24a64b407aaf2f0

That strange handling is in order to support $PATH_INFO, the fix was to abort the request if S_ISDIR and stat(real_path) != 0 after appending index.gmi

~sircmpwn REPORTED FIXED 7 months ago

Register here or Log in to comment, or comment via email.