aboutsummaryrefslogtreecommitdiff
path: root/fcgi.c
diff options
context:
space:
mode:
authorOmar Polo <op@omarpolo.com>2023-08-08 18:07:54 +0000
committerOmar Polo <op@omarpolo.com>2023-08-08 18:07:54 +0000
commita1e159c917d4cc0bf27e3faedf69e8d720162936 (patch)
treeb74704b6568b840eefb42c65f0d1adb69a6d8627 /fcgi.c
parent03d671e2aa44271e6feb5dc6b1f20f833735d917 (diff)
fix PATH_INFO / SCRIPT_NAME splitting
Diffstat (limited to 'fcgi.c')
-rw-r--r--fcgi.c35
1 files changed, 19 insertions, 16 deletions
diff --git a/fcgi.c b/fcgi.c
index cd8f667..69613d2 100644
--- a/fcgi.c
+++ b/fcgi.c
@@ -374,37 +374,43 @@ void
fcgi_req(struct client *c, struct location *loc)
{
char buf[22], path[GEMINI_URL_LEN];
- char *qs, *p, *pathinfo, *scriptname = NULL;
+ char *scriptname, *qs;
+ const char *stripped;
size_t l;
time_t tim;
struct tm tminfo;
struct envlist *p;
+ fcgi_begin_request(c->cgibev);
+
+ scriptname = "";
TAILQ_FOREACH(p, &loc->params, envs) {
if (!strcmp(p->name, "SCRIPT_NAME")) {
scriptname = p->value;
break;
}
}
- if (scriptname == NULL)
- scriptname = "";
- p = strip_path(c->iri.path, loc->fcgi_strip);
- if (*p != '/')
- snprintf(path, sizeof(path), "/%s", p);
+ stripped = strip_path(c->iri.path, loc->fcgi_strip);
+ if (*stripped != '/')
+ snprintf(path, sizeof(path), "/%s", stripped);
else
- strlcpy(path, p, sizeof(path));
+ strlcpy(path, stripped, sizeof(path));
- pathinfo = path;
l = strlen(scriptname);
while (l > 0 && scriptname[l - 1] == '/')
l--;
- if (!strncmp(scriptname, pathinfo, l))
- pathinfo += l;
-
- log_debug("scriptname=%s ; pathinfo=%s", scriptname, pathinfo);
+ if (!strncmp(scriptname, path, l) && (path[l] == '/' ||
+ path[l] == '\0')) {
+ log_warnx("in here! %zu %s", l, path);
+ fcgi_send_param(c->cgibev, "PATH_INFO", &path[l]);
+ path[l] = '\0';
+ fcgi_send_param(c->cgibev, "SCRIPT_NAME", path);
+ } else {
+ fcgi_send_param(c->cgibev, "PATH_INFO", stripped);
+ fcgi_send_param(c->cgibev, "SCRIPT_NAME", scriptname);
+ }
- fcgi_begin_request(c->cgibev);
fcgi_send_param(c->cgibev, "GATEWAY_INTERFACE", "CGI/1.1");
fcgi_send_param(c->cgibev, "GEMINI_URL_PATH", c->iri.path);
fcgi_send_param(c->cgibev, "QUERY_STRING", c->iri.query);
@@ -415,9 +421,6 @@ fcgi_req(struct client *c, struct location *loc)
fcgi_send_param(c->cgibev, "SERVER_PROTOCOL", "GEMINI");
fcgi_send_param(c->cgibev, "SERVER_SOFTWARE", GMID_VERSION);
- fcgi_send_param(c->cgibev, "SCRIPT_NAME", scriptname);
- fcgi_send_param(c->cgibev, "PATH_INFO", pathinfo);
-
if (*c->iri.query != '\0' &&
strchr(c->iri.query, '=') == NULL &&
(qs = strdup(c->iri.query)) != NULL) {