From a43df5a0b13086e6b1ce40aa4fa3f046584f2009 Mon Sep 17 00:00:00 2001 From: schwarze Date: Tue, 5 Jul 2022 14:03:35 +0000 Subject: [PATCH] Somehow, the content of header.html ended up before and outside the
element. Fix this by moving it into the
element where it belongs. While here, also wrap footer.html in a
element. --- usr.bin/mandoc/cgi.c | 74 +++++++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 31 deletions(-) diff --git a/usr.bin/mandoc/cgi.c b/usr.bin/mandoc/cgi.c index a23cdfcee81..0b941b6463d 100644 --- a/usr.bin/mandoc/cgi.c +++ b/usr.bin/mandoc/cgi.c @@ -1,6 +1,6 @@ -/* $OpenBSD: cgi.c,v 1.116 2022/07/04 16:20:09 schwarze Exp $ */ +/* $OpenBSD: cgi.c,v 1.117 2022/07/05 14:03:35 schwarze Exp $ */ /* - * Copyright (c) 2014-2019, 2021 Ingo Schwarze + * Copyright (c) 2014-2019, 2021, 2022 Ingo Schwarze * Copyright (c) 2011, 2012 Kristaps Dzonsons * Copyright (c) 2022 Anna Vyalkova * @@ -83,10 +83,10 @@ static void pg_search(const struct req *); static void pg_searchres(const struct req *, struct manpage *, size_t); static void pg_show(struct req *, const char *); -static void resp_begin_html(int, const char *, const char *); +static int resp_begin_html(int, const char *, const char *); static void resp_begin_http(int, const char *); static void resp_catman(const struct req *, const char *); -static void resp_copy(const char *); +static int resp_copy(const char *, const char *); static void resp_end_html(void); static void resp_format(const struct req *, const char *); static void resp_searchform(const struct req *, enum focus); @@ -349,22 +349,26 @@ resp_begin_http(int code, const char *msg) fflush(stdout); } -static void -resp_copy(const char *filename) +static int +resp_copy(const char *element, const char *filename) { char buf[4096]; ssize_t sz; int fd; - if ((fd = open(filename, O_RDONLY)) != -1) { - fflush(stdout); - while ((sz = read(fd, buf, sizeof(buf))) > 0) - write(STDOUT_FILENO, buf, sz); - close(fd); - } + if ((fd = open(filename, O_RDONLY)) == -1) + return 0; + + if (element != NULL) + printf("<%s>\n", element); + fflush(stdout); + while ((sz = read(fd, buf, sizeof(buf))) > 0) + write(STDOUT_FILENO, buf, sz); + close(fd); + return 1; } -static void +static int resp_begin_html(int code, const char *msg, const char *file) { const char *name, *sec, *cp; @@ -410,14 +414,14 @@ resp_begin_html(int code, const char *msg, const char *file) "\n", CUSTOMIZE_TITLE); - resp_copy(MAN_DIR "/header.html"); + return resp_copy("header", MAN_DIR "/header.html"); } static void resp_end_html(void) { - - resp_copy(MAN_DIR "/footer.html"); + if (resp_copy("footer", MAN_DIR "/footer.html")) + puts("
"); puts("\n" ""); @@ -428,8 +432,7 @@ resp_searchform(const struct req *req, enum focus focus) { int i; - printf("
\n" - "
\n" "
\n" " Manual Page Search Parameters\n", @@ -497,8 +500,7 @@ resp_searchform(const struct req *req, enum focus focus) } puts("
\n" - "
\n" - "
"); + ""); } static int @@ -553,10 +555,11 @@ validate_filename(const char *file) static void pg_index(const struct req *req) { - - resp_begin_html(200, NULL, NULL); + if (resp_begin_html(200, NULL, NULL) == 0) + puts("
"); resp_searchform(req, FOCUS_QUERY); - printf("
\n" + printf("
\n" + "
\n" "

\n" "This web interface is documented in the\n" ""); resp_searchform(req, FOCUS_QUERY); + puts("

"); puts("
"); puts("

"); puts(user_msg); @@ -589,8 +594,8 @@ pg_noresult(const struct req *req, int code, const char *http_msg, static void pg_error_badrequest(const char *msg) { - - resp_begin_html(400, "Bad Request", NULL); + if (resp_begin_html(400, "Bad Request", NULL)) + puts("

"); puts("
\n" "

Bad Request

\n" "

"); @@ -598,14 +603,15 @@ pg_error_badrequest(const char *msg) printf("Try again from the\n" "main page.\n" "

\n" - "
", scriptname); + "\n", scriptname); resp_end_html(); } static void pg_error_internal(void) { - resp_begin_html(500, "Internal Server Error", NULL); + if (resp_begin_html(500, "Internal Server Error", NULL)) + puts(""); puts("

Internal Server Error

"); resp_end_html(); } @@ -637,6 +643,7 @@ pg_searchres(const struct req *req, struct manpage *r, size_t sz) size_t i, iuse; int archprio, archpriouse; int prio, priouse; + int have_header; for (i = 0; i < sz; i++) { if (validate_filename(r[i].file)) @@ -703,12 +710,15 @@ pg_searchres(const struct req *req, struct manpage *r, size_t sz) priouse = prio; iuse = i; } - resp_begin_html(200, NULL, r[iuse].file); + have_header = resp_begin_html(200, NULL, r[iuse].file); } else - resp_begin_html(200, NULL, NULL); + have_header = resp_begin_html(200, NULL, NULL); + if (have_header == 0) + puts("
"); resp_searchform(req, req->q.equal || sz == 1 ? FOCUS_NONE : FOCUS_QUERY); + puts("
"); if (sz > 1) { puts("