Skip to content

Commit

Permalink
Fix memory issue in test varints
Browse files Browse the repository at this point in the history
  • Loading branch information
huitema committed Dec 17, 2023
1 parent 0cb7fcc commit 7b2ebee
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion UnitTest1/unittest1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ namespace UnitTest1
Assert::AreEqual(ret, 0);
}

TEST_METHOD(test_varints)
TEST_METHOD(varints)
{
int ret = varint_test();

Expand Down
7 changes: 5 additions & 2 deletions picoquictest/edge_cases.c
Original file line number Diff line number Diff line change
Expand Up @@ -1013,8 +1013,7 @@ int reset_repeat_test_one(uint8_t test_id)
ret == 0) {
int was_active = 0;
picoquic_stream_head_t* c_stream = picoquic_find_stream(test_ctx->cnx_client, data_stream_id);
picoquic_stream_head_t* s_stream = (test_ctx->cnx_server == NULL)?NULL:
picoquic_find_stream(test_ctx->cnx_server, data_stream_id);
picoquic_stream_head_t* s_stream = picoquic_find_stream(test_ctx->cnx_server, data_stream_id);
if (c_stream != NULL && c_stream->sent_offset > 10000 && s_stream != NULL) {
break;
}
Expand All @@ -1033,6 +1032,10 @@ int reset_repeat_test_one(uint8_t test_id)
/* Verify that the stream #4 is present, and the
* transmission has not stopped.
*/
if (!(TEST_CLIENT_READY) || !(TEST_SERVER_READY)) {
DBG_PRINTF("%s", "Sevrer or client not ready!");
ret = -1;
}
if (ret == 0) {
picoquic_stream_head_t* stream = picoquic_find_stream(test_ctx->cnx_client, data_stream_id);
if (stream == NULL || stream->fin_sent) {
Expand Down
12 changes: 8 additions & 4 deletions picoquictest/intformattest.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,21 +249,25 @@ static size_t nb_varint_test_cases = sizeof(varint_test_cases) / sizeof(picoquic
int varint_test()
{
int ret = 0;
uint8_t test_buf[16];
const picoquic_varintformat_test_t* max_test = varint_test_cases + nb_varint_test_cases;
memset(test_buf, 0xcc, 16);

for (picoquic_varintformat_test_t* test = varint_test_cases; ret == 0 && test < max_test; test++) {
for (int is_new_decode = 0; ret == 0 && is_new_decode <= 1; is_new_decode++) {
for (size_t buf_size = 0; ret == 0 && buf_size <= test->length + 2; buf_size++) {
for (size_t buf_size = 0; ret == 0 && buf_size <= test->length + 2 && buf_size < 16; buf_size++) {
int test_ret = 0;
uint64_t n64 = 0;
size_t length;

memcpy(test_buf, test->encoding, test->length);

if (is_new_decode) {
const uint8_t* bytes = picoquic_frames_varint_decode(test->encoding, test->encoding + buf_size, &n64);
length = bytes != NULL ? bytes - test->encoding : 0;
const uint8_t* bytes = picoquic_frames_varint_decode(test_buf, test_buf + buf_size, &n64);
length = bytes != NULL ? bytes - test_buf : 0;
}
else {
length = picoquic_varint_decode(test->encoding, buf_size, &n64);
length = picoquic_varint_decode(test_buf, buf_size, &n64);
}

if (length != (buf_size < test->length ? 0 : test->length)) {
Expand Down

0 comments on commit 7b2ebee

Please sign in to comment.