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.
This commit is contained in:
Ian Dowse 2002-05-14 23:24:28 +00:00
parent e7b663eff2
commit 91ca1a918f
2 changed files with 30 additions and 28 deletions

View File

@ -54,6 +54,8 @@ static const char rcsid[] =
#include <sys/stat.h>
#include <sys/syslog.h>
#include <sys/sysctl.h>
#include <sys/linker.h>
#include <sys/module.h>
#include <rpc/rpc.h>
#include <rpc/pmap_clnt.h>
@ -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);
}

View File

@ -54,6 +54,8 @@ static const char rcsid[] =
#include <sys/stat.h>
#include <sys/syslog.h>
#include <sys/sysctl.h>
#include <sys/linker.h>
#include <sys/module.h>
#include <rpc/rpc.h>
#include <rpc/pmap_clnt.h>
@ -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);
}