From 36cd292d7d6aabeb37153a23e56edf19634ea118 Mon Sep 17 00:00:00 2001 From: iedowse Date: Tue, 14 May 2002 23:24:28 +0000 Subject: Use fgetln to remove the static limit on the length of lines in /etc/exports. Oversized lines were unlikely due to the large 10k limit, but any found would cause mountd to exit with an error. Also fix one or two compiler warnings. --- usr.sbin/mountd/mountd.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'usr.sbin/mountd') diff --git a/usr.sbin/mountd/mountd.c b/usr.sbin/mountd/mountd.c index 3061d2f..b219c76 100644 --- a/usr.sbin/mountd/mountd.c +++ b/usr.sbin/mountd/mountd.c @@ -54,6 +54,8 @@ static const char rcsid[] = #include #include #include +#include +#include #include #include @@ -268,7 +270,7 @@ main(argc, argv) int udpsock, tcpsock, udp6sock, tcp6sock; int xcreated = 0, s; int one = 1; - int c, error; + int c; udp6conf = tcp6conf = NULL; udp6sock = tcp6sock = NULL; @@ -874,8 +876,8 @@ put_exlist(dp, xdrsp, adp, putdefp) return (0); } -#define LINESIZ 10240 -char line[LINESIZ]; +char *line; +int linesize; FILE *exp_file; /* @@ -1997,7 +1999,7 @@ int get_line() { char *p, *cp; - int len; + size_t len; int totlen, cont_line; /* @@ -2006,9 +2008,8 @@ get_line() p = line; totlen = 0; do { - if (fgets(p, LINESIZ - totlen, exp_file) == NULL) + if ((p = fgetln(exp_file, &len)) == NULL) return (0); - len = strlen(p); cp = p + len - 1; cont_line = 0; while (cp >= p && @@ -2022,15 +2023,15 @@ get_line() *++cp = ' '; len++; } - *++cp = '\0'; - if (len > 0) { - totlen += len; - if (totlen >= LINESIZ) { - syslog(LOG_ERR, "exports line too long"); - exit(2); - } - p = cp; + if (linesize < len + totlen + 1) { + linesize = len + totlen + 1; + line = realloc(line, linesize); + if (line == NULL) + out_of_mem(); } + memcpy(line + totlen, p, len); + totlen += len; + line[totlen] = '\0'; } while (totlen == 0 || cont_line); return (1); } -- cgit v1.1