source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: schwarze@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: clean up pg_show() to not modify a string returned from
Date: Fri, 25 Jul 2014 12:43:37 -0400 (EDT)	[thread overview]
Message-ID: <201407251643.s6PGhbKP001720@krisdoz.my.domain> (raw)

Log Message:
-----------
clean up pg_show() to not modify a string returned from getenv(3)

Modified Files:
--------------
    mdocml:
        cgi.c

Revision Data
-------------
Index: cgi.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/cgi.c,v
retrieving revision 1.83
retrieving revision 1.84
diff -Lcgi.c -Lcgi.c -u -p -r1.83 -r1.84
--- cgi.c
+++ cgi.c
@@ -908,20 +908,23 @@ resp_show(const struct req *req, const c
 }
 
 static void
-pg_show(struct req *req, const char *path)
+pg_show(struct req *req, const char *fullpath)
 {
-	char		*sub;
+	char		*manpath;
+	const char	*file;
 
-	if (NULL == path || NULL == (sub = strchr(path, '/'))) {
+	if ((file = strchr(fullpath, '/')) == NULL) {
 		pg_error_badrequest(
 		    "You did not specify a page to show.");
 		return;
 	} 
-	*sub++ = '\0';
+	manpath = mandoc_strndup(fullpath, file - fullpath);
+	file++;
 
-	if ( ! validate_manpath(req, path)) {
+	if ( ! validate_manpath(req, manpath)) {
 		pg_error_badrequest(
 		    "You specified an invalid manpath.");
+		free(manpath);
 		return;
 	}
 
@@ -931,27 +934,29 @@ pg_show(struct req *req, const char *pat
 	 * relative to the manpath root.
 	 */
 
-	if (-1 == chdir(path)) {
+	if (chdir(manpath) == -1) {
 		fprintf(stderr, "chdir %s: %s\n",
-		    path, strerror(errno));
+		    manpath, strerror(errno));
 		pg_error_internal();
+		free(manpath);
 		return;
 	}
 
-	if ( ! validate_filename(sub)) {
+	if (strcmp(manpath, "mandoc")) {
+		free(req->q.manpath);
+		req->q.manpath = manpath;
+	} else
+		free(manpath);
+
+	if ( ! validate_filename(file)) {
 		pg_error_badrequest(
 		    "You specified an invalid manual file.");
 		return;
 	}
 
-	if (strcmp(path, "mandoc")) {
-		free(req->q.manpath);
-		req->q.manpath = mandoc_strdup(path);
-	}
-
 	resp_begin_html(200, NULL);
 	resp_searchform(req);
-	resp_show(req, sub);
+	resp_show(req, file);
 	resp_end_html();
 }
 
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

                 reply	other threads:[~2014-07-25 16:43 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201407251643.s6PGhbKP001720@krisdoz.my.domain \
    --to=schwarze@mdocml.bsd.lv \
    --cc=source@mdocml.bsd.lv \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).