mainGNU M4 - Support: sr #110809, UBSAN failure in output.c:511...

 
 

sr #110809: UBSAN failure in output.c:511 (make_room_for)

Submitter:  Sam James <thesamesam>
Submitted:  Sat 07 Jan 2023 10:01:44 PM UTC
Votes: 2
 
Category:  None Priority:  5 - Normal
Severity:  3 - Normal Status:  None
Privacy:  Public Assigned to:  ericb
Open/Closed:  Open Operating System:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Fri 13 Jan 2023 10:25:42 PM UTC, comment #2: 

Thanks for the useful report, including reproduction instructions that worked out of the box.  The code is indeed calling memcpy(dest, NULL, 0) which works on all known libc implementations, but where the sanitizer is indeed correct that NULL is not a pointer to a valid object (even if we won't be copying from it).  It is easy enough to work around, so I'll post a patch along those lines.

Eric Blake <ericb>
Group administrator
Sat 07 Jan 2023 10:20:40 PM UTC, comment #1: 

Sorry, this is GCC 13.0.0_pre20230101.

Sam James <thesamesam>
Sat 07 Jan 2023 10:01:44 PM UTC, original submission:  

When building m4 1.4.19 or from the 'branch-1.4' branch, a collection of Undefined Behaviour Sanitizer (UBSAN, -fsanitize=undefined) errors are thrown both at runtime in real world use and in the test suite.

Steps to reproduce:
1. ./configure CFLAGS="-O2 -fsanitize=undefined -ggdb3" LDFLAGS="-fsanitize=undefined -ggdb3" --disable-gcc-warnings
2. make -j$(nproc)
3. make check -j$(nproc)

This is with GCC 12.2.1_p20221231.

Snippet from build log:
```
[...]
./233.improved_c: stderr mismatch
--- m4-tmp.1998872/m4-xerr      2023-01-07 21:59:28.043863382 +0000
+++ m4-tmp.1998872/m4-err       2023-01-07 21:59:28.030529977 +0000
@@ -0,0 +1,10 @@
+output.c:511:9: runtime error: null pointer passed as argument 2, which is declared to never be null
+    #0 0x5577efe67295 in make_room_for /tmp/m4/src/output.c:511
+    #1 0x5577efe8fe05 in output_character_helper /tmp/m4/src/output.c:539
+    #2 0x5577efe8fe05 in shipout_text /tmp/m4/src/output.c:627
+    #3 0x5577efe8d67d in expand_input /tmp/m4/src/macro.c:68
+    #4 0x5577efe6a3de in main /tmp/m4/src/m4.c:684
+    #5 0x7f1bea2bb289  (/usr/lib64/libc.so.6+0x23289)
+    #6 0x7f1bea2bb344 in __libc_start_main (/usr/lib64/libc.so.6+0x23344)
+    #7 0x5577efe6a980 in _start (/tmp/m4/src/m4+0x52980)
+
Checking ./234.improved_c
Checking ./235.improved_c
Checking ./236.improved_f
Checking ./stackovf.test
Stack soft limit set to 300K
Pass

Skipped checks were:
  ./125.changeword ./126.changeword ./127.changeword ./128.changeword ./129.changeword ./130.changeword
Failed checks were:
  ./143.diversions:err ./144.diversions:err ./145.diversions:err ./146.diversions:err ./147.divert:err ./148.divert:err ./150.divert:err ./152.undivert:err ./153.undivert:err ./154.undivert:err ./155.undivert:err ./157.undivert:err ./158.divnum:err ./159.cleardiver:err ./206.m4exit:err ./212.other_inco:err ./233.improved_c:err
```

```
# ./m4 --version
m4 (GNU M4) 1.4.19.15-bb35
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by René Seindal.
```

I've attached the full test log as 'm4.log' (make check output).

Sam James <thesamesam>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #54200:  m4.log added by thesamesam (21KiB - application/octet-stream - m4.log)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by egallager (Voted in favor of this item)
  • -email is unavailable- added by ericb (Posted a comment)
  • -email is unavailable- added by thesamesam (Submitted the item)
  •  

    There are 2 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2024-02-29 egallager Carbon-Copy- Added egallager
    2023-01-13 ericb Assigned toNone ericb
    2023-01-07 thesamesam Attached File- Added m4.log, #54200

    Back to the top

    Powered by Savane 3.13-04b1.
    Corresponding source code