mirror of
https://github.com/intel/llvm.git
synced 2026-01-23 07:58:23 +08:00
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.)
36 lines
1.1 KiB
C++
36 lines
1.1 KiB
C++
//===-- sanitizer_errno.cpp -------------------------------------*- C++ -*-===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file is shared between sanitizers run-time libraries.
|
|
//
|
|
// Defines errno to avoid including errno.h and its dependencies into other
|
|
// files (e.g. interceptors are not supposed to include any system headers).
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "sanitizer_errno_codes.h"
|
|
#include "sanitizer_internal_defs.h"
|
|
|
|
#include <errno.h>
|
|
|
|
namespace __sanitizer {
|
|
|
|
COMPILER_CHECK(errno_ENOMEM == ENOMEM);
|
|
COMPILER_CHECK(errno_EBUSY == EBUSY);
|
|
COMPILER_CHECK(errno_EINVAL == EINVAL);
|
|
COMPILER_CHECK(errno_ERANGE == ERANGE);
|
|
|
|
// EOWNERDEAD is not present in some older platforms.
|
|
#if defined(EOWNERDEAD)
|
|
extern const int errno_EOWNERDEAD = EOWNERDEAD;
|
|
#else
|
|
extern const int errno_EOWNERDEAD = -1;
|
|
#endif
|
|
|
|
} // namespace __sanitizer
|