Skip to content

Commit df65997

Browse files
authored
Epoll: setTcpMg5Sig(...) might overflow (#16511) (#16520)
Motivation: We did not check that the provided byte[] will fin into tcpm_key and so might overflow Modifications: Add length check and if it does not fit throw Result: No risk of overflow
1 parent 692ec87 commit df65997

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

transport-native-epoll/src/main/c/netty_epoll_linuxsocket.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,8 +507,13 @@ static void netty_epoll_linuxsocket_setTcpMd5Sig(JNIEnv* env, jclass clazz, jint
507507
}
508508

509509
if (key != NULL) {
510-
md5sig.tcpm_keylen = (*env)->GetArrayLength(env, key);
511-
(*env)->GetByteArrayRegion(env, key, 0, md5sig.tcpm_keylen, (void *) &md5sig.tcpm_key);
510+
jint keylen = (*env)->GetArrayLength(env, key);
511+
if (keylen > TCP_MD5SIG_MAXKEYLEN) {
512+
netty_unix_errors_throwIOException(env, "key is too long");
513+
return;
514+
}
515+
md5sig.tcpm_keylen = (u_int16_t) keylen;
516+
(*env)->GetByteArrayRegion(env, key, 0, keylen, (void *) &md5sig.tcpm_key);
512517
if ((*env)->ExceptionCheck(env) == JNI_TRUE) {
513518
return;
514519
}

0 commit comments

Comments
 (0)