Skip to content

Commit

Permalink
[Msan] Fix the getline.cc test to pass on FreeBSD
Browse files Browse the repository at this point in the history
Differential Revision: http://reviews.llvm.org/D9251

llvm-svn: 235975
v-kutuzov committed Apr 28, 2015
1 parent 41ad9c4 commit 86e0249
Showing 3 changed files with 30 additions and 18 deletions.
42 changes: 25 additions & 17 deletions compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
Original file line number Diff line number Diff line change
@@ -3904,25 +3904,33 @@ INTERCEPTOR(SSIZE_T, getline, char **lineptr, SIZE_T *n, void *stream) {
}
return res;
}
INTERCEPTOR(SSIZE_T, __getdelim, char **lineptr, SIZE_T *n, int delim,
void *stream) {
void *ctx;
COMMON_INTERCEPTOR_ENTER(ctx, __getdelim, lineptr, n, delim, stream);
// FIXME: under ASan the call below may write to freed memory and corrupt
// its metadata. See
// https://code.google.com/p/address-sanitizer/issues/detail?id=321.
SSIZE_T res = REAL(__getdelim)(lineptr, n, delim, stream);
if (res > 0) {
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, lineptr, sizeof(*lineptr));
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, n, sizeof(*n));
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, *lineptr, res + 1);

// FIXME: under ASan the call below may write to freed memory and corrupt its
// metadata. See
// https://code.google.com/p/address-sanitizer/issues/detail?id=321.
#define GETDELIM_INTERCEPTOR_IMPL(vname) \
{ \
void *ctx; \
COMMON_INTERCEPTOR_ENTER(ctx, vname, lineptr, n, delim, stream); \
SSIZE_T res = REAL(vname)(lineptr, n, delim, stream); \
if (res > 0) { \
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, lineptr, sizeof(*lineptr)); \
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, n, sizeof(*n)); \
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, *lineptr, res + 1); \
} \
return res; \
}
return res;
}

INTERCEPTOR(SSIZE_T, __getdelim, char **lineptr, SIZE_T *n, int delim,
void *stream)
GETDELIM_INTERCEPTOR_IMPL(__getdelim)

// There's no __getdelim() on FreeBSD so we supply the getdelim() interceptor
// with its own body.
INTERCEPTOR(SSIZE_T, getdelim, char **lineptr, SIZE_T *n, int delim,
void *stream) {
return __getdelim(lineptr, n, delim, stream);
}
void *stream)
GETDELIM_INTERCEPTOR_IMPL(getdelim)

#define INIT_GETLINE \
COMMON_INTERCEPT_FUNCTION(getline); \
COMMON_INTERCEPT_FUNCTION(__getdelim); \
Original file line number Diff line number Diff line change
@@ -208,7 +208,7 @@
#define SANITIZER_INTERCEPT_TIMES SI_NOT_WINDOWS

// FIXME: getline seems to be available on OSX 10.7
#define SANITIZER_INTERCEPT_GETLINE SI_LINUX_NOT_ANDROID
#define SANITIZER_INTERCEPT_GETLINE SI_FREEBSD || SI_LINUX_NOT_ANDROID

#define SANITIZER_INTERCEPT__EXIT SI_LINUX || SI_FREEBSD

4 changes: 4 additions & 0 deletions compiler-rt/test/msan/getline.cc
Original file line number Diff line number Diff line change
@@ -7,6 +7,10 @@
// RUN: %clang_msan -O0 -xc -D_GNU_SOURCE=1 %s -o %t && %run %t %t-testdata
// RUN: %clang_msan -O2 -xc -D_GNU_SOURCE=1 %s -o %t && %run %t %t-testdata

#if defined(__FreeBSD__)
#define _WITH_GETLINE // To declare getline().
#endif

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>

0 comments on commit 86e0249

Please sign in to comment.