1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-26 21:57:41 +03:00

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>
This commit is contained in:
Swen Schillig 2019-04-11 14:46:49 +02:00 committed by Ralph Boehme
parent f0d1339ed5
commit b1c2f168ce

View File

@ -62,6 +62,8 @@
* SMB_STR_STANDARD # raise error if negative or non-numeric * SMB_STR_STANDARD # raise error if negative or non-numeric
* SMB_STR_ALLOW_NEGATIVE # allow strings with a leading "-" * SMB_STR_ALLOW_NEGATIVE # allow strings with a leading "-"
* SMB_STR_FULL_STR_CONV # entire string must be converted * 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 * The following errors are detected
* - wrong base * - wrong base
@ -92,11 +94,12 @@ smb_strtoul(const char *nptr, char **endptr, int base, int *err, int flags)
return val; return val;
} }
/* got an invalid number-string resulting in no conversion */ if ((flags & SMB_STR_ALLOW_NO_CONVERSION) == 0) {
if (nptr == tmp_endptr) { /* got an invalid number-string resulting in no conversion */
*err = EINVAL; if (nptr == tmp_endptr) {
errno = saved_errno; *err = EINVAL;
return val; goto out;
}
} }
if ((flags & SMB_STR_ALLOW_NEGATIVE ) == 0) { if ((flags & SMB_STR_ALLOW_NEGATIVE ) == 0) {
@ -135,6 +138,8 @@ out:
* SMB_STR_STANDARD # raise error if negative or non-numeric * SMB_STR_STANDARD # raise error if negative or non-numeric
* SMB_STR_ALLOW_NEGATIVE # allow strings with a leading "-" * SMB_STR_ALLOW_NEGATIVE # allow strings with a leading "-"
* SMB_STR_FULL_STR_CONV # entire string must be converted * 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 * The following errors are detected
* - wrong base * - wrong base
@ -165,11 +170,12 @@ smb_strtoull(const char *nptr, char **endptr, int base, int *err, int flags)
return val; return val;
} }
/* got an invalid number-string resulting in no conversion */ if ((flags & SMB_STR_ALLOW_NO_CONVERSION) == 0) {
if (nptr == tmp_endptr) { /* got an invalid number-string resulting in no conversion */
*err = EINVAL; if (nptr == tmp_endptr) {
errno = saved_errno; *err = EINVAL;
return val; goto out;
}
} }
if ((flags & SMB_STR_ALLOW_NEGATIVE ) == 0) { if ((flags & SMB_STR_ALLOW_NEGATIVE ) == 0) {