@@ -165,15 +165,18 @@ static void test_basic(void)
165165 }
166166
167167 // Receiving the second response and verifying its validity
168- uint8_t packet_resp [4096 ];
168+ const size_t max_packet_size = 4096 ;
169+ uint8_t * packet_resp = (uint8_t * )malloc (max_packet_size );
170+ ck_assert (packet_resp != nullptr );
169171 int recv_data_len = net_recv (ns , logger , sock , packet_resp , 2 + 2 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE , & localhost );
170172 ck_assert_msg (recv_data_len == 2 + 2 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE ,
171173 "Failed to receive server response to request. %d" , recv_data_len );
172174 memcpy (& size , packet_resp , 2 );
173175 ck_assert_msg (net_ntohs (size ) == 2 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE ,
174176 "Wrong packet size for request response." );
175177
176- uint8_t packet_resp_plain [4096 ];
178+ uint8_t * packet_resp_plain = (uint8_t * )malloc (max_packet_size );
179+ ck_assert (packet_resp_plain != nullptr );
177180 ret = decrypt_data_symmetric (mem , f_shared_key , f_nonce_r , packet_resp + 2 , recv_data_len - 2 , packet_resp_plain );
178181 ck_assert_msg (ret != -1 , "Failed to decrypt the TCP server's response." );
179182 increment_nonce (f_nonce_r );
@@ -183,6 +186,9 @@ static void test_basic(void)
183186 ck_assert_msg (packet_resp_plain [1 ] == 0 , "Server did not refuse the connection." );
184187 ck_assert_msg (pk_equal (packet_resp_plain + 2 , f_public_key ), "Server sent the wrong public key." );
185188
189+ free (packet_resp_plain );
190+ free (packet_resp );
191+
186192 // Closing connections.
187193 kill_sock (ns , sock );
188194 kill_tcp_server (tcp_s );
@@ -337,7 +343,8 @@ static void test_some(void)
337343 do_tcp_server_delay (tcp_s , mono_time , 50 );
338344
339345 // Testing response from connection 1
340- uint8_t data [2048 ];
346+ const size_t max_packet_size = 4096 ;
347+ uint8_t * data = (uint8_t * )malloc (max_packet_size );
341348 int len = read_packet_sec_tcp (logger , con1 , data , 2 + 1 + 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE );
342349 ck_assert_msg (len == 1 + 1 + CRYPTO_PUBLIC_KEY_SIZE , "Wrong response packet length of %d." , len );
343350 ck_assert_msg (data [0 ] == TCP_PACKET_ROUTING_RESPONSE , "Wrong response packet id of %d." , data [0 ]);
@@ -351,7 +358,7 @@ static void test_some(void)
351358 ck_assert_msg (data [1 ] == 16 , "Server didn't refuse connection using wrong public key." );
352359 ck_assert_msg (pk_equal (data + 2 , con1 -> public_key ), "Key in response packet wrong." );
353360
354- uint8_t test_packet [512 ] = {16 , 17 , 16 , 86 , 99 , 127 , 255 , 189 , 78 }; // What is this packet????
361+ const uint8_t test_packet [512 ] = {16 , 17 , 16 , 86 , 99 , 127 , 255 , 189 , 78 }; // What is this packet????
355362
356363 write_packet_tcp_test_connection (logger , con3 , test_packet , sizeof (test_packet ));
357364 write_packet_tcp_test_connection (logger , con3 , test_packet , sizeof (test_packet ));
@@ -406,6 +413,8 @@ static void test_some(void)
406413 ck_assert_msg (data [0 ] == TCP_PACKET_PONG , "wrong packet id %u" , data [0 ]);
407414 ck_assert_msg (memcmp (ping_packet + 1 , data + 1 , sizeof (uint64_t )) == 0 , "wrong packet data" );
408415
416+ free (data );
417+
409418 // Kill off the connections
410419 kill_tcp_server (tcp_s );
411420 kill_tcp_con (con1 );
0 commit comments