Skip to content

Commit 61e37ce

Browse files
committed
Check return value of openssl ASN1_string_[get0_]data() functions for NULL.
This prevents a crash in case of incorrect certificate handling in openssl. Closes #3390. Thanks to Qingpeng Du.
1 parent 3591e3a commit 61e37ce

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

ChangeLog.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ Broker:
77
prevent possible crash. This could occur only in extremely unlikely
88
situations. See https://github.com/eclipse-mosquitto/mosquitto/issues/3389
99
Closes #3389.
10+
- Check return value of openssl ASN1_string_[get0_]data() functions for NULL.
11+
This prevents a crash in case of incorrect certificate handling in openssl.
12+
Closes #3390.
1013

1114

1215
2.0.22 - 2025-07-11

src/handle_connect.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ int handle__connect(struct mosquitto *context)
805805
#else
806806
new_username = (const char *) ASN1_STRING_get0_data(name_asn1);
807807
#endif
808-
if(mosquitto_validate_utf8(new_username, (int)strlen(new_username))){
808+
if(!new_username || mosquitto_validate_utf8(new_username, (int)strlen(new_username))){
809809
if(context->protocol == mosq_p_mqtt5){
810810
send__connack(context, 0, MQTT_RC_BAD_USERNAME_OR_PASSWORD, NULL);
811811
}else{

src/security_default.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,10 +1200,17 @@ int mosquitto_security_apply_default(void)
12001200
continue;
12011201
}
12021202
#if OPENSSL_VERSION_NUMBER < 0x10100000L
1203-
context->username = mosquitto__strdup((char *) ASN1_STRING_data(name_asn1));
1203+
const char *username = (const char *)ASN1_STRING_data(name_asn1);
12041204
#else
1205-
context->username = mosquitto__strdup((char *) ASN1_STRING_get0_data(name_asn1));
1205+
const char *username = (const char *)ASN1_STRING_get0_data(name_asn1);
12061206
#endif
1207+
if(!username){
1208+
X509_free(client_cert);
1209+
client_cert = NULL;
1210+
security__disconnect_auth(context);
1211+
continue;
1212+
}
1213+
context->username = mosquitto__strdup(username);
12071214
if(!context->username){
12081215
X509_free(client_cert);
12091216
client_cert = NULL;

0 commit comments

Comments
 (0)