diff options
author | Douglas Bagnall <douglas.bagnall@catalyst.net.nz> | 2016-12-07 14:35:58 +1300 |
---|---|---|
committer | Douglas Bagnall <dbagnall@samba.org> | 2016-12-14 05:02:24 +0100 |
commit | 6c9a185be260a914bc0bd2dcf76c9dcb9664a687 (patch) | |
tree | 38929c12f8914751b645ae5742ec43dc5ea34d33 /source4/torture/ndr | |
parent | c0549aea68662cb7a1309d358fc8480f0023e360 (diff) | |
download | samba-6c9a185be260a914bc0bd2dcf76c9dcb9664a687.tar.gz |
s4-torture: better, failing, tests for GUID_from_string
These tests reveal that the current implementation accepts all kinds
of invalid GUIDs. In particular, we fail on these ones:
"00000001-0002-0003-0405--060708090a0"
"-0000001-0002-0003-0405-060708090a0b"
"-0000001-0002-0003-04-5-060708090a0b"
"d0000001-0002-0003-0405-060708090a-b"
"00000001- -2-0003-0405-060708090a0b"
"00000001-0002-0003-0405- 060708090a0"
"0x000001-0002-0003-0405-060708090a0b"
"00000001-0x02-0x03-0405-060708090a0b"
This test is added to selftest/knownfail.
The test for valid string GUIDs is extended to test upper and mixed case
GUIDs.
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'source4/torture/ndr')
-rw-r--r-- | source4/torture/ndr/ndr.c | 64 |
1 files changed, 55 insertions, 9 deletions
diff --git a/source4/torture/ndr/ndr.c b/source4/torture/ndr/ndr.c index 7d28eb01869..d67585c723a 100644 --- a/source4/torture/ndr/ndr.c +++ b/source4/torture/ndr/ndr.c @@ -296,17 +296,61 @@ static bool test_guid_from_string_null(struct torture_context *tctx) static bool test_guid_from_string_invalid(struct torture_context *tctx) { struct GUID g1; - torture_assert_ntstatus_equal(tctx, NT_STATUS_INVALID_PARAMETER, - GUID_from_string("bla", &g1), - "parameter not invalid"); + bool failed = false; + int i; + const char *bad_guids[] = { + "bla", + "", + /* + "00000001-0002-0003-0405-060708090a0b", correct + */ + "00000001-0002-0003-0405-060708090a0b1", /* too long */ + "00000001-0002-0003-0405-060708090a0", /* too short */ + "00000001-0002-0003-0405--060708090a0", /* negative */ + "00000001-0002-0003--0405-060708090a0", /* negative */ + "-0000001-0002-0003-0405-060708090a0b", /* negative */ + "-0000001-0002-0003-04-5-060708090a0b", /* negative */ + "d0000001-0002-0003-0405-060708090a-b", /* negative */ + "00000001- -2-0003-0405-060708090a0b", /* negative, space */ + "00000001-0002-0003-0405- 060708090a0", /* whitespace */ + " 0000001-0002-0003--0405-060708090a0", /* whitespace */ + "00000001-0002-0003--0405-060708090a ", /* whitespace */ + "0000001-00002-0003-04050-60708090a0b", /* misshapen */ + "00000010-0002-0003-04050-60708090a0b", /* misshapen */ + "00000001-0002-0003-0405-0z0708090a0b", /* bad char */ + "00000001-00x2-0x03-0405-060708090a0b", /* bad char (00x) */ + "0x000001-0002-0003-0405-060708090a0b", /* 0x char */ + "00000001-0x02-0x03-0405-060708090a0b", /* 0x char */ + }; + + for (i = 0; i < ARRAY_SIZE(bad_guids); i++) { + NTSTATUS status = GUID_from_string(bad_guids[i], &g1); + if (! NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) { + torture_comment(tctx, "bad guid %s parsed as OK\n", + bad_guids[i]); + failed = true; + } + } + if (failed) { + torture_fail(tctx, "wrongly allowing invalid guids"); + } return true; } static bool test_guid_from_string(struct torture_context *tctx) { struct GUID g1, exp; + /* we are asserting all these guids are valid and equal */ + const char *guids[4] = { + "00000001-0002-0003-0405-060708090a0b", + "{00000001-0002-0003-0405-060708090a0b}", + "{00000001-0002-0003-0405-060708090a0B}", /* mixed */ + "00000001-0002-0003-0405-060708090A0B", /* upper */ + }; + int i; + torture_assert_ntstatus_ok(tctx, - GUID_from_string("00000001-0002-0003-0405-060708090a0b", &g1), + GUID_from_string(guids[0], &g1), "invalid return code"); exp.time_low = 1; exp.time_mid = 2; @@ -319,12 +363,14 @@ static bool test_guid_from_string(struct torture_context *tctx) exp.node[3] = 9; exp.node[4] = 10; exp.node[5] = 11; - torture_assert(tctx, GUID_equal(&g1, &exp), "UUID parsed incorrectly"); - torture_assert_ntstatus_ok(tctx, - GUID_from_string("{00000001-0002-0003-0405-060708090a0b}", &g1), - "invalid return code"); - torture_assert(tctx, GUID_equal(&g1, &exp), "UUID parsed incorrectly"); + for (i = 1; i < ARRAY_SIZE(guids); i++) { + torture_assert_ntstatus_ok(tctx, + GUID_from_string(guids[i], &g1), + "invalid return code"); + torture_assert(tctx, GUID_equal(&g1, &exp), + "UUID parsed incorrectly"); + } return true; } |