Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 24 Jul 2001 01:46:02 -0700
From:      Kris Kennaway <kris@obsecurity.org>
To:        audit@FreeBSD.org
Subject:   finger strdup patch
Message-ID:  <20010724014602.A5532@xor.obsecurity.org>

next in thread | raw e-mail | index | archive | help

--45Z9DzgjV8m4Oswq
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

This is a slight consolidation from OpenBSD: it checks the return
values of a few more strdup()s and saves a few bytes on the binary
size, as a bonus :-)

Kris

Index: extern.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /mnt/ncvs/src/usr.bin/finger/extern.h,v
retrieving revision 1.4
diff -u -r1.4 extern.h
--- extern.h	2001/03/21 18:43:49	1.4
+++ extern.h	2001/07/24 08:40:58
@@ -42,6 +42,7 @@
 void	 enter_lastlog __P((PERSON *));
 PERSON	*enter_person __P((struct passwd *));
 void	 enter_where __P((struct utmp *, PERSON *));
+char	*estrdup __P((char *));
 PERSON	*find_person __P((char *));
 int		hide __P((struct passwd *));
 void	 lflag_print __P((void));
Index: finger.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /mnt/ncvs/src/usr.bin/finger/finger.c,v
retrieving revision 1.24
diff -u -r1.24 finger.c
--- finger.c	2001/03/21 18:43:49	1.24
+++ finger.c	2001/07/24 08:41:23
@@ -311,9 +311,7 @@
 		*conf_realname =3D '\0';               /* Replace : with NUL */
 		for (p =3D argv; *p; ++p) {
 		    if (strcmp(*p, conf_alias) =3D=3D NULL) {
-			if ((*p =3D strdup(conf_realname+1)) =3D=3D NULL) {
-			    err(1, NULL);
-			}
+			*p =3D estrdup(conf_realname+1);
 		    }
 		}
 	    }
Index: util.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /mnt/ncvs/src/usr.bin/finger/util.c,v
retrieving revision 1.13
diff -u -r1.13 util.c
--- util.c	2001/03/01 05:52:38	1.13
+++ util.c	2001/07/24 08:38:04
@@ -104,6 +104,17 @@
 	return(0);
 }
=20
+char *estrdup(char *);
+
+char *
+estrdup(char *s)
+{
+	char *p =3D strdup(s);
+	if (p)
+		err(1, "strdup failed");
+	return (p);
+}
+
 void
 enter_lastlog(pn)
 	register PERSON *pn;
@@ -351,12 +362,9 @@
 	pn->realname =3D pn->office =3D pn->officephone =3D pn->homephone =3D NUL=
L;
=20
 	pn->uid =3D pw->pw_uid;
-	if ((pn->name =3D strdup(pw->pw_name)) =3D=3D NULL)
-		err(1, "strdup failed");
-	if ((pn->dir =3D strdup(pw->pw_dir)) =3D=3D NULL)
-		err(1, "strdup failed");
-	if ((pn->shell =3D strdup(pw->pw_shell)) =3D=3D NULL)
-		err(1, "strdup failed");
+	pn->name =3D estrdup(pw->pw_name);
+	pn->dir =3D estrdup(pw->pw_dir);
+	pn->shell =3D estrdup(pw->pw_shell);
=20
 	/* why do we skip asterisks!?!? */
 	(void)strncpy(bp =3D tbuf, pw->pw_gecos, sizeof(tbuf));
@@ -381,14 +389,13 @@
 		}
 	}
 	*t =3D '\0';
-	if ((pn->realname =3D strdup(name)) =3D=3D NULL)
-		err(1, "strdup failed");
+	pn->realname =3D estrdup(name);
 	pn->office =3D ((p =3D strsep(&bp, ",")) && *p) ?
-	    strdup(p) : NULL;
+	    estrdup(p) : NULL;
 	pn->officephone =3D ((p =3D strsep(&bp, ",")) && *p) ?
-	    strdup(p) : NULL;
+	    estrdup(p) : NULL;
 	pn->homephone =3D ((p =3D strsep(&bp, ",")) && *p) ?
-	    strdup(p) : NULL;
+	    estrdup(p) : NULL;
 	(void)snprintf(tbuf, sizeof(tbuf), "%s/%s", _PATH_MAILDIR, pw->pw_name);
 	pn->mailrecv =3D -1;		/* -1 =3D=3D not_valid */
 	if (stat(tbuf, &sb) < 0) {


--45Z9DzgjV8m4Oswq
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (FreeBSD)
Comment: For info see http://www.gnupg.org

iD8DBQE7XTXKWry0BWjoQKURArixAKCfo/621aPdsTVl43slb/JxUupMlACbBUyp
BaxS4h2evfWUKewd5Ax7jMg=
=vLxB
-----END PGP SIGNATURE-----

--45Z9DzgjV8m4Oswq--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-audit" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010724014602.A5532>