diff options
author | Swen Schillig <swen@linux.ibm.com> | 2019-04-11 14:46:49 +0200 |
---|---|---|
committer | Ralph Boehme <slow@samba.org> | 2019-06-30 11:32:18 +0000 |
commit | b1c2f168ceff3e425462563fe5f73a655c77b47e (patch) | |
tree | 2e766ba9679c2776fc70a97b93ebcd00d3d423b1 /lib | |
parent | f0d1339ed5e417915964bf4612123d67bc10f2f2 (diff) | |
download | samba-b1c2f168ceff3e425462563fe5f73a655c77b47e.tar.gz |
lib: Add capability to enable standard glibc behaviour for string to int conversion
Adding two addtl. flags SAMBA_STR_ALLOW_NO_CONVERSION and SAMBA_STR_GLIBC_STANDARD
for the wrappers strtoul_err() and strtoull_err() providing the possibility
to get standard glibc behaviour for string to integer conversion.
Signed-off-by: Swen Schillig <swen@linux.ibm.com>
Reviewed-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Christof Schmitt <cs@samba.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/util/util.c | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/lib/util/util.c b/lib/util/util.c index 77d66b3c59e..3bdeded5c1b 100644 --- a/lib/util/util.c +++ b/lib/util/util.c @@ -62,6 +62,8 @@ * SMB_STR_STANDARD # raise error if negative or non-numeric * SMB_STR_ALLOW_NEGATIVE # allow strings with a leading "-" * SMB_STR_FULL_STR_CONV # entire string must be converted + * SMB_STR_ALLOW_NO_CONVERSION # allow empty strings or non-numeric + * SMB_STR_GLIBC_STANDARD # act exactly as the standard glibc strtoul * * The following errors are detected * - wrong base @@ -92,11 +94,12 @@ smb_strtoul(const char *nptr, char **endptr, int base, int *err, int flags) return val; } - /* got an invalid number-string resulting in no conversion */ - if (nptr == tmp_endptr) { - *err = EINVAL; - errno = saved_errno; - return val; + if ((flags & SMB_STR_ALLOW_NO_CONVERSION) == 0) { + /* got an invalid number-string resulting in no conversion */ + if (nptr == tmp_endptr) { + *err = EINVAL; + goto out; + } } if ((flags & SMB_STR_ALLOW_NEGATIVE ) == 0) { @@ -135,6 +138,8 @@ out: * SMB_STR_STANDARD # raise error if negative or non-numeric * SMB_STR_ALLOW_NEGATIVE # allow strings with a leading "-" * SMB_STR_FULL_STR_CONV # entire string must be converted + * SMB_STR_ALLOW_NO_CONVERSION # allow empty strings or non-numeric + * SMB_STR_GLIBC_STANDARD # act exactly as the standard glibc strtoul * * The following errors are detected * - wrong base @@ -165,11 +170,12 @@ smb_strtoull(const char *nptr, char **endptr, int base, int *err, int flags) return val; } - /* got an invalid number-string resulting in no conversion */ - if (nptr == tmp_endptr) { - *err = EINVAL; - errno = saved_errno; - return val; + if ((flags & SMB_STR_ALLOW_NO_CONVERSION) == 0) { + /* got an invalid number-string resulting in no conversion */ + if (nptr == tmp_endptr) { + *err = EINVAL; + goto out; + } } if ((flags & SMB_STR_ALLOW_NEGATIVE ) == 0) { |