diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2016-04-15 15:13:07 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2016-04-15 15:13:07 +0000 |
commit | 8f2b6a67d98c7a974397d78645d1bcb06304f253 (patch) | |
tree | ad852a28a7e328d4fb4bed24891bf57cf2ca3b8b | |
parent | b1ebd83680bfd8dad238011efcae46f5495e9bb7 (diff) | |
download | mandoc-8f2b6a67d98c7a974397d78645d1bcb06304f253.tar.gz |
Fix parsing of PATH_INFO if both a section directory and an
architecture subdirectory are specified. Issue reported by tb@.
-rw-r--r-- | cgi.c | 30 |
1 files changed, 13 insertions, 17 deletions
@@ -1085,7 +1085,7 @@ main(void) static void path_parse(struct req *req, const char *path) { - int dir_done; + char *dir; req->isquery = 0; req->q.equal = 1; @@ -1115,23 +1115,19 @@ path_parse(struct req *req, const char *path) req->q.query = mandoc_strdup(req->q.query); /* Optional architecture. */ - dir_done = 0; - for (;;) { - if ((req->q.arch = strrchr(req->q.manpath, '/')) == NULL) - break; - *req->q.arch++ = '\0'; - if (dir_done || strncmp(req->q.arch, "man", 3)) { - req->q.arch = mandoc_strdup(req->q.arch); - break; - } + dir = strrchr(req->q.manpath, '/'); + if (dir != NULL && strncmp(dir + 1, "man", 3) != 0) { + *dir++ = '\0'; + req->q.arch = mandoc_strdup(dir); + dir = strrchr(req->q.manpath, '/'); + } else + req->q.arch = NULL; - /* Optional directory name. */ - req->q.arch += 3; - if (*req->q.arch != '\0') { - free(req->q.sec); - req->q.sec = mandoc_strdup(req->q.arch); - } - dir_done = 1; + /* Optional directory name. */ + if (dir != NULL && strncmp(dir + 1, "man", 3) == 0) { + *dir++ = '\0'; + free(req->q.sec); + req->q.sec = mandoc_strdup(dir + 3); } } |