summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorHenning Brauer <henning@cvs.openbsd.org>2002-12-09 18:26:10 +0000
committerHenning Brauer <henning@cvs.openbsd.org>2002-12-09 18:26:10 +0000
commitf5dac07cebbafc9835f922597238dfce49e1b06d (patch)
treeda5e5b4a9e8204c778506afc12e5bb6eefa287ab /sbin
parent37a32d6b138eafa0cd9f830575a4e473c77975a4 (diff)
replace (properly guarded) strncpy using logic by a strsep & strlcpy using
one. discussion & ok dhartmei@
Diffstat (limited to 'sbin')
-rw-r--r--sbin/pfctl/pfctl.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/sbin/pfctl/pfctl.c b/sbin/pfctl/pfctl.c
index cdf9c7102e3..74383a074bb 100644
--- a/sbin/pfctl/pfctl.c
+++ b/sbin/pfctl/pfctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfctl.c,v 1.100 2002/12/07 20:45:04 mcbride Exp $ */
+/* $OpenBSD: pfctl.c,v 1.101 2002/12/09 18:26:09 henning Exp $ */
/*
* Copyright (c) 2001 Daniel Hartmeier
@@ -1215,20 +1215,28 @@ main(int argc, char *argv[])
char *t = strchr(anchoropt, ':');
if (t == NULL) {
- if (strlen(anchoropt) >= sizeof(anchorname))
- err(1, "anchor name '%s' too long",
+ if (strlcpy(anchorname, anchoropt,
+ sizeof(anchorname)) >= sizeof(anchorname))
+ errx(1, "anchor name '%s' too long",
anchoropt);
- strcpy(anchorname, anchoropt);
} else {
+ char *p;
+
if (t == anchoropt || !strlen(t+1))
- err(1, "anchor names '%s' invalid",
- anchoropt);
- if (t-anchoropt >= sizeof(anchorname) ||
- strlen(t+1) >= sizeof(rulesetname))
- err(1, "anchor names '%s' too long",
+ errx(1, "anchor names '%s' invalid", anchoropt);
+ if ((p = malloc(strlen(anchoropt) + 1)) == NULL)
+ err(1, "malloc");
+ strlcpy(p, anchoropt, strlen(anchoropt) + 1);
+ if ((t = strsep(&p, ":")) == NULL)
+ errx(1, "anchor names '%s' invalid",
anchoropt);
- strncpy(anchorname, anchoropt, t-anchoropt);
- strcpy(rulesetname, t+1);
+ if (strlcpy(anchorname, t, sizeof(anchorname)) >=
+ sizeof(anchorname))
+ errx(1, "anchor name '%s' too long", t);
+ if (strlcpy(rulesetname, p, sizeof(rulesetname)) >=
+ sizeof(rulesetname))
+ errx(1, "ruleset name '%s' too long", p);
+ free(t);
}
}