[all-commits] [llvm/llvm-project] 9f3d08: [win/asan] Ensure errno gets set correctly for str...

Hans via All-commits all-commits at lists.llvm.org
Sun Sep 22 10:05:41 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 9f3d083c4963fcd164fc48e326e5967e6395f28a
      https://github.com/llvm/llvm-project/commit/9f3d083c4963fcd164fc48e326e5967e6395f28a
  Author: Hans <hans at hanshq.net>
  Date:   2024-09-22 (Sun, 22 Sep 2024)

  Changed paths:
    M compiler-rt/lib/asan/asan_interceptors.cpp
    M compiler-rt/lib/asan/asan_win_static_runtime_thunk.cpp
    M compiler-rt/lib/asan/tests/asan_str_test.cpp
    M compiler-rt/lib/sanitizer_common/sanitizer_errno.cpp
    M compiler-rt/lib/sanitizer_common/sanitizer_errno_codes.h
    M compiler-rt/test/asan/TestCases/strtol_strict.c

  Log Message:
  -----------
  [win/asan] Ensure errno gets set correctly for strtol (#109258)

This fixes two problems with asan's interception of `strtol` on Windows:

1. In the dynamic runtime, the `strtol` interceptor calls out to ntdll's
`strtol` to perform the string conversion. Unfortunately, that function
doesn't set `errno`. This has been a long-standing problem (#34485), but
it was not an issue when using the static runtime. After the static
runtime was removed recently (#107899), the problem became more urgent.

2. A module linked against the static CRT will have a different instance
of `errno` than the ASan runtime, since that's now always linked against
the dynamic CRT. That means even if the ASan runtime sets `errno`
correctly, the calling module will not see it.

This patch fixes the first problem by making the `strtol` interceptor
call out to `strtoll` instead, and do 32-bit range checks on the result.

I can't think of any reasonable way to fix the second problem, so we
should stop intercepting `strtol` in the static runtime thunk. I checked
the list of functions in the thunk, and `strtol` and `strtoll` are the
only ones that set `errno`. (`strtoll` was already missing, probably by
mistake.)



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list