From: Swen Schillig Date: Wed, 10 Apr 2019 08:52:35 +0000 (+0200) Subject: tests-util: Adding test to verify "no-conversion" detection X-Git-Tag: ldb-2.0.5~143 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ba021e3cfb2d8497f0e62001782387547e996ded;p=thirdparty%2Fsamba.git tests-util: Adding test to verify "no-conversion" detection The standard string to integer conversion routines return zero if a string was to be converted which did not reflect a number. It is not flag'ed as an error. The wrapper functions strtoul_err() and strtoull_err() are expected to exactly do this. 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 c45f3835cf7..de9dca1ffc5 100644 --- a/lib/util/tests/util.c +++ b/lib/util/tests/util.c @@ -481,6 +481,31 @@ static bool test_strtoul_err_negative(struct torture_context *tctx) return true; } +static bool test_strtoul_err_no_number(struct torture_context *tctx) +{ + const char *number = "ghijk"; + const char *blank = ""; + int err; + + err = 0; + strtoul_err(number, NULL, 0, &err); + torture_assert(tctx, err == EINVAL, "strtoul_err: Expected EINVAL"); + + err = 0; + strtoull_err(number, NULL, 0, &err); + torture_assert(tctx, err == EINVAL, "strtoull_err: Expected EINVAL"); + + err = 0; + strtoul_err(blank, NULL, 0, &err); + torture_assert(tctx, err == EINVAL, "strtoul_err: Expected EINVAL"); + + err = 0; + strtoull_err(blank, NULL, 0, &err); + torture_assert(tctx, err == EINVAL, "strtoull_err: Expected EINVAL"); + + return true; +} + struct torture_suite *torture_local_util(TALLOC_CTX *mem_ctx) { struct torture_suite *suite = @@ -498,5 +523,8 @@ struct torture_suite *torture_local_util(TALLOC_CTX *mem_ctx) torture_suite_add_simple_test(suite, "strtoul(l)_err negative", test_strtoul_err_negative); + torture_suite_add_simple_test(suite, + "strtoul(l)_err no number", + test_strtoul_err_no_number); return suite; }