Skip to content

Commit 376df03

Browse files
Merge pull request #205 from expressvpn/cvpn-2035-fix
CVPN-2035: Fix using correct struct for validating length
2 parents 7629f4f + bad068c commit 376df03

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/he/msg_handlers.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ he_return_code_t he_handle_msg_auth(he_conn_t *conn, uint8_t *packet, int length
279279

280280
// Check the auth token length
281281
uint16_t auth_token_length = ntohs(msg_token->token_length);
282-
if(auth_token_length > (length - sizeof(he_msg_auth_hdr_t))) {
282+
if(auth_token_length > (length - sizeof(he_msg_auth_token_t))) {
283283
return HE_ERR_PACKET_TOO_SMALL;
284284
}
285285
auth_state = conn->auth_token_cb(conn, msg_token->token, auth_token_length, conn->data);
@@ -298,7 +298,7 @@ he_return_code_t he_handle_msg_auth(he_conn_t *conn, uint8_t *packet, int length
298298

299299
// Check the auth buffer length
300300
uint16_t auth_buf_length = ntohs(msg_buf->buffer_length);
301-
if(auth_buf_length > (length - sizeof(he_msg_auth_hdr_t))) {
301+
if(auth_buf_length > (length - sizeof(he_msg_auth_buf_t))) {
302302
return HE_ERR_PACKET_TOO_SMALL;
303303
}
304304
auth_state = conn->auth_buf_cb(conn, msg_buf->header.auth_type, msg_buf->buffer,

test/he/test_msg_handlers.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,14 @@ void test_msg_auth_token_packet_too_small(void) {
837837
// Call with a small size to trigger the size check
838838
he_return_code_t res = he_handle_msg_auth(conn, empty_data, 4);
839839
TEST_ASSERT_EQUAL(HE_ERR_PACKET_TOO_SMALL, res);
840+
841+
auth_message->header.auth_type = HE_AUTH_TYPE_TOKEN;
842+
// Fake buffer length
843+
auth_message->token_length = ntohs(4);
844+
845+
// Call with a small size to trigger the size check
846+
res = he_handle_msg_auth(conn, empty_data, sizeof(he_msg_auth_token_t) + 2);
847+
TEST_ASSERT_EQUAL(HE_ERR_PACKET_TOO_SMALL, res);
840848
}
841849

842850
void test_msg_auth_token_packet_invalid_length(void) {
@@ -906,6 +914,14 @@ void test_msg_auth_buf_packet_too_small(void) {
906914
// Call with a small size to trigger the size check
907915
he_return_code_t res = he_handle_msg_auth(conn, empty_data, 4);
908916
TEST_ASSERT_EQUAL(HE_ERR_PACKET_TOO_SMALL, res);
917+
918+
auth_message->header.auth_type = HE_AUTH_TYPE_CB;
919+
// Fake buffer length
920+
auth_message->buffer_length = ntohs(4);
921+
922+
// Call with a small size to trigger the size check
923+
res = he_handle_msg_auth(conn, empty_data, sizeof(he_msg_auth_buf_t) + 2);
924+
TEST_ASSERT_EQUAL(HE_ERR_PACKET_TOO_SMALL, res);
909925
}
910926

911927
void test_msg_auth_buf_packet_invalid_length(void) {

0 commit comments

Comments
 (0)