summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Thomas McBride <mcbride@cvs.openbsd.org>2002-12-11 13:23:39 +0000
committerRyan Thomas McBride <mcbride@cvs.openbsd.org>2002-12-11 13:23:39 +0000
commiteb5fd297b208d56e46e5620151cc47d6388a4f52 (patch)
tree266d7ead162d3a8ab159f8ea64954b4612974a5e
parentf957ca0319a0a42402f0b10e0aa7a6c182fdfd77 (diff)
Replace strncpy + ugly pointer math with sscanif for reading source-hash keys
ok dhartmei@ henning@
-rw-r--r--sbin/pfctl/parse.y22
1 files changed, 7 insertions, 15 deletions
diff --git a/sbin/pfctl/parse.y b/sbin/pfctl/parse.y
index 24e1c771c06..e3750b9f2c8 100644
--- a/sbin/pfctl/parse.y
+++ b/sbin/pfctl/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.248 2002/12/09 13:17:48 dhartmei Exp $ */
+/* $OpenBSD: parse.y,v 1.249 2002/12/11 13:23:38 mcbride Exp $ */
/*
* Copyright (c) 2001 Markus Friedl. All rights reserved.
@@ -1906,9 +1906,6 @@ hashkey : /* empty */
}
| string
{
- char buf[11] = "0x";
- int i;
-
if (!strncmp((char *)$1, "0x", 2)) {
if (strlen((char *)$1) != 34) {
yyerror("hex key must be 128 bits "
@@ -1919,17 +1916,12 @@ hashkey : /* empty */
if ($$ == NULL)
err(1, "hashkey: calloc");
- /* convert to binary */
- for (i = 0; i < 4; i++) {
- strncpy((char *)(buf + 2),
- (char *)($1 + 2 + (i * 8)), 8);
- if (atoul(buf,
- (u_long *)&$$->key32[i]) == -1) {
- /* not hex */
- free($$);
- yyerror("invalid hex key");
- YYERROR;
- }
+ if (sscanf($1, "0x%8x%8x%8x%8x",
+ &$$->key32[0], &$$->key32[1],
+ &$$->key32[2], &$$->key32[3]) != 4) {
+ free($$);
+ yyerror("invalid hex key");
+ YYERROR;
}
} else {
MD5_CTX context;