From: Swen Schillig Date: Mon, 3 Jun 2019 08:37:07 +0000 (+0200) Subject: tests-util: Adding test to verify "full-string-conversion" flag X-Git-Tag: ldb-2.0.5~130 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=dac981a3887fe79650b38e63799e344b22c8f5f1;p=thirdparty%2Fsamba.git 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 Reviewed-by: Ralph Boehme Reviewed-by: Christof Schmitt --- 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; }