gbranden pushed a commit to branch master
in repository groff.

commit 44d39da585b8a0713c4b966f0a5e029479b78abb
Author: G. Branden Robinson <[email protected]>
AuthorDate: Fri Dec 12 20:32:08 2025 -0600

    [xtotroff]: Disclose more info in diagnostic.
    
    * src/utils/xtotroff/xtotroff.c (MapFont): Make fatal error diagnostic
      on memory allocation failure disclose how many bytes we attempted to
      grab from the heap.  This way the user can better distinguish system
      starvation scenarios from attempted denial-of-service attacks (or
      worse).  (Admittedly, few people ever run xtotroff at all, let alone
      in scenarios where a busy system is so pinned that `malloc(PATH_MAX)`
      is likely to fail.  But I feel that since we have this information, we
      should disclose it.)
---
 ChangeLog                     | 12 ++++++++++++
 src/utils/xtotroff/xtotroff.c |  6 ++++--
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 9c2c2ce06..ad74067e3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2025-12-12  G. Branden Robinson <[email protected]>
+
+       * src/utils/xtotroff/xtotroff.c (MapFont): Make fatal error
+       diagnostic on memory allocation failure disclose how many bytes
+       we attempted to grab from the heap.  This way the user can
+       better distinguish system starvation scenarios from attempted
+       denial-of-service attacks (or worse).  (Admittedly, few people
+       ever run xtotroff at all, let alone in scenarios where a busy
+       system is so pinned that `malloc(PATH_MAX)` is likely to fail.
+       But I feel that since we have this information, we should
+       disclose it.)
+
 2025-12-17  G. Branden Robinson <[email protected]>
 
        * doc/groff.texi.in (Other Differences):
diff --git a/src/utils/xtotroff/xtotroff.c b/src/utils/xtotroff/xtotroff.c
index 45861a412..7c38dcd38 100644
--- a/src/utils/xtotroff/xtotroff.c
+++ b/src/utils/xtotroff/xtotroff.c
@@ -198,10 +198,12 @@ static bool MapFont(char *font_name, const char 
*troff_name)
 
   if (dirlen > 0) {
     size_t baselen = strlen(troff_name);
-    file_name = malloc(dirlen + baselen + 2 /* '/' and '\0' */);
+    size_t bufsz = dirlen + baselen + 2 /* '/' and '\0' */;
+    file_name = malloc(bufsz);
     if (NULL == file_name) {
       (void) fprintf(stderr, "%s: fatal error:"
-                    " cannot allocate memory\n", program_name);
+                    " cannot allocate %ld bytes for font description"
+                    " file name\n", program_name, bufsz);
       xtotroff_exit(EXIT_FAILURE);
     }
     (void) strcpy(file_name, destdir);

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

Reply via email to