Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libc/stdlib Correct handling of minval > maxval in strto...
details: https://anonhg.NetBSD.org/src/rev/274779e50e43
branches: trunk
changeset: 837468:274779e50e43
user: kamil <kamil%NetBSD.org@localhost>
date: Thu Dec 06 06:29:56 2018 +0000
description:
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.
diffstat:
lib/libc/stdlib/strtonum.c | 9 +++++++--
1 files changed, 7 insertions(+), 2 deletions(-)
diffs (30 lines):
diff -r d43b8ae079b2 -r 274779e50e43 lib/libc/stdlib/strtonum.c
--- a/lib/libc/stdlib/strtonum.c Thu Dec 06 01:42:20 2018 +0000
+++ b/lib/libc/stdlib/strtonum.c Thu Dec 06 06:29:56 2018 +0000
@@ -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 @@
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) {
Home |
Main Index |
Thread Index |
Old Index