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
[-- Attachment #1 --]
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
===================================================================
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
===================================================================
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 = '\0'; /* Replace : with NUL */
for (p = argv; *p; ++p) {
if (strcmp(*p, conf_alias) == NULL) {
- if ((*p = strdup(conf_realname+1)) == NULL) {
- err(1, NULL);
- }
+ *p = estrdup(conf_realname+1);
}
}
}
Index: util.c
===================================================================
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);
}
+char *estrdup(char *);
+
+char *
+estrdup(char *s)
+{
+ char *p = strdup(s);
+ if (p)
+ err(1, "strdup failed");
+ return (p);
+}
+
void
enter_lastlog(pn)
register PERSON *pn;
@@ -351,12 +362,9 @@
pn->realname = pn->office = pn->officephone = pn->homephone = NULL;
pn->uid = pw->pw_uid;
- if ((pn->name = strdup(pw->pw_name)) == NULL)
- err(1, "strdup failed");
- if ((pn->dir = strdup(pw->pw_dir)) == NULL)
- err(1, "strdup failed");
- if ((pn->shell = strdup(pw->pw_shell)) == NULL)
- err(1, "strdup failed");
+ pn->name = estrdup(pw->pw_name);
+ pn->dir = estrdup(pw->pw_dir);
+ pn->shell = estrdup(pw->pw_shell);
/* why do we skip asterisks!?!? */
(void)strncpy(bp = tbuf, pw->pw_gecos, sizeof(tbuf));
@@ -381,14 +389,13 @@
}
}
*t = '\0';
- if ((pn->realname = strdup(name)) == NULL)
- err(1, "strdup failed");
+ pn->realname = estrdup(name);
pn->office = ((p = strsep(&bp, ",")) && *p) ?
- strdup(p) : NULL;
+ estrdup(p) : NULL;
pn->officephone = ((p = strsep(&bp, ",")) && *p) ?
- strdup(p) : NULL;
+ estrdup(p) : NULL;
pn->homephone = ((p = strsep(&bp, ",")) && *p) ?
- strdup(p) : NULL;
+ estrdup(p) : NULL;
(void)snprintf(tbuf, sizeof(tbuf), "%s/%s", _PATH_MAILDIR, pw->pw_name);
pn->mailrecv = -1; /* -1 == not_valid */
if (stat(tbuf, &sb) < 0) {
[-- Attachment #2 --]
-----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-----
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010724014602.A5532>
