@@ -165,15 +165,18 @@ static void test_basic(void)
165
165
}
166
166
167
167
// 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 );
169
171
int recv_data_len = net_recv (ns , logger , sock , packet_resp , 2 + 2 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE , & localhost );
170
172
ck_assert_msg (recv_data_len == 2 + 2 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE ,
171
173
"Failed to receive server response to request. %d" , recv_data_len );
172
174
memcpy (& size , packet_resp , 2 );
173
175
ck_assert_msg (net_ntohs (size ) == 2 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE ,
174
176
"Wrong packet size for request response." );
175
177
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 );
177
180
ret = decrypt_data_symmetric (mem , f_shared_key , f_nonce_r , packet_resp + 2 , recv_data_len - 2 , packet_resp_plain );
178
181
ck_assert_msg (ret != -1 , "Failed to decrypt the TCP server's response." );
179
182
increment_nonce (f_nonce_r );
@@ -183,6 +186,9 @@ static void test_basic(void)
183
186
ck_assert_msg (packet_resp_plain [1 ] == 0 , "Server did not refuse the connection." );
184
187
ck_assert_msg (pk_equal (packet_resp_plain + 2 , f_public_key ), "Server sent the wrong public key." );
185
188
189
+ free (packet_resp_plain );
190
+ free (packet_resp );
191
+
186
192
// Closing connections.
187
193
kill_sock (ns , sock );
188
194
kill_tcp_server (tcp_s );
@@ -337,7 +343,8 @@ static void test_some(void)
337
343
do_tcp_server_delay (tcp_s , mono_time , 50 );
338
344
339
345
// 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 );
341
348
int len = read_packet_sec_tcp (logger , con1 , data , 2 + 1 + 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE );
342
349
ck_assert_msg (len == 1 + 1 + CRYPTO_PUBLIC_KEY_SIZE , "Wrong response packet length of %d." , len );
343
350
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)
351
358
ck_assert_msg (data [1 ] == 16 , "Server didn't refuse connection using wrong public key." );
352
359
ck_assert_msg (pk_equal (data + 2 , con1 -> public_key ), "Key in response packet wrong." );
353
360
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????
355
362
356
363
write_packet_tcp_test_connection (logger , con3 , test_packet , sizeof (test_packet ));
357
364
write_packet_tcp_test_connection (logger , con3 , test_packet , sizeof (test_packet ));
@@ -406,6 +413,8 @@ static void test_some(void)
406
413
ck_assert_msg (data [0 ] == TCP_PACKET_PONG , "wrong packet id %u" , data [0 ]);
407
414
ck_assert_msg (memcmp (ping_packet + 1 , data + 1 , sizeof (uint64_t )) == 0 , "wrong packet data" );
408
415
416
+ free (data );
417
+
409
418
// Kill off the connections
410
419
kill_tcp_server (tcp_s );
411
420
kill_tcp_con (con1 );
0 commit comments