=================================================================== RCS file: /cvs/mandoc/cgi.c,v retrieving revision 1.157 retrieving revision 1.161 diff -u -p -r1.157 -r1.161 --- mandoc/cgi.c 2018/05/18 14:23:00 1.157 +++ mandoc/cgi.c 2018/10/19 21:10:56 1.161 @@ -1,7 +1,7 @@ -/* $Id: cgi.c,v 1.157 2018/05/18 14:23:00 schwarze Exp $ */ +/* $Id: cgi.c,v 1.161 2018/10/19 21:10:56 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 @@ -69,6 +69,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 +91,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 +318,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 +414,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 +450,7 @@ resp_searchform(const struct req *req, enum focus focu printf(" selected=\"selected\""); puts(">All Architectures"); for (i = 0; i < arch_MAX; i++) { - printf("