asn1: Fix UB and incorrect codec for unconstrained INTEGER values of -1

This commit is contained in:
Nicolas Williams
2022-10-26 01:53:10 -05:00
parent 476d216f89
commit e4311f3a82
5 changed files with 206 additions and 55 deletions

View File

@@ -67,11 +67,12 @@ test_integer (void)
{NULL, 1, "\xff", NULL },
{NULL, 2, "\xff\x01", NULL },
{NULL, 2, "\x00\xff", NULL },
{NULL, 2, "\xfe\x01", NULL },
{NULL, 4, "\x7f\xff\xff\xff", NULL }
};
int values[] = {0, 127, 128, 256, -128, -129, -1, -255, 255,
0x7fffffff};
-511, 0x7fffffff};
int i, ret;
int ntests = sizeof(tests) / sizeof(*tests);
@@ -153,7 +154,7 @@ test_one_int(int val)
static int
test_integer_more (void)
{
int i, n1, n2, n3, n4, n5, n6;
int64_t i, n1, n2, n3, n4, n5, n6;
n2 = 0;
for (i = 0; i < (sizeof(int) * 8); i++) {
@@ -522,23 +523,27 @@ static int
test_heim_integer (void)
{
struct test_case tests[] = {
{NULL, 1, "\xff", NULL },
{NULL, 2, "\xff\x01", NULL },
{NULL, 2, "\xfe\x01", NULL },
{NULL, 2, "\xef\x01", NULL },
{NULL, 3, "\xff\x00\xff", NULL },
{NULL, 3, "\xff\x01\x00", NULL },
{NULL, 1, "\x00", NULL },
{NULL, 1, "\x01", NULL },
{NULL, 2, "\x00\x80", NULL }
{NULL, 2, "\x00\x80", NULL },
};
heim_integer values[] = {
{ 1, "\x01", 1 },
{ 1, "\xff", 1 },
{ 2, "\x01\xff", 1 },
{ 2, "\x10\xff", 1 },
{ 2, "\xff\x01", 1 },
{ 2, "\xff\x00", 1 },
{ 0, "", 0 },
{ 1, "\x01", 0 },
{ 1, "\x80", 0 }
{ 1, "\x80", 0 },
};
int i, ret;
int ntests = sizeof(tests) / sizeof(tests[0]);