Module Name: src
Committed By: kamil
Date: Thu Dec 6 06:29:56 UTC 2018
Modified Files:
src/lib/libc/stdlib: strtonum.c
Log Message:
Correct handling of minval > maxval in strtonum(3)
The original implementation in OpenBSD returns "invalid" and avoids reading
the input string. The replaced behavior was interpreting the input string
ignoring the invalid arguments.
To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/lib/libc/stdlib/strtonum.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/lib/libc/stdlib/strtonum.c
diff -u src/lib/libc/stdlib/strtonum.c:1.5 src/lib/libc/stdlib/strtonum.c:1.6
--- src/lib/libc/stdlib/strtonum.c:1.5 Thu Jan 4 20:57:29 2018
+++ src/lib/libc/stdlib/strtonum.c Thu Dec 6 06:29:56 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: strtonum.c,v 1.5 2018/01/04 20:57:29 kamil Exp $ */
+/* $NetBSD: strtonum.c,v 1.6 2018/12/06 06:29:56 kamil Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
* All rights reserved.
@@ -29,7 +29,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: strtonum.c,v 1.5 2018/01/04 20:57:29 kamil Exp $");
+__RCSID("$NetBSD: strtonum.c,v 1.6 2018/12/06 06:29:56 kamil Exp $");
#include "namespace.h"
@@ -50,6 +50,11 @@ strtonum(const char *nptr, long long min
if (errstr == NULL)
errstr = &resp;
+ if (minval > maxval) {
+ *errstr = "invalid";
+ return 0;
+ }
+
rv = (long long)strtoi(nptr, NULL, 10, minval, maxval, &e);
if (e == 0) {