diff options
author | charnier <charnier@FreeBSD.org> | 1997-06-25 06:59:55 +0000 |
---|---|---|
committer | charnier <charnier@FreeBSD.org> | 1997-06-25 06:59:55 +0000 |
commit | 8a89f6079cc66b8d7accdd3f30ff2c3eec80abb3 (patch) | |
tree | 6a8c81f2e7933d3c45a23f663b601ab2f622e84f | |
parent | eddc8f58268876ae8bd11c77a8d550e6bcd0d57b (diff) | |
download | FreeBSD-src-8a89f6079cc66b8d7accdd3f30ff2c3eec80abb3.zip FreeBSD-src-8a89f6079cc66b8d7accdd3f30ff2c3eec80abb3.tar.gz |
Free a malloc'ed variable before exiting. Compute line number when parsing
input file, it helps finding errors.
Obtained from: OpenBSD.
-rw-r--r-- | usr.bin/chpass/chpass.1 | 3 | ||||
-rw-r--r-- | usr.bin/chpass/edit.c | 14 |
2 files changed, 12 insertions, 5 deletions
diff --git a/usr.bin/chpass/chpass.1 b/usr.bin/chpass/chpass.1 index 0a0d0c7..e9059a6 100644 --- a/usr.bin/chpass/chpass.1 +++ b/usr.bin/chpass/chpass.1 @@ -30,6 +30,7 @@ .\" SUCH DAMAGE. .\" .\" @(#)chpass.1 8.2 (Berkeley) 12/30/93 +.\" $Id$ .\" .Dd December 30, 1993 .Dt CHPASS 1 @@ -38,7 +39,7 @@ .Nm chpass, chfn, chsh, ypchpass, ypchfn, ypchsh .Nd add or change user database information .Sh SYNOPSIS -chpass +.Nm chpass .Op Fl a Ar list .Op Fl p Ar encpass .Op Fl s Ar newshell diff --git a/usr.bin/chpass/edit.c b/usr.bin/chpass/edit.c index 40119f0..ad99822 100644 --- a/usr.bin/chpass/edit.c +++ b/usr.bin/chpass/edit.c @@ -29,6 +29,8 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. + * + * $Id$ */ #ifndef lint @@ -173,7 +175,7 @@ verify(pw) char *p; struct stat sb; FILE *fp; - int len; + int len, line; static char buf[LINE_MAX]; if (!(fp = fopen(tempname, "r"))) @@ -184,17 +186,19 @@ verify(pw) warnx("corrupted temporary file"); goto bad; } + line = 0; while (fgets(buf, sizeof(buf), fp)) { + line++; if (!buf[0] || buf[0] == '#') continue; if (!(p = strchr(buf, '\n'))) { - warnx("line too long"); + warnx("line %d too long", line); goto bad; } *p = '\0'; for (ep = list;; ++ep) { if (!ep->prompt) { - warnx("unrecognized field"); + warnx("unrecognized field on line %d", line); goto bad; } if (!strncasecmp(buf, ep->prompt, ep->len)) { @@ -205,7 +209,7 @@ verify(pw) goto bad; } if (!(p = strchr(buf, ':'))) { - warnx("line corrupted"); + warnx("line %d corrupted", line); goto bad; } while (isspace(*++p)); @@ -242,7 +246,9 @@ bad: (void)fclose(fp); pw->pw_change, pw->pw_expire, pw->pw_gecos, pw->pw_dir, pw->pw_shell) >= sizeof(buf)) { warnx("entries too long"); + free(p); return (0); } + free(p); return (pw_scan(buf, pw)); } |