summaryrefslogtreecommitdiff
path: root/system/mandoc/cgi-gz.patch
diff options
context:
space:
mode:
Diffstat (limited to 'system/mandoc/cgi-gz.patch')
-rw-r--r--system/mandoc/cgi-gz.patch77
1 files changed, 77 insertions, 0 deletions
diff --git a/system/mandoc/cgi-gz.patch b/system/mandoc/cgi-gz.patch
new file mode 100644
index 000000000..ac506b797
--- /dev/null
+++ b/system/mandoc/cgi-gz.patch
@@ -0,0 +1,77 @@
+Handle the case where some of the entries in the manpath are gzipped by
+removing the .gz extension and allowing mparse_open to add it back and
+mark the page as gzipped. This is part of the documented contract for
+mparse_open, see mandoc(3).
+
+--- mandoc-1.14.5/cgi.c 2019-03-10 04:56:43.000000000 -0500
++++ mandoc-1.14.5/cgi.c 2020-06-05 15:54:05.681060852 -0500
+@@ -93,7 +93,7 @@ static void resp_searchform(const stru
+ 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_filename(char *);
+ static int validate_manpath(const struct req *, const char *);
+ static int validate_urifrag(const char *);
+
+@@ -517,8 +509,13 @@ validate_arch(const char *arch)
+ }
+
+ static int
+-validate_filename(const char *file)
++validate_filename(char *file)
+ {
++ char *cp;
++
++ cp = strrchr(file, '.');
++ if (cp != NULL && ! strcmp(cp + 1, "gz"))
++ *cp = '\0';
+
+ if ('.' == file[0] && '/' == file[1])
+ file += 2;
+@@ -854,14 +862,15 @@ resp_format(const struct req *req, const
+ int fd;
+ int usepath;
+
+- if (-1 == (fd = open(file, O_RDONLY, 0))) {
+- puts("<p>You specified an invalid manual file.</p>");
+- return;
+- }
+-
+ mchars_alloc();
+ mp = mparse_alloc(MPARSE_SO | MPARSE_UTF8 | MPARSE_LATIN1 |
+ MPARSE_VALIDATE, MANDOC_OS_OTHER, req->q.manpath);
++
++ if (-1 == (fd = mparse_open(mp, file))) {
++ puts("<p>You specified an invalid manual file.</p>");
++ goto out;
++ }
++
+ mparse_readfd(mp, fd, file);
+ close(fd);
+ meta = mparse_result(mp);
+@@ -882,10 +891,11 @@ resp_format(const struct req *req, const
+ html_man(vp, meta);
+
+ html_free(vp);
+- mparse_free(mp);
+- mchars_free();
+ free(conf.man);
+ free(conf.style);
++out:
++ mparse_free(mp);
++ mchars_free();
+ }
+
+ static void
+@@ -904,8 +914,8 @@ resp_show(const struct req *req, const c
+ static void
+ pg_show(struct req *req, const char *fullpath)
+ {
+- char *manpath;
+- const char *file;
++ char *manpath;
++ char *file;
+
+ if ((file = strchr(fullpath, '/')) == NULL) {
+ pg_error_badrequest(