summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>2014-11-19 22:07:13 +0000
committermillert <millert@openbsd.org>2014-11-19 22:07:13 +0000
commit90934534fd82c5a5b6e22c6bace6419a3a202cc3 (patch)
tree7e029025ec756557c5b1466864cc4ca979eef054
parentLet .Ao and .Aq render as "<>" after .An and as "\(la\(ra" elsewhere, (diff)
downloadwireguard-openbsd-90934534fd82c5a5b6e22c6bace6419a3a202cc3.tar.xz
wireguard-openbsd-90934534fd82c5a5b6e22c6bace6419a3a202cc3.zip
Use stravis() instead of a custom() strvis + mallocarray wrapper.
OK tedu@ tobias@
-rw-r--r--usr.bin/finger/extern.h3
-rw-r--r--usr.bin/finger/util.c63
2 files changed, 28 insertions, 38 deletions
diff --git a/usr.bin/finger/extern.h b/usr.bin/finger/extern.h
index 70ca8dd4f0e..ed8e21abfba 100644
--- a/usr.bin/finger/extern.h
+++ b/usr.bin/finger/extern.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: extern.h,v 1.8 2014/10/17 20:19:15 millert Exp $ */
+/* $OpenBSD: extern.h,v 1.9 2014/11/19 22:07:13 millert Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -57,6 +57,5 @@ void sflag_print(void);
int show_text(char *, char *, char *);
PERSON **sort(void);
void stimeprint(WHERE *);
-char *vs(const char *);
void userlist(int, char **);
void vputc(int);
diff --git a/usr.bin/finger/util.c b/usr.bin/finger/util.c
index e8b858730d2..3b4b3654c52 100644
--- a/usr.bin/finger/util.c
+++ b/usr.bin/finger/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.28 2014/11/18 20:54:28 krw Exp $ */
+/* $OpenBSD: util.c,v 1.29 2014/11/19 22:07:13 millert Exp $ */
/*
* Copyright (c) 1989 The Regents of the University of California.
@@ -89,8 +89,10 @@ userinfo(PERSON *pn, struct passwd *pw)
char *p;
char *bp, name[1024];
struct stat sb;
+ int len;
pn->realname = pn->office = pn->officephone = pn->homephone = NULL;
+ pn->mailrecv = -1; /* -1 == not_valid */
pn->uid = pw->pw_uid;
pn->name = estrdup(pw->pw_name);
@@ -103,24 +105,32 @@ userinfo(PERSON *pn, struct passwd *pw)
if (!(p = strsep(&bp, ",")))
return;
expandusername(p, pw->pw_name, name, sizeof(name));
- pn->realname = vs(name);
- pn->office = ((p = strsep(&bp, ",")) && *p) ?
- vs(p) : NULL;
- pn->officephone = ((p = strsep(&bp, ",")) && *p) ?
- vs(p) : NULL;
- pn->homephone = ((p = strsep(&bp, ",")) && *p) ?
- vs(p) : NULL;
- (void)snprintf(tbuf, sizeof(tbuf), "%s/%s", _PATH_MAILSPOOL,
+ if (stravis(&pn->realname, p, VIS_SAFE|VIS_NOSLASH) == -1)
+ err(1, "stravis");
+ if ((p = strsep(&bp, ",")) && *p) {
+ if (stravis(&pn->office, p, VIS_SAFE|VIS_NOSLASH) == -1)
+ err(1, "stravis");
+ }
+ if ((p = strsep(&bp, ",")) && *p) {
+ if (stravis(&pn->officephone, p, VIS_SAFE|VIS_NOSLASH) == -1)
+ err(1, "stravis");
+ }
+ if ((p = strsep(&bp, ",")) && *p) {
+ if (stravis(&pn->homephone, p, VIS_SAFE|VIS_NOSLASH) == -1)
+ err(1, "stravis");
+ }
+ len = snprintf(tbuf, sizeof(tbuf), "%s/%s", _PATH_MAILSPOOL,
pw->pw_name);
- pn->mailrecv = -1; /* -1 == not_valid */
- if (stat(tbuf, &sb) < 0) {
- if (errno != ENOENT) {
- warn("%s", tbuf);
- return;
+ if (len != -1 && len < sizeof(tbuf)) {
+ if (stat(tbuf, &sb) < 0) {
+ if (errno != ENOENT) {
+ warn("%s", tbuf);
+ return;
+ }
+ } else if (sb.st_size != 0) {
+ pn->mailrecv = sb.st_mtime;
+ pn->mailread = sb.st_atime;
}
- } else if (sb.st_size != 0) {
- pn->mailrecv = sb.st_mtime;
- pn->mailread = sb.st_atime;
}
}
@@ -363,22 +373,3 @@ prphone(char *num)
*p = '\0';
return (pbuf);
}
-
-/*
- * Like strvis(), but use malloc() to get the space and returns a pointer
- * to the destination string.
- *
- * The caller is responsible for free()'ing the returned string.
- */
-char *
-vs(const char *src)
-{
- char *dst;
-
- /* This will allocate 3 extra bytes but gives overflow protection. */
- dst = reallocarray(NULL, 4, strlen(src) + 1);
- if (dst == NULL)
- err(1, "reallocarray");
- strvis(dst, src, VIS_SAFE|VIS_NOSLASH);
- return (dst);
-}