diff options
author | Swen Schillig <swen@linux.ibm.com> | 2019-06-03 10:37:07 +0200 |
---|---|---|
committer | Ralph Boehme <slow@samba.org> | 2019-06-30 11:32:19 +0000 |
commit | dac981a3887fe79650b38e63799e344b22c8f5f1 (patch) | |
tree | cd742e38f376a280462aa9b33aefc1bf803fac01 /lib/util | |
parent | ed533debc40f3173326c65a90ae344d01ec1d427 (diff) | |
download | samba-dac981a3887fe79650b38e63799e344b22c8f5f1.tar.gz |
tests-util: Adding test to verify "full-string-conversion" flag
The standard string to integer conversion routines stop at the first
character which cannot be converted to a number.
However, if such a character is found, it is not considered an error.
With the flag "SMB_STR_FULL_STR_CONV" enabled, an error will be returned
if the string could not be converted entirely.
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/util')
-rw-r--r-- | lib/util/tests/util.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/util/tests/util.c b/lib/util/tests/util.c index f12021fe2a2..4741f466b35 100644 --- a/lib/util/tests/util.c +++ b/lib/util/tests/util.c @@ -541,6 +541,31 @@ static bool test_smb_strtoul_allow_negative(struct torture_context *tctx) return true; } +static bool test_smb_strtoul_full_string(struct torture_context *tctx) +{ + const char *number = "123 "; + const char *number2 = "123"; + int err; + + err = 0; + smb_strtoul(number, NULL, 0, &err, SMB_STR_FULL_STR_CONV); + torture_assert(tctx, err == EINVAL, "strtoul_err: Expected EINVAL"); + + err = 0; + smb_strtoull(number, NULL, 0, &err, SMB_STR_FULL_STR_CONV); + torture_assert(tctx, err == EINVAL, "strtoull_err: Expected EINVAL"); + + err = 0; + smb_strtoul(number2, NULL, 0, &err, SMB_STR_FULL_STR_CONV); + torture_assert(tctx, err == 0, "strtoul_err: Unexpected error"); + + err = 0; + smb_strtoull(number2, NULL, 0, &err, SMB_STR_FULL_STR_CONV); + torture_assert(tctx, err == 0, "strtoull_err: Unexpected error"); + + return true; +} + struct torture_suite *torture_local_util(TALLOC_CTX *mem_ctx) { struct torture_suite *suite = @@ -564,5 +589,8 @@ struct torture_suite *torture_local_util(TALLOC_CTX *mem_ctx) torture_suite_add_simple_test(suite, "smb_strtoul(l) allow_negative", test_smb_strtoul_allow_negative); + torture_suite_add_simple_test(suite, + "smb_strtoul(l) full string conversion", + test_smb_strtoul_full_string); return suite; } |