This is an automated email from the ASF dual-hosted git repository.

markt-asf pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat-native.git


The following commit(s) were added to refs/heads/main by this push:
     new 4c7e985ef Harden against mis-use
4c7e985ef is described below

commit 4c7e985ef7c934833b18f1059f6a277dab130e3b
Author: Mark Thomas <[email protected]>
AuthorDate: Fri Aug 28 18:49:45 2026 +0100

    Harden against mis-use
---
 native/src/bb.c                   | 13 ++++++++++++-
 xdocs/miscellaneous/changelog.xml |  4 ++++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/native/src/bb.c b/native/src/bb.c
index 3e48c9b04..105de1bf8 100644
--- a/native/src/bb.c
+++ b/native/src/bb.c
@@ -22,6 +22,17 @@
 
 TCN_IMPLEMENT_CALL(jlong, Buffer, address)(TCN_STDARGS, jobject bb)
 {
+    void *address;
+
     UNREFERENCED(o);
-    return P2J((*e)->GetDirectBufferAddress(e, bb));
+    address = (*e)->GetDirectBufferAddress(e, bb);
+    if (address == NULL) {
+        jclass npe = (*e)->FindClass(e, "java/lang/NullPointerException");
+        if (npe != NULL) {
+            (*e)->ThrowNew(e, npe, "ByteBuffer is null or not direct");
+            (*e)->DeleteLocalRef(e, npe);
+        }
+        return 0;
+    }
+    return P2J(address);
 }
diff --git a/xdocs/miscellaneous/changelog.xml 
b/xdocs/miscellaneous/changelog.xml
index 656653d43..347d98cca 100644
--- a/xdocs/miscellaneous/changelog.xml
+++ b/xdocs/miscellaneous/changelog.xml
@@ -87,6 +87,10 @@
     <fix>
       Stricter OCSP handling when soft-fail is disabled. (markt)
     </fix>
+    <fix>
+      Harden against the mis-use of <code>Buffer.address(ByteBuffer)</code>.
+      (markt)
+    </fix>
   </changelog>
 </section>
 <section name="2.0.15" rtext="2026-06-15">


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to