aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2016-04-15 15:13:07 +0000
committerIngo Schwarze <schwarze@openbsd.org>2016-04-15 15:13:07 +0000
commit7b751d29f53782f11b94b65c913b76fc197dbc8a (patch)
tree3d3b66b12a661c2f5236af9d8db090940cd1eb14
parent66f0529966c19d3a2d436cc41864b9aff362bb79 (diff)
downloadmandoc-7b751d29f53782f11b94b65c913b76fc197dbc8a.tar.gz
mandoc-7b751d29f53782f11b94b65c913b76fc197dbc8a.tar.zst
mandoc-7b751d29f53782f11b94b65c913b76fc197dbc8a.zip
Fix parsing of PATH_INFO if both a section directory and an
architecture subdirectory are specified. Issue reported by tb@.
-rw-r--r--cgi.c32
1 files changed, 14 insertions, 18 deletions
diff --git a/cgi.c b/cgi.c
index dee2ad7c..2b521e21 100644
--- a/cgi.c
+++ b/cgi.c
@@ -1,4 +1,4 @@
-/* $Id: cgi.c,v 1.126 2016/04/15 01:34:51 schwarze Exp $ */
+/* $Id: cgi.c,v 1.127 2016/04/15 15:13:07 schwarze Exp $ */
/*
* Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014, 2015, 2016 Ingo Schwarze <schwarze@usta.de>
@@ -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);
}
}