summaryrefslogtreecommitdiff
path: root/usr.bin/mandoc/cgi.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2016-04-15 15:13:03 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2016-04-15 15:13:03 +0000
commitb4323358431548bc3774a4ee393a48c12cb0b441 (patch)
tree6718d0a5b13bd5f8223679f039999cdc330fbccc /usr.bin/mandoc/cgi.c
parent02c77acc6bb20a35fce03f66108e7d38f3763106 (diff)
Fix parsing of PATH_INFO if both a section directory and an
architecture subdirectory are specified. Issue reported by tb@.
Diffstat (limited to 'usr.bin/mandoc/cgi.c')
-rw-r--r--usr.bin/mandoc/cgi.c32
1 files changed, 14 insertions, 18 deletions
diff --git a/usr.bin/mandoc/cgi.c b/usr.bin/mandoc/cgi.c
index cd6cb0c3945..178561fb1f0 100644
--- a/usr.bin/mandoc/cgi.c
+++ b/usr.bin/mandoc/cgi.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cgi.c,v 1.65 2016/04/15 01:33:48 schwarze Exp $ */
+/* $OpenBSD: cgi.c,v 1.66 2016/04/15 15:13:02 schwarze Exp $ */
/*
* Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014, 2015, 2016 Ingo Schwarze <schwarze@usta.de>
@@ -1083,7 +1083,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;
@@ -1113,23 +1113,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);
}
}