gbranden pushed a commit to branch master
in repository groff.

commit ec98603c49a1b69be59673e94541ddf506ed409f
Author: G. Branden Robinson <[email protected]>
AuthorDate: Mon Nov 9 07:10:28 2026 -0600

    [tbl]: Fix Savannah #68897.
    
    * src/preproc/tbl/main.cpp (process_format): Stop deleting the `format`
      passed in as an argument if rejecting table description because its
      final row definition contains only horizontal rules.  I can't improve
      on Dickson Wu's analysis (slightly recast).
    
        "In src/preproc/tbl/main.cpp (1.25.0), `process_table()` owns
        the first format ... [Upon] `.T&`, `process_data()` hands that
        same object back to `process_format()` as `current_format`
        {line 1617}, and `process_format()` keeps extending it in
        place (`f = current_format;`, line 1254).  The all-lines check
        then deletes it ... `process_data()` gives up and returns [a]
        null [pointer], and `process_table()` reaches `delete fmt`
        with a dangling pointer.  The other continued-format error
        path, "cannot increase the number of columns", already returns
        without deleting.  Only this one gets ownership wrong."
    
      Remedy by deleting the deletion of `f` on the "all-lines" error path.
      For me, using a GCC 12 ASAN build, this resolves the heap-use-after-
      free and does not introduce a memory leak.
    
    Fixes <https://savannah.gnu.org/bugs/?68897>.  Thanks to Dickson Wu for
    the report; a cogent analysis; and a plausible, cautious recommended
    fix.  I went with a different one, doing nothing with `f` on the error
    path.
    
    ANNOUNCE: Acknowledge Dickson.
---
 ANNOUNCE                 |  1 +
 ChangeLog                | 26 ++++++++++++++++++++++++++
 src/preproc/tbl/main.cpp |  1 -
 3 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/ANNOUNCE b/ANNOUNCE
index 40f2b3981..2cc4badec 100644
--- a/ANNOUNCE
+++ b/ANNOUNCE
@@ -229,5 +229,6 @@ of this release.
    instance with "grep -i -A1 thanks ChangeLog".  A manual merge of
    similar from the contrib/ change log files may also be necessary. ]]
 
+Dickson Wu
 Morten Bo Johansen
 Stefan Möding
diff --git a/ChangeLog b/ChangeLog
index ada61775a..c2c4a21b2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,29 @@
+2026-11-09  G. Branden Robinson <[email protected]>
+
+       * src/preproc/tbl/main.cpp (process_format): Stop deleting the
+       `format` passed in as an argument if rejecting table description
+       because its final row definition contains only horizontal rules.
+       I can't improve on Dickson Wu's analysis (slightly recast).
+         "In src/preproc/tbl/main.cpp (1.25.0), `process_table()` owns
+         the first format ... [Upon] `.T&`, `process_data()` hands that
+         same object back to `process_format()` as `current_format`
+         {line 1617}, and `process_format()` keeps extending it in
+         place (`f = current_format;`, line 1254).  The all-lines check
+         then deletes it ... `process_data()` gives up and returns [a]
+         null [pointer], and `process_table()` reaches `delete fmt`
+         with a dangling pointer.  The other continued-format error
+         path, "cannot increase the number of columns", already returns
+         without deleting.  Only this one gets ownership wrong."
+       Remedy by deleting the deletion of `f` on the "all-lines" error
+       path.  For me, using a GCC 12 ASAN build, this resolves the
+       heap-use-after-free and does not introduce a memory leak.
+
+       Fixes <https://savannah.gnu.org/bugs/?68897>.  Problem appears
+       to date back to groff's birth.  Thanks to Dickson Wu for the
+       report; a cogent analysis; and a plausible, cautious recommended
+       fix.  I went with a different one, doing nothing with `f` on the
+       error path.
+
 2026-11-09  G. Branden Robinson <[email protected]>
 
        [tbl]: Regression-test Savannah #68897.
diff --git a/src/preproc/tbl/main.cpp b/src/preproc/tbl/main.cpp
index b33d5e736..e66fad189 100644
--- a/src/preproc/tbl/main.cpp
+++ b/src/preproc/tbl/main.cpp
@@ -1319,7 +1319,6 @@ static format *process_format(table_input &in, options 
*opt,
   if (col >= ncolumns) {
     error("final row definition in table description"
          " cannot contain only horizontal rules ('-', '_', '=')");
-    delete f;
     return 0 /* nullptr */;
   }
   if (have_expand && (opt->flags & table::EXPAND)) {

_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit

Reply via email to