summaryrefslogtreecommitdiff
path: root/lib/param
diff options
context:
space:
mode:
authorSwen Schillig <swen@linux.ibm.com>2019-01-30 08:33:02 +0100
committerJeremy Allison <jra@samba.org>2019-03-01 00:32:11 +0000
commite7b7c634e8bb5e9df5c523377458d880a6368ddc (patch)
tree3b1fb4e8a1118a5f62c86f9e10eb573ae086f58a /lib/param
parentebeae5dcbad898e8ee0d64c4ed44751b753f27de (diff)
downloadsamba-e7b7c634e8bb5e9df5c523377458d880a6368ddc.tar.gz
common-lib: Use wrapper for string to integer conversion
In order to detect an value overflow error during the string to integer conversion with strtoul/strtoull, the errno variable must be set to zero before the execution and checked after the conversion is performed. This is achieved by using the wrapper function strtoul_err and strtoull_err. Signed-off-by: Swen Schillig <swen@linux.ibm.com> Reviewed-by: Ralph Böhme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'lib/param')
-rw-r--r--lib/param/loadparm.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/lib/param/loadparm.c b/lib/param/loadparm.c
index 84c83ae91ec..9c7bf892835 100644
--- a/lib/param/loadparm.c
+++ b/lib/param/loadparm.c
@@ -331,13 +331,21 @@ int lp_int(const char *s)
*/
unsigned long lp_ulong(const char *s)
{
+ int error = 0;
+ unsigned long int ret;
if (!s || !*s) {
- DEBUG(0,("lp_ulong(%s): is called with NULL!\n",s));
+ DBG_DEBUG("lp_ulong(%s): is called with NULL!\n",s);
return -1;
}
- return strtoul(s, NULL, 0);
+ ret = strtoul_err(s, NULL, 0, &error);
+ if (error != 0) {
+ DBG_DEBUG("lp_ulong(%s): conversion failed\n",s);
+ return -1;
+ }
+
+ return ret;
}
/**
@@ -345,13 +353,21 @@ unsigned long lp_ulong(const char *s)
*/
unsigned long long lp_ulonglong(const char *s)
{
+ int error = 0;
+ unsigned long long int ret;
if (!s || !*s) {
- DEBUG(0, ("lp_ulonglong(%s): is called with NULL!\n", s));
+ DBG_DEBUG("lp_ulonglong(%s): is called with NULL!\n", s);
return -1;
}
- return strtoull(s, NULL, 0);
+ ret = strtoull_err(s, NULL, 0, &error);
+ if (error != 0) {
+ DBG_DEBUG("lp_ulonglong(%s): conversion failed\n",s);
+ return -1;
+ }
+
+ return ret;
}
/**