Commits on Source 11

  • cznic's avatar
    update builder.json · 25f21551
    cznic authored
    25f21551
  • cznic's avatar
    Move strlen(3) to libc_all.go, updates sqlite!88 · 95e1e242
    cznic authored
    This is a classic case of **"Valid C Optimization vs. Strict Memory Safety."**
    
    1. **The Musl C Source:** It is **correct** (by C standards of the
       time). Musl uses a common optimization: reading 8 bytes (a size\_t)
       at a time to check for null terminators in parallel. This relies on
       the assumption that reading aligned words is safe on the hardware
       level (it won't cross a page boundary and fault). It assumes "dirty
       reads" of the bytes immediately following the string are harmless.
    2. **The Transpiler:** It is **correct**. It faithfully translated the
       bit-twiddling logic from C to Go.
    
    The Problem:
    AddressSanitizer (ASan) is designed to flag exactly this kind of behavior.
    
    * **In standard C:** Reading bytes 12-15 of an 11-byte array usually
      just reads the next global variable or padding. No harm done.
    * **With ASan:** ASan inserts "Redzones" (poisoned memory) immediately
      after every allocation.
    * **The Conflict:** The Xstrlen function aligns the pointer and then
      reads a full 8-byte word. For an 11-byte string, the second read grabs
      bytes 8–15. Bytes 11–15 fall into the ASan redzone, triggering the
      global-buffer-overflow.
    
    The fault lies in this loop strategy:
    
    1. **Alignment:** The code advances s until it is 8-byte aligned.
    2. **Word Read:** It casts the pointer to \*uint64 and reads.
    3. **The Overshoot:** If you have an 11-byte string aligned at address 0x1000:
       * **First read (0x1000):** Reads bytes 0-7. (Safe)
       * **Second read (0x1008):** Reads bytes 8-15. (Safe for bytes 8-10, **Illegal** for 11-15).
    
    Musl doesn't care because it masks out the garbage bytes later using the
    HASZERO logic. ASan cares because you *touched* the poisoned memory.
    95e1e242
  • cznic's avatar
    modernc.org/libc: e5-1650 auto generate · 248d5f09
    cznic authored
    248d5f09
  • cznic's avatar
    modernc.org/libc: nuc64 auto generate · 23d53ab3
    cznic authored
    23d53ab3
  • cznic's avatar
    modernc.org/libc: pi32 auto generate · acdc7b5d
    cznic authored
    acdc7b5d
  • cznic's avatar
    modernc.org/libc: pi64 auto generate · 340f9df5
    cznic authored
    340f9df5
  • cznic's avatar
    modernc.org/libc: ppc64le auto generate · 6836d1cb
    cznic authored
    6836d1cb
  • cznic's avatar
    modernc.org/libc: linux_loong64b auto generate · 923344d4
    cznic authored
    923344d4
  • cznic's avatar
    modernc.org/libc: riscv64 auto generate · cd53f037
    cznic authored
    cd53f037
  • cznic's avatar
    modernc.org/libc: s390x auto generate · 674bf5c0
    cznic authored
    674bf5c0
  • cznic's avatar
    libc_all.go: fix strlen() wrt -asan · 101bbe5e
    cznic authored
    101bbe5e
Loading
Loading