summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>2005-11-12 15:26:23 +0000
committerderaadt <deraadt@openbsd.org>2005-11-12 15:26:23 +0000
commitf760b59d08a62144d339aa50ada412374167c51e (patch)
tree4bc6923265b176a6362bddadd7687530c62beca4
parentmore memleaks plugged; evol@online.ptt.ru (diff)
downloadwireguard-openbsd-f760b59d08a62144d339aa50ada412374167c51e.tar.xz
wireguard-openbsd-f760b59d08a62144d339aa50ada412374167c51e.zip
more asprintf; ok dhill@mindcry.org
-rw-r--r--sbin/ccdconfig/ccdconfig.c18
-rw-r--r--sbin/ncheck_ffs/ncheck_ffs.c11
-rw-r--r--usr.bin/cdio/cddb.c9
-rw-r--r--usr.sbin/edquota/edquota.c11
4 files changed, 19 insertions, 30 deletions
diff --git a/sbin/ccdconfig/ccdconfig.c b/sbin/ccdconfig/ccdconfig.c
index ec36417f988..01b64936dbb 100644
--- a/sbin/ccdconfig/ccdconfig.c
+++ b/sbin/ccdconfig/ccdconfig.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ccdconfig.c,v 1.23 2005/03/29 22:23:42 mickey Exp $ */
+/* $OpenBSD: ccdconfig.c,v 1.24 2005/11/12 15:26:23 deraadt Exp $ */
/* $NetBSD: ccdconfig.c,v 1.6 1996/05/16 07:11:18 thorpej Exp $ */
/*-
@@ -422,7 +422,7 @@ static char *
resolve_ccdname(char *name)
{
char c, *path;
- size_t len, newlen;
+ size_t len;
int rawpart;
if (name[0] == '/' || name[0] == '.') {
@@ -433,19 +433,17 @@ resolve_ccdname(char *name)
len = strlen(name);
c = name[len - 1];
- newlen = len + 8;
- if ((path = malloc(newlen)) == NULL)
- return (NULL);
- memset(path, 0, newlen);
-
if (isdigit(c)) {
if ((rawpart = getrawpartition()) < 0) {
free(path);
return (NULL);
}
- (void)snprintf(path, newlen, "/dev/%s%c", name, 'a' + rawpart);
- } else
- (void)snprintf(path, newlen, "/dev/%s", name);
+ if (asprintf(&path, "/dev/%s%c", name, 'a' + rawpart) == -1)
+ return (NULL);
+ } else {
+ if (asprintf(&path, "/dev/%s", name) == -1)
+ return (NULL);
+ }
return (path);
}
diff --git a/sbin/ncheck_ffs/ncheck_ffs.c b/sbin/ncheck_ffs/ncheck_ffs.c
index 28d8a1b0e39..93ecf017de0 100644
--- a/sbin/ncheck_ffs/ncheck_ffs.c
+++ b/sbin/ncheck_ffs/ncheck_ffs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ncheck_ffs.c,v 1.24 2005/04/12 06:39:29 deraadt Exp $ */
+/* $OpenBSD: ncheck_ffs.c,v 1.25 2005/11/12 15:26:23 deraadt Exp $ */
/*-
* Copyright (c) 1995, 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
@@ -26,7 +26,7 @@
*/
#ifndef lint
-static const char rcsid[] = "$OpenBSD: ncheck_ffs.c,v 1.24 2005/04/12 06:39:29 deraadt Exp $";
+static const char rcsid[] = "$OpenBSD: ncheck_ffs.c,v 1.25 2005/11/12 15:26:23 deraadt Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -385,18 +385,13 @@ searchdir(ino_t ino, daddr_t blkno, long size, long filesize,
}
}
if (mode == IFDIR) {
- int len;
-
if (dp->d_name[0] == '.') {
if (dp->d_name[1] == '\0' ||
(dp->d_name[1] == '.' && dp->d_name[2] == '\0'))
continue;
}
- len = strlen(path) + strlen(dp->d_name) + 2;
- npath = malloc(len);
- if (npath == NULL)
+ if (asprintf(&npath, "%s/%s", path, dp->d_name) == -1)
errx(1, "malloc");
- snprintf(npath, len, "%s/%s", path, dp->d_name);
scanonedir(dp->d_ino, npath);
free(npath);
}
diff --git a/usr.bin/cdio/cddb.c b/usr.bin/cdio/cddb.c
index 89a6ea9c0df..9ea17188f55 100644
--- a/usr.bin/cdio/cddb.c
+++ b/usr.bin/cdio/cddb.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cddb.c,v 1.8 2003/06/09 11:33:14 espie Exp $ */
+/* $OpenBSD: cddb.c,v 1.9 2005/11/12 15:26:23 deraadt Exp $ */
/*
* Copyright (c) 2002 Marc Espie.
*
@@ -106,11 +106,10 @@ safe_copy(char **p, const char *title)
if (*p == NULL)
*p = strdup(copy_buffer);
else {
- size_t len = strlen(*p) + strlen(copy_buffer) + 1;
- char *n = malloc(len);
- if (n == NULL)
+ char *n;
+
+ if (asprintf(&n, "%s%s", *p, copy_buffer) == -1)
return;
- snprintf(n, len, "%s%s", *p, copy_buffer);
free(*p);
*p = n;
}
diff --git a/usr.sbin/edquota/edquota.c b/usr.sbin/edquota/edquota.c
index 0b2ee5a61e5..255164380a4 100644
--- a/usr.sbin/edquota/edquota.c
+++ b/usr.sbin/edquota/edquota.c
@@ -38,7 +38,7 @@ static char copyright[] =
#ifndef lint
/*static char sccsid[] = "from: @(#)edquota.c 8.1 (Berkeley) 6/6/93";*/
-static char *rcsid = "$Id: edquota.c,v 1.42 2005/04/01 04:31:11 deraadt Exp $";
+static char *rcsid = "$Id: edquota.c,v 1.43 2005/11/12 15:26:23 deraadt Exp $";
#endif /* not lint */
/*
@@ -352,15 +352,12 @@ editit(char *tmpfile)
char *argp[] = {"sh", "-c", NULL, NULL};
char *ed, *p;
sigset_t mask, omask;
- int stat, len;
+ int stat;
if ((ed = getenv("EDITOR")) == (char *)0)
ed = _PATH_VI;
- len = strlen(ed) + 1 + strlen(tmpfile) + 1;
- p = (char *)malloc(len);
- if (!p)
- return(0);
- (void)snprintf(p, len, "%s %s", ed, tmpfile);
+ if (asprintf(&p, "%s %s", ed, tmpfile) == -1)
+ return (0);
argp[2] = p;
sigemptyset(&mask);