[msan] strsignal interceptor

Reviewed By: kstoimenov

Differential Revision: https://reviews.llvm.org/D120082
This commit is contained in:
Vitaly Buka 2022-02-17 13:06:11 -08:00
parent 79b0fa08e0
commit c046cff1cf
2 changed files with 23 additions and 0 deletions

View File

@ -1436,6 +1436,15 @@ static uptr signal_impl(int signo, uptr cb) {
#include "sanitizer_common/sanitizer_common_syscalls.inc"
#include "sanitizer_common/sanitizer_syscalls_netbsd.inc"
INTERCEPTOR(const char *, strsignal, int sig) {
void *ctx;
COMMON_INTERCEPTOR_ENTER(ctx, strsignal, sig);
const char *res = REAL(strsignal)(sig);
if (res)
__msan_unpoison(res, internal_strlen(res) + 1);
return res;
}
struct dlinfo {
char *dli_fname;
void *dli_fbase;
@ -1699,6 +1708,7 @@ void InitializeInterceptors() {
INTERCEPT_FUNCTION(gethostname);
MSAN_MAYBE_INTERCEPT_EPOLL_WAIT;
MSAN_MAYBE_INTERCEPT_EPOLL_PWAIT;
INTERCEPT_FUNCTION(strsignal);
INTERCEPT_FUNCTION(dladdr);
INTERCEPT_FUNCTION(dlerror);
INTERCEPT_FUNCTION(dl_iterate_phdr);

View File

@ -0,0 +1,13 @@
// RUN: %clangxx_msan -O0 %s -o %t && %run %t
#include <assert.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
int main(void) {
const char *p = strsignal(SIGSEGV);
assert(p);
printf("%s %zu\n", p, strlen(p));
return 0;
}