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

lib: Add check for full string consumption when converting string to int

Some callers want to have the entire string being used for a
string to integer conversion, otherwise flag an error.
This is possible by providing the SAMBA_STR_FULL_STR_CONV flag.

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:42:37 +02:00 committed by Ralph Boehme
parent f2997ad677
commit f0d1339ed5

View File

@ -61,6 +61,7 @@
* The following flags are supported
* 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
*
* The following errors are detected
* - wrong base
@ -103,9 +104,19 @@ smb_strtoul(const char *nptr, char **endptr, int base, int *err, int flags)
needle = strchr(nptr, '-');
if (needle != NULL && needle < tmp_endptr) {
*err = EINVAL;
goto out;
}
}
if ((flags & SMB_STR_FULL_STR_CONV) != 0) {
/* did we convert the entire string ? */
if (tmp_endptr[0] != '\0') {
*err = EINVAL;
goto out;
}
}
out:
errno = saved_errno;
return val;
}
@ -123,6 +134,7 @@ smb_strtoul(const char *nptr, char **endptr, int base, int *err, int flags)
* The following flags are supported
* 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
*
* The following errors are detected
* - wrong base
@ -165,9 +177,19 @@ smb_strtoull(const char *nptr, char **endptr, int base, int *err, int flags)
needle = strchr(nptr, '-');
if (needle != NULL && needle < tmp_endptr) {
*err = EINVAL;
goto out;
}
}
if ((flags & SMB_STR_FULL_STR_CONV) != 0) {
/* did we convert the entire string ? */
if (tmp_endptr[0] != '\0') {
*err = EINVAL;
goto out;
}
}
out:
errno = saved_errno;
return val;
}