-/* $Id: cgi.c,v 1.16 2014/07/19 11:35:09 schwarze Exp $ */
+/* $Id: cgi.c,v 1.17 2014/07/19 13:15:07 schwarze Exp $ */
/*
* Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014 Ingo Schwarze <schwarze@usta.de>
puts("<!-- End search form. //-->");
}
+static int
+validate_manpath(const struct req *req, const char* manpath)
+{
+ size_t i;
+
+ if ( ! strcmp(manpath, "mandoc"))
+ return(1);
+
+ for (i = 0; i < req->psz; i++)
+ if ( ! strcmp(manpath, req->p[i]))
+ return(1);
+
+ return(0);
+}
+
static int
validate_filename(const char *file)
{
}
*sub++ = '\0';
+ if ( ! validate_manpath(req, path)) {
+ pg_error_badrequest(
+ "You specified an invalid manpath.");
+ return;
+ }
+
/*
* Begin by chdir()ing into the manpath.
* This way we can pick up the database files, which are
*/
if (-1 == chdir(path)) {
- pg_error_badrequest(
- "You specified an invalid manpath.");
+ fprintf(stderr, "chdir %s: %s\n",
+ path, strerror(errno));
+ pg_error_internal();
return;
}
*/
if (-1 == (chdir(req->q.manpath))) {
- pg_error_badrequest(
- "You specified an invalid manpath.");
+ fprintf(stderr, "chdir %s: %s\n",
+ req->q.manpath, strerror(errno));
+ pg_error_internal();
return;
}
if (NULL != (querystring = getenv("QUERY_STRING")))
http_parse(&req, querystring);
+ if ( ! validate_manpath(&req, req.q.manpath)) {
+ pg_error_badrequest(
+ "You specified an invalid manpath.");
+ return(EXIT_FAILURE);
+ }
+
/* Dispatch to the three different pages. */
path = getenv("PATH_INFO");