aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/cgi.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2014-07-25 16:43:37 +0000
committerIngo Schwarze <schwarze@openbsd.org>2014-07-25 16:43:37 +0000
commit707279602804e036d565d3c797d430debfe746c5 (patch)
treed7d816eadd73bf6189202add52e4d064213819b9 /cgi.c
parent9c6008b72736d076c52853fb8cff8cb8c3dbf893 (diff)
downloadmandoc-707279602804e036d565d3c797d430debfe746c5.tar.gz
mandoc-707279602804e036d565d3c797d430debfe746c5.tar.zst
mandoc-707279602804e036d565d3c797d430debfe746c5.zip
clean up pg_show() to not modify a string returned from getenv(3)
Diffstat (limited to 'cgi.c')
-rw-r--r--cgi.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/cgi.c b/cgi.c
index e7fbbdd2..08c32bdb 100644
--- a/cgi.c
+++ b/cgi.c
@@ -1,4 +1,4 @@
-/* $Id: cgi.c,v 1.83 2014/07/25 16:07:13 schwarze Exp $ */
+/* $Id: cgi.c,v 1.84 2014/07/25 16:43:37 schwarze Exp $ */
/*
* Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014 Ingo Schwarze <schwarze@usta.de>
@@ -908,20 +908,23 @@ resp_show(const struct req *req, const char *file)
}
static void
-pg_show(struct req *req, const char *path)
+pg_show(struct req *req, const char *fullpath)
{
- char *sub;
+ char *manpath;
+ const char *file;
- if (NULL == path || NULL == (sub = strchr(path, '/'))) {
+ if ((file = strchr(fullpath, '/')) == NULL) {
pg_error_badrequest(
"You did not specify a page to show.");
return;
}
- *sub++ = '\0';
+ manpath = mandoc_strndup(fullpath, file - fullpath);
+ file++;
- if ( ! validate_manpath(req, path)) {
+ if ( ! validate_manpath(req, manpath)) {
pg_error_badrequest(
"You specified an invalid manpath.");
+ free(manpath);
return;
}
@@ -931,27 +934,29 @@ pg_show(struct req *req, const char *path)
* relative to the manpath root.
*/
- if (-1 == chdir(path)) {
+ if (chdir(manpath) == -1) {
fprintf(stderr, "chdir %s: %s\n",
- path, strerror(errno));
+ manpath, strerror(errno));
pg_error_internal();
+ free(manpath);
return;
}
- if ( ! validate_filename(sub)) {
+ if (strcmp(manpath, "mandoc")) {
+ free(req->q.manpath);
+ req->q.manpath = manpath;
+ } else
+ free(manpath);
+
+ if ( ! validate_filename(file)) {
pg_error_badrequest(
"You specified an invalid manual file.");
return;
}
- if (strcmp(path, "mandoc")) {
- free(req->q.manpath);
- req->q.manpath = mandoc_strdup(path);
- }
-
resp_begin_html(200, NULL);
resp_searchform(req);
- resp_show(req, sub);
+ resp_show(req, file);
resp_end_html();
}