summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilippe Charnier <charnier@FreeBSD.org>1997-06-25 06:59:55 +0000
committerPhilippe Charnier <charnier@FreeBSD.org>1997-06-25 06:59:55 +0000
commit5f4429291b5d146d997227d085fb7016e3d45574 (patch)
treea917c14db019a5a612bf084124a7c10b083b6938
parent60991f53045b69c5cc93101d6f3c279838cc620a (diff)
downloadpw-darwin-5f4429291b5d146d997227d085fb7016e3d45574.tar.gz
pw-darwin-5f4429291b5d146d997227d085fb7016e3d45574.tar.zst
pw-darwin-5f4429291b5d146d997227d085fb7016e3d45574.zip
Free a malloc'ed variable before exiting. Compute line number when parsing
input file, it helps finding errors. Obtained from: OpenBSD.
-rw-r--r--chpass/chpass.13
-rw-r--r--chpass/edit.c14
2 files changed, 12 insertions, 5 deletions
diff --git a/chpass/chpass.1 b/chpass/chpass.1
index 0a0d0c7..e9059a6 100644
--- a/chpass/chpass.1
+++ b/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/chpass/edit.c b/chpass/edit.c
index 40119f0..ad99822 100644
--- a/chpass/edit.c
+++ b/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));
}