Skip to content

Commit a879c85

Browse files
committed
Decoding of the SNI server_name allow to embed NUL Character
Motivation: We incorrectly used NewStringUTF(...) to construct the java string which uses modified UTF-8 and so could result in have embed NUL chars. We need to ensure we re-construct the java string from the byte array to ensure nothing is re-interpreted. Modifications: Replace use of NewStringUTF(...) with tcn_new_stringn(...) which is the correct thing to use when creating a String from raw bytes received on the wire. Result: Correct converting of SNI server_name to java string
1 parent 92dd66f commit a879c85

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

‎openssl-dynamic/src/main/c/ssl.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2612,7 +2612,7 @@ TCN_IMPLEMENT_CALL(jstring, SSL, getSniHostname)(TCN_STDARGS, jlong ssl)
26122612
if (servername == NULL) {
26132613
return NULL;
26142614
}
2615-
return tcn_new_string(e, servername);
2615+
return tcn_new_stringn(e, servername, strlen(servername));
26162616
}
26172617

26182618
TCN_IMPLEMENT_CALL(jboolean, SSL, isSessionReused)(TCN_STDARGS, jlong ssl)

‎openssl-dynamic/src/main/c/sslcontext.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2616,7 +2616,7 @@ static int ssl_servername_cb(SSL *ssl, int *ad, void *arg)
26162616
if (tcn_get_java_env(&e) != JNI_OK) {
26172617
return SSL_TLSEXT_ERR_ALERT_FATAL;
26182618
}
2619-
if ((servername_str = (*e)->NewStringUTF(e, servername)) == NULL) {
2619+
if ((servername_str = tcn_new_stringn(e, servername, strlen(servername))) == NULL) {
26202620
return SSL_TLSEXT_ERR_ALERT_FATAL;
26212621
}
26222622
result = (*e)->CallBooleanMethod(e, c->sni_hostname_matcher, c->sni_hostname_matcher_method, P2J(ssl), servername_str);

0 commit comments

Comments
 (0)