diff options
author | Dima Dorfman <dd@FreeBSD.org> | 2005-06-15 10:13:04 +0000 |
---|---|---|
committer | Dima Dorfman <dd@FreeBSD.org> | 2005-06-15 10:13:04 +0000 |
commit | ff900deda6909db0e25e9418506848d3bde02fbe (patch) | |
tree | 853f0d282f9e7f08f32f4b2b98319676deefb039 /usr.sbin/pwd_mkdb | |
parent | b61403ff72cd78ad6c7529487bf2d87daededa00 (diff) | |
download | src-ff900deda6909db0e25e9418506848d3bde02fbe.tar.gz src-ff900deda6909db0e25e9418506848d3bde02fbe.zip |
Correctly handle an input file without a newline on the last line (and
avoid the confusing error message about the line being too long). This
change uses fgetln to detect the right conditions, but the fixed-width
line buffer is kept because too many other places in the program make
assumptions about its maximum width.
Approved by: re (scottl)
Notes
Notes:
svn path=/head/; revision=147395
Diffstat (limited to 'usr.sbin/pwd_mkdb')
-rw-r--r-- | usr.sbin/pwd_mkdb/pwd_mkdb.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/usr.sbin/pwd_mkdb/pwd_mkdb.c b/usr.sbin/pwd_mkdb/pwd_mkdb.c index d164d340c86c..3c8ca252a0c8 100644 --- a/usr.sbin/pwd_mkdb/pwd_mkdb.c +++ b/usr.sbin/pwd_mkdb/pwd_mkdb.c @@ -631,12 +631,14 @@ main(int argc, char *argv[]) } int -scan(FILE * fp, struct passwd *pw) +scan(FILE *fp, struct passwd *pw) { static int lcnt; + size_t len; char *p; - if (!fgets(line, sizeof(line), fp)) + p = fgetln(fp, &len); + if (p == NULL) return (0); ++lcnt; /* @@ -644,16 +646,14 @@ scan(FILE * fp, struct passwd *pw) * throat...'' * -- The Who */ - if (!(p = strchr(line, '\n'))) { - /* - * XXX: This may also happen if the last line in a - * file does not have a trailing newline. - */ + if (len > 0 && p[len - 1] == '\n') + len--; + if (len >= sizeof(line) - 1) { warnx("line #%d too long", lcnt); goto fmt; - } - *p = '\0'; + memcpy(line, p, len); + line[len] = '\0'; /* * Ignore comments: ^[ \t]*# |