Skip to content

Commit 6089db4

Browse files
authored
proto_smpp: bound sm_length against buffer overflow (#3891)
Clamp attacker-controlled sm_length to MAX_SMS_CHARACTERS in parse_submit_or_deliver_body() and reject oversized or odd UCS2 lengths in recv_smpp_msg() before they reach copy_fixed_str() or the GSM7/UCS2 decoders. Fixes a stack/heap buffer overflow reachable from a malicious SMSC peer sending submit_sm/deliver_sm with sm_length > 254. Signed-off-by: NetworkLab Dev <info@networklab.ca>
1 parent 5f106c4 commit 6089db4

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

modules/proto_smpp/smpp.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,12 @@ static void parse_submit_or_deliver_body(smpp_submit_sm_t *body, smpp_header_t *
10001000
body->data_coding = *p++;
10011001
body->sm_default_msg_id = *p++;
10021002
body->sm_length = *p++;
1003+
if (body->sm_length > MAX_SMS_CHARACTERS) {
1004+
LM_ERR("invalid short_message length %u (max %u)\n",
1005+
body->sm_length, MAX_SMS_CHARACTERS);
1006+
body->sm_length = 0;
1007+
return;
1008+
}
10031009
copy_fixed_str(body->short_message, p, body->sm_length);
10041010
}
10051011

@@ -1572,6 +1578,14 @@ static int recv_smpp_msg(smpp_header_t *header, smpp_deliver_sm_t *body,
15721578
else
15731579
init_str(&hdr, "Content-Type:text/plain\r\n");
15741580

1581+
if (body->sm_length > MAX_SMS_CHARACTERS) {
1582+
LM_ERR("invalid short_message length %u (max %u)\n",
1583+
body->sm_length, MAX_SMS_CHARACTERS);
1584+
pkg_free(src.s);
1585+
pkg_free(dst.s);
1586+
return -1;
1587+
}
1588+
15751589
if (body->data_coding == SMPP_CODING_UCS2) {
15761590
memset(sms_body,0,2*MAX_SMS_CHARACTERS);
15771591
body_str.len = string2hex((char *)body->short_message,

0 commit comments

Comments
 (0)