summaryrefslogtreecommitdiffstats
path: root/usr.sbin/mtree
diff options
context:
space:
mode:
authorhenning <henning@openbsd.org>2003-04-19 10:43:55 +0000
committerhenning <henning@openbsd.org>2003-04-19 10:43:55 +0000
commite296a845a16705f4a49628153a53394c5b00a865 (patch)
treea9710aeeebe3d1d7344899bf5a7a4ebc819283de /usr.sbin/mtree
parentFix format odditiy in 'ERRORS' section, formats like mmap(2) manpage now. (diff)
downloadwireguard-openbsd-e296a845a16705f4a49628153a53394c5b00a865.tar.xz
wireguard-openbsd-e296a845a16705f4a49628153a53394c5b00a865.zip
string stuff, ok krw@
Diffstat (limited to 'usr.sbin/mtree')
-rw-r--r--usr.sbin/mtree/spec.c16
-rw-r--r--usr.sbin/mtree/verify.c15
2 files changed, 18 insertions, 13 deletions
diff --git a/usr.sbin/mtree/spec.c b/usr.sbin/mtree/spec.c
index 6499e9046de..057c8fbb0a1 100644
--- a/usr.sbin/mtree/spec.c
+++ b/usr.sbin/mtree/spec.c
@@ -1,5 +1,5 @@
/* $NetBSD: spec.c,v 1.6 1995/03/07 21:12:12 cgd Exp $ */
-/* $OpenBSD: spec.c,v 1.16 2002/03/14 17:01:16 millert Exp $ */
+/* $OpenBSD: spec.c,v 1.17 2003/04/19 10:43:55 henning Exp $ */
/*-
* Copyright (c) 1989, 1993
@@ -38,7 +38,7 @@
#if 0
static const char sccsid[] = "@(#)spec.c 8.1 (Berkeley) 6/6/93";
#else
-static const char rcsid[] = "$OpenBSD: spec.c,v 1.16 2002/03/14 17:01:16 millert Exp $";
+static const char rcsid[] = "$OpenBSD: spec.c,v 1.17 2003/04/19 10:43:55 henning Exp $";
#endif
#endif /* not lint */
@@ -68,6 +68,7 @@ spec()
NODE ginfo, *root;
int c_cur, c_next;
char buf[2048];
+ size_t len;
centry = last = root = NULL;
bzero(&ginfo, sizeof(ginfo));
@@ -142,7 +143,8 @@ spec()
noparent: error("no parent node");
}
- if ((centry = calloc(1, sizeof(NODE) + strlen(p))) == NULL)
+ len = strlen(p) + 1; /* NUL in struct _node */
+ if ((centry = calloc(1, sizeof(NODE) + len - 1)) == NULL)
error("%s", strerror(errno));
*centry = ginfo;
#define MAGIC "?*["
@@ -151,7 +153,7 @@ noparent: error("no parent node");
if (strunvis(centry->name, p) == -1) {
fprintf(stderr,
"mtree: filename (%s) encoded incorrectly\n", p);
- strcpy(centry->name, p);
+ strlcpy(centry->name, p, len);
}
set(NULL, centry);
@@ -183,6 +185,7 @@ set(t, ip)
int value;
u_int32_t fset, fclr;
char *ep;
+ size_t len;
for (; (kw = strtok(t, "= \t\n")); t = NULL) {
ip->flags |= type = parsekey(kw, &value);
@@ -248,12 +251,13 @@ set(t, ip)
error("invalid size %s", val);
break;
case F_SLINK:
- if ((ip->slink = malloc(strlen(val) + 1)) == NULL)
+ len = strlen(val) + 1;
+ if ((ip->slink = malloc(len)) == NULL)
error("%s", strerror(errno));
if (strunvis(ip->slink, val) == -1) {
fprintf(stderr,
"mtree: filename (%s) encoded incorrectly\n", val);
- strcpy(ip->slink, val);
+ strlcpy(ip->slink, val, len);
}
break;
case F_TIME:
diff --git a/usr.sbin/mtree/verify.c b/usr.sbin/mtree/verify.c
index 63ddf7e855b..cd60ea8d9ba 100644
--- a/usr.sbin/mtree/verify.c
+++ b/usr.sbin/mtree/verify.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: verify.c,v 1.11 2002/03/14 16:44:25 mpech Exp $ */
+/* $OpenBSD: verify.c,v 1.12 2003/04/19 10:43:55 henning Exp $ */
/* $NetBSD: verify.c,v 1.10 1995/03/07 21:26:28 cgd Exp $ */
/*-
@@ -38,7 +38,7 @@
#if 0
static const char sccsid[] = "@(#)verify.c 8.1 (Berkeley) 6/6/93";
#else
-static const char rcsid[] = "$OpenBSD: verify.c,v 1.11 2002/03/14 16:44:25 mpech Exp $";
+static const char rcsid[] = "$OpenBSD: verify.c,v 1.12 2003/04/19 10:43:55 henning Exp $";
#endif
#endif /* not lint */
@@ -61,7 +61,7 @@ extern char fullpath[MAXPATHLEN];
static NODE *root;
static char path[MAXPATHLEN];
-static void miss(NODE *, char *);
+static void miss(NODE *, char *, size_t);
static int vwalk(void);
int
@@ -71,7 +71,7 @@ verify()
root = spec();
rval = vwalk();
- miss(root, path);
+ miss(root, path, sizeof(path));
return (rval);
}
@@ -157,9 +157,10 @@ extra:
}
static void
-miss(p, tail)
+miss(p, tail, len)
NODE *p;
char *tail;
+ size_t len;
{
int create;
char *tp;
@@ -169,7 +170,7 @@ miss(p, tail)
continue;
if (p->type != F_DIR && (dflag || p->flags & F_VISIT))
continue;
- (void)strcpy(tail, p->name);
+ (void)strlcpy(tail, p->name, len);
if (!(p->flags & F_VISIT)) {
/* Don't print missing message if file exists as a
symbolic link and the -q flag is set. */
@@ -207,7 +208,7 @@ miss(p, tail)
for (tp = tail; *tp; ++tp);
*tp = '/';
- miss(p->child, tp + 1);
+ miss(p->child, tp + 1, len - (tp + 1 - tail));
*tp = '\0';
if (!create)