summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2006-10-25 12:23:11 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2006-10-25 12:23:11 +0000
commitc1742c33f295ae5c018f3cddb1fb745c382d2bb5 (patch)
tree624814690a923af3aac61714e8c6f3daa32b2792 /usr.sbin
parentac5d17d09f6550a6db591a0a0452fd2794c0f49e (diff)
Use strtonum(3) instead of the hand made atoul. This solves an issue with
possible integer truncation because of the use of u_longs and u_int32_t in the code. Initial diff by Pierre-Yves Ritschard but slightly modified version commited.
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/ospfd/parse.y29
1 files changed, 7 insertions, 22 deletions
diff --git a/usr.sbin/ospfd/parse.y b/usr.sbin/ospfd/parse.y
index 0ef106aa452..95ba580c235 100644
--- a/usr.sbin/ospfd/parse.y
+++ b/usr.sbin/ospfd/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.34 2006/05/31 03:59:51 claudio Exp $ */
+/* $OpenBSD: parse.y,v 1.35 2006/10/25 12:23:10 claudio Exp $ */
/*
* Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org>
@@ -93,7 +93,6 @@ struct sym {
int symset(const char *, const char *, int);
char *symget(const char *);
-int atoul(char *, u_long *);
struct area *conf_get_area(struct in_addr);
struct iface *conf_get_if(struct kif *);
@@ -130,14 +129,16 @@ grammar : /* empty */
;
number : STRING {
- u_long ulval;
+ u_int32_t uval;
+ const char *errstr;
- if (atoul($1, &ulval) == -1) {
- yyerror("%s is not a number", $1);
+ uval = strtonum($1, 0, UINT_MAX, &errstr);
+ if (errstr) {
+ yyerror("number %s is %s", $1, errstr);
free($1);
YYERROR;
} else
- $$ = ulval;
+ $$ = uval;
free($1);
}
;
@@ -868,22 +869,6 @@ symget(const char *nam)
return (NULL);
}
-int
-atoul(char *s, u_long *ulvalp)
-{
- u_long ulval;
- char *ep;
-
- errno = 0;
- ulval = strtoul(s, &ep, 0);
- if (s[0] == '\0' || *ep != '\0')
- return (-1);
- if (errno == ERANGE && ulval == ULONG_MAX)
- return (-1);
- *ulvalp = ulval;
- return (0);
-}
-
struct area *
conf_get_area(struct in_addr id)
{