=================================================================== RCS file: /cvs/mandoc/cgi.c,v retrieving revision 1.114 retrieving revision 1.115 diff -u -p -r1.114 -r1.115 --- mandoc/cgi.c 2015/11/05 20:55:41 1.114 +++ mandoc/cgi.c 2015/11/07 17:58:55 1.115 @@ -1,4 +1,4 @@ -/* $Id: cgi.c,v 1.114 2015/11/05 20:55:41 schwarze Exp $ */ +/* $Id: cgi.c,v 1.115 2015/11/07 17:58:55 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons * Copyright (c) 2014, 2015 Ingo Schwarze @@ -704,12 +704,13 @@ static void catman(const struct req *req, const char *file) { FILE *f; - size_t len; - int i; char *p; + size_t sz; + ssize_t len; + int i; int italic, bold; - if (NULL == (f = fopen(file, "r"))) { + if ((f = fopen(file, "r")) == NULL) { puts("

You specified an invalid manual file.

"); return; } @@ -717,9 +718,12 @@ catman(const struct req *req, const char *file) puts("
\n" "
");
 
-	while (NULL != (p = fgetln(f, &len))) {
+	p = NULL;
+	sz = 0;
+
+	while ((len = getline(&p, &sz, f)) != -1) {
 		bold = italic = 0;
-		for (i = 0; i < (int)len - 1; i++) {
+		for (i = 0; i < len - 1; i++) {
 			/*
 			 * This means that the catpage is out of state.
 			 * Ignore it and keep going (although the
@@ -744,7 +748,7 @@ catman(const struct req *req, const char *file)
 				italic = bold = 0;
 				html_putchar(p[i]);
 				continue;
-			} else if (i + 2 >= (int)len)
+			} else if (i + 2 >= len)
 				continue;
 
 			/* Italic mode. */
@@ -820,11 +824,12 @@ catman(const struct req *req, const char *file)
 		if (bold)
 			printf("");
 
-		if (i == (int)len - 1 && '\n' != p[i])
+		if (i == len - 1 && p[i] != '\n')
 			html_putchar(p[i]);
 
 		putchar('\n');
 	}
+	free(p);
 
 	puts("
\n" "
"); @@ -1134,6 +1139,7 @@ pathgen(struct req *req) FILE *fp; char *dp; size_t dpsz; + ssize_t len; if (NULL == (fp = fopen("manpath.conf", "r"))) { fprintf(stderr, "%s/manpath.conf: %s\n", @@ -1142,12 +1148,14 @@ pathgen(struct req *req) exit(EXIT_FAILURE); } - while (NULL != (dp = fgetln(fp, &dpsz))) { - if ('\n' == dp[dpsz - 1]) - dpsz--; + dp = NULL; + dpsz = 0; + + while ((len = getline(&dp, &dpsz, fp)) != -1) { + if (dp[len - 1] == '\n') + dp[--len] = '\0'; req->p = mandoc_realloc(req->p, (req->psz + 1) * sizeof(char *)); - dp = mandoc_strndup(dp, dpsz); if ( ! validate_urifrag(dp)) { fprintf(stderr, "%s/manpath.conf contains " "unsafe path \"%s\"\n", MAN_DIR, dp); @@ -1161,7 +1169,10 @@ pathgen(struct req *req) exit(EXIT_FAILURE); } req->p[req->psz++] = dp; + dp = NULL; + dpsz = 0; } + free(dp); if ( req->p == NULL ) { fprintf(stderr, "%s/manpath.conf is empty\n", MAN_DIR);