Skip to content

Commit 1046294

Browse files
committedFeb 15, 2018
Add new interceptor: lstat(2)
Summary: lstat - get file status Use it on NetBSD. Sponsored by <The NetBSD Foundation> Reviewers: joerg, vitalybuka, eugenis Reviewed By: vitalybuka Subscribers: kubamracek, llvm-commits, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D42909 llvm-svn: 325199
1 parent ddde46a commit 1046294

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed
 

‎compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc

+18
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
#define localtime __locatime50
9393
#define localtime_r __localtime_r50
9494
#define mktime __mktime50
95+
#define lstat __lstat50
9596
#define opendir __opendir30
9697
#define readdir __readdir30
9798
#define readdir_r __readdir_r30
@@ -6277,6 +6278,22 @@ INTERCEPTOR(int, stat, const char *path, void *buf) {
62776278
#define INIT_STAT
62786279
#endif
62796280

6281+
#if SANITIZER_INTERCEPT_LSTAT
6282+
INTERCEPTOR(int, lstat, const char *path, void *buf) {
6283+
void *ctx;
6284+
COMMON_INTERCEPTOR_ENTER(ctx, lstat, path, buf);
6285+
if (common_flags()->intercept_stat)
6286+
COMMON_INTERCEPTOR_READ_STRING(ctx, path, 0);
6287+
int res = REAL(lstat)(path, buf);
6288+
if (!res)
6289+
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, __sanitizer::struct_stat_sz);
6290+
return res;
6291+
}
6292+
#define INIT_LSTAT COMMON_INTERCEPT_FUNCTION(lstat)
6293+
#else
6294+
#define INIT_LSTAT
6295+
#endif
6296+
62806297
#if SANITIZER_INTERCEPT___XSTAT
62816298
INTERCEPTOR(int, __xstat, int version, const char *path, void *buf) {
62826299
void *ctx;
@@ -6991,6 +7008,7 @@ static void InitializeCommonInterceptors() {
69917008
INIT_SEND_SENDTO;
69927009
INIT_STAT;
69937010
INIT_EVENTFD_READ_WRITE;
7011+
INIT_LSTAT;
69947012
INIT___XSTAT;
69957013
INIT___XSTAT64;
69967014
INIT___LXSTAT;

‎compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h

+1
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@
406406

407407
#define SANITIZER_INTERCEPT_STAT \
408408
(SI_FREEBSD || SI_MAC || SI_ANDROID || SI_NETBSD || SI_SOLARIS)
409+
#define SANITIZER_INTERCEPT_LSTAT SI_NETBSD
409410
#define SANITIZER_INTERCEPT___XSTAT (!SANITIZER_INTERCEPT_STAT && SI_POSIX)
410411
#define SANITIZER_INTERCEPT___XSTAT64 SI_LINUX_NOT_ANDROID
411412
#define SANITIZER_INTERCEPT___LXSTAT SANITIZER_INTERCEPT___XSTAT
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %clangxx -O0 -g %s -o %t && %run %t
2+
3+
#include <stdlib.h>
4+
#include <sys/stat.h>
5+
6+
int main(void) {
7+
struct stat st;
8+
9+
if (lstat("/dev/null", &st))
10+
exit(1);
11+
12+
if (!S_ISCHR(st.st_mode))
13+
exit(1);
14+
15+
return 0;
16+
}

0 commit comments

Comments
 (0)
Please sign in to comment.