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

asf-gitbox-commits pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/openoffice.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 68e3364441 Fix a possible stack overflow caused by infinite recursion 
when recursively converting Java exception causes which form cycles.
68e3364441 is described below

commit 68e3364441a5fc788fd68015de159f98e3e8a22c
Author: Damjan Jovanovic <[email protected]>
AuthorDate: Fri Jun 26 20:21:56 2026 +0200

    Fix a possible stack overflow caused by infinite recursion when
    recursively converting Java exception causes which form cycles.
    
    Patch by: me
    Fixes: https://bz.apache.org/ooo/show_bug.cgi?id=128633
---
 .../java/sdbc_jdbc/src/com/sun/star/comp/sdbc/Tools.java      | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git 
a/main/connectivity/java/sdbc_jdbc/src/com/sun/star/comp/sdbc/Tools.java 
b/main/connectivity/java/sdbc_jdbc/src/com/sun/star/comp/sdbc/Tools.java
index f17eaef6dd..49cb07cb0f 100644
--- a/main/connectivity/java/sdbc_jdbc/src/com/sun/star/comp/sdbc/Tools.java
+++ b/main/connectivity/java/sdbc_jdbc/src/com/sun/star/comp/sdbc/Tools.java
@@ -32,7 +32,13 @@ import com.sun.star.uno.Any;
 import com.sun.star.uno.AnyConverter;
 
 public class Tools {
+    private static final int MAX_EXCEPTION_NESTING = 8;
+
     public static SQLException toUnoException(Object source, Throwable 
throwable) {
+        return toUnoException(source, throwable, 0);
+    }
+
+    private static SQLException toUnoException(Object source, Throwable 
throwable, int nesting) {
         // FIXME: use SQLException.getNextException() instead of getCause()?
         // There are up to 3 dimensions of exception chaining of warnings in 
Java,
         // getCause(), getNextException(), and getNextWarning().
@@ -40,8 +46,9 @@ public class Tools {
         // but I am using the widely used and more helpful getCause().
         Throwable cause = throwable.getCause();
         Object unoCause = Any.VOID;
-        if (cause != null) {
-            unoCause = toUnoException(source, throwable);
+        // Avoid loops and limit recursion to prevent stack overflows:
+        if (cause != null && cause != throwable && nesting < 
MAX_EXCEPTION_NESTING) {
+            unoCause = toUnoException(source, throwable, nesting + 1);
         }
         if (throwable instanceof SQLException) {
             return (SQLException)throwable;

Reply via email to