More tests for trailing NULs.

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@20370 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Love Hörnquist Åstrand
2007-04-17 17:41:28 +00:00
parent b39214ed96
commit e652d77112

View File

@@ -532,7 +532,7 @@ static int
check_fail_general_string(void)
{
struct test_case tests[] = {
{ NULL, 3, "A\x00B", "NUL char in string"}
{ NULL, 3, "A\x00i", "NUL char in string"}
};
int ntests = sizeof(tests) / sizeof(*tests);
@@ -749,6 +749,46 @@ test_heim_oid_format(void)
return ret;
}
static int
check_trailing_nul(void)
{
int i, ret;
struct {
int fail;
const unsigned char *p;
size_t len;
const char *s;
size_t size;
} foo[] = {
{ 1, (const unsigned char *)"foo\x00o", 5, NULL, 0 },
{ 1, (const unsigned char *)"\x00o", 2, NULL, 0 },
{ 0, (const unsigned char *)"\x00\x00\x00\x00\x00", 5, "", 5 },
{ 0, (const unsigned char *)"foo\x00\x00", 5, "foo", 5 },
{ 0, (const unsigned char *)"foo\0", 4, "foo", 4 },
{ 0, (const unsigned char *)"foo", 3, "foo", 3 }
};
for (i = 0; i < sizeof(foo)/sizeof(foo[0]); i++) {
char *s;
size_t size;
ret = der_get_general_string(foo[i].p, foo[i].len, &s, &size);
if (foo[i].fail) {
if (ret == 0)
errx(1, "check %d NULL didn't fail", i);
continue;
}
if (ret)
errx(1, "NULL check %d der_get_general_string failed", i);
if (foo[i].size != size)
errx(1, "NUL check i = %d size failed", i);
if (strcmp(foo[i].s, s) != 0)
errx(1, "NUL check i = %d content failed", i);
free(s);
}
return 0;
}
int
main(int argc, char **argv)
{
@@ -778,6 +818,7 @@ main(int argc, char **argv)
ret += check_fail_bitstring();
ret += test_heim_int_format();
ret += test_heim_oid_format();
ret += check_trailing_nul();
return ret;
}