Skip to content

Commit

Permalink
unittests: Do not use uninitialized memory
Browse files Browse the repository at this point in the history
Thanks Coverity CID 414676, 414677, 414678,
414679, 414680, 414681, 414682, 414683, 414684,
414685, 414686
  • Loading branch information
xhanulik committed Feb 7, 2024
1 parent 4deace2 commit 5747804
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/tests/unittests/strip_pkcs1_2_padding.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ torture_long_output_buffer(void **state)
0x00,
'm', 's', 'g'};
unsigned int out_len = 3;
unsigned char *out = malloc(out_len * sizeof(unsigned char));
unsigned char *out = calloc(out_len, sizeof(unsigned char));
unsigned char result_msg[] = {'m', 's', 'g'};
int r = sc_pkcs1_strip_02_padding_constant_time(NULL, n, in, in_len, out, &out_len);
assert_int_equal(r, 3);
Expand All @@ -32,7 +32,7 @@ torture_short_output_buffer(void **state)
0x00,
'm', 's', 'g'};
unsigned int out_len = 1;
unsigned char *out = malloc(out_len * sizeof(unsigned char));
unsigned char *out = calloc(out_len, sizeof(unsigned char));
int r = sc_pkcs1_strip_02_padding_constant_time(NULL, n, in, in_len, out, &out_len);
assert_int_equal(r, SC_ERROR_WRONG_PADDING);
free(out);
Expand All @@ -48,7 +48,7 @@ torture_short_message_correct_padding(void **state)
0x00,
'm', 's', 'g'};
unsigned int out_len = 3;
unsigned char *out = malloc(out_len * sizeof(unsigned char));
unsigned char *out = calloc(out_len, sizeof(unsigned char));
unsigned char result_msg[] = {'m', 's', 'g'};
int r = sc_pkcs1_strip_02_padding_constant_time(NULL, n, in, in_len, out, &out_len);
assert_int_equal(r, 3);
Expand All @@ -66,7 +66,7 @@ torture_missing_first_zero(void **state)
0x00,
'm', 's', 'g'};
unsigned int out_len = 10;
unsigned char *out = malloc(out_len * sizeof(unsigned char));
unsigned char *out = calloc(out_len, sizeof(unsigned char));
int r = sc_pkcs1_strip_02_padding_constant_time(NULL, n, in, in_len, out, &out_len);
assert_int_equal(r, SC_ERROR_WRONG_PADDING);
free(out);
Expand All @@ -82,7 +82,7 @@ torture_missing_two(void **state)
0x00,
'm', 's', 'g'};
unsigned int out_len = 10;
unsigned char *out = malloc(out_len * sizeof(unsigned char));
unsigned char *out = calloc(out_len, sizeof(unsigned char));
int r = sc_pkcs1_strip_02_padding_constant_time(NULL, n, in, in_len, out, &out_len);
assert_int_equal(r, SC_ERROR_WRONG_PADDING);
free(out);
Expand All @@ -98,7 +98,7 @@ torture_short_padding(void **state)
0x00,
'm', 's', 'g'};
unsigned int out_len = 10;
unsigned char *out = malloc(out_len * sizeof(unsigned char));
unsigned char *out = calloc(out_len, sizeof(unsigned char));
int r = sc_pkcs1_strip_02_padding_constant_time(NULL, n, in, in_len, out, &out_len);
assert_int_equal(r, SC_ERROR_WRONG_PADDING);
free(out);
Expand All @@ -113,7 +113,7 @@ torture_missing_second_zero(void **state)
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
'm', 's', 'g'};
unsigned int out_len = 10;
unsigned char *out = malloc(out_len * sizeof(unsigned char));
unsigned char *out = calloc(out_len, sizeof(unsigned char));
int r = sc_pkcs1_strip_02_padding_constant_time(NULL, n, in, in_len, out, &out_len);
assert_int_equal(r, SC_ERROR_WRONG_PADDING);
free(out);
Expand All @@ -128,7 +128,7 @@ torture_missing_message(void **state)
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x00};
unsigned int out_len = 11;
unsigned char *out = malloc(out_len * sizeof(unsigned char));
unsigned char *out = calloc(out_len, sizeof(unsigned char));
int r = sc_pkcs1_strip_02_padding_constant_time(NULL, n, in, in_len, out, &out_len);
assert_int_equal(r, SC_ERROR_WRONG_PADDING);
free(out);
Expand All @@ -144,7 +144,7 @@ torture_one_byte_message(void **state)
0x00,
'm'};
unsigned int out_len = 1;
unsigned char *out = malloc(out_len * sizeof(unsigned char));
unsigned char *out = calloc(out_len, sizeof(unsigned char));
unsigned char result_msg[] = {'m'};
int r = sc_pkcs1_strip_02_padding_constant_time(NULL, n, in, in_len, out, &out_len);
assert_int_equal(r, 1);
Expand All @@ -162,7 +162,7 @@ torture_longer_padding(void **state)
0x00,
0x9d, 0x98, 0x3d, 0xca, 0xa9, 0xa7, 0x11, 0x0a};
unsigned int out_len = 8;
unsigned char *out = malloc(out_len * sizeof(unsigned char));
unsigned char *out = calloc(out_len, sizeof(unsigned char));
unsigned char result_msg[] = {0x9d, 0x98, 0x3d, 0xca, 0xa9, 0xa7, 0x11, 0x0a};
int r = sc_pkcs1_strip_02_padding_constant_time(NULL, n, in, in_len, out, &out_len);
assert_int_equal(r, 8);
Expand All @@ -179,7 +179,7 @@ torture_empty_message(void **state)
0x0e, 0x38, 0x97, 0x18, 0x16, 0x57, 0x9e, 0x30, 0xb6, 0xa5, 0x78, 0x13, 0x20, 0xca, 0x11,
0x00};
unsigned int out_len = 8;
unsigned char *out = malloc(out_len * sizeof(unsigned char));
unsigned char *out = calloc(out_len, sizeof(unsigned char));
int r = sc_pkcs1_strip_02_padding_constant_time(NULL, n, in, in_len, out, &out_len);
assert_int_equal(r, 0);
free(out);
Expand Down

0 comments on commit 5747804

Please sign in to comment.