=================================================================== RCS file: /cvs/mandoc/cgi.c,v retrieving revision 1.157 retrieving revision 1.162 diff -u -p -r1.157 -r1.162 --- mandoc/cgi.c 2018/05/18 14:23:00 1.157 +++ mandoc/cgi.c 2018/12/13 11:55:46 1.162 @@ -1,7 +1,7 @@ -/* $Id: cgi.c,v 1.157 2018/05/18 14:23:00 schwarze Exp $ */ +/* $Id: cgi.c,v 1.162 2018/12/13 11:55:46 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons - * Copyright (c) 2014, 2015, 2016, 2017 Ingo Schwarze + * Copyright (c) 2014, 2015, 2016, 2017, 2018 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -38,6 +38,7 @@ #include "roff.h" #include "mdoc.h" #include "man.h" +#include "mandoc_parse.h" #include "main.h" #include "manconf.h" #include "mansearch.h" @@ -69,6 +70,7 @@ enum focus { static void html_print(const char *); static void html_putchar(char); static int http_decode(char *); +static void http_encode(const char *p); static void parse_manpath_conf(struct req *); static void parse_path_info(struct req *req, const char *path); static void parse_query_string(struct req *, const char *); @@ -90,6 +92,7 @@ static void resp_format(const struct req *, const ch static void resp_searchform(const struct req *, enum focus); static void resp_show(const struct req *, const char *); static void set_query_attr(char **, char **); +static int validate_arch(const char *); static int validate_filename(const char *); static int validate_manpath(const struct req *, const char *); static int validate_urifrag(const char *); @@ -316,6 +319,18 @@ http_decode(char *p) } static void +http_encode(const char *p) +{ + for (; *p != '\0'; p++) { + if (isalnum((unsigned char)*p) == 0 && + strchr("-._~", *p) == NULL) + printf("%%%02.2X", (unsigned char)*p); + else + putchar(*p); + } +} + +static void resp_begin_http(int code, const char *msg) { @@ -400,7 +415,7 @@ resp_searchform(const struct req *req, enum focus focu /* Write query input box. */ - printf(" q.query != NULL) html_print(req->q.query); printf( "\" size=\"40\""); @@ -436,7 +451,7 @@ resp_searchform(const struct req *req, enum focus focu printf(" selected=\"selected\""); puts(">All Architectures"); for (i = 0; i < arch_MAX; i++) { - printf("