[msan] Intercept getsockname.

llvm-svn: 182475
This commit is contained in:
Evgeniy Stepanov 2013-05-22 13:46:22 +00:00
parent 14a4449589
commit 97aea34b54
5 changed files with 43 additions and 1 deletions

View File

@ -629,6 +629,28 @@ TEST(MemorySanitizer, socketpair) {
close(sv[1]);
}
TEST(MemorySanitizer, bind_getsockname) {
int sock = socket(AF_UNIX, SOCK_STREAM, 0);
struct sockaddr_in sai;
memset(&sai, 0, sizeof(sai));
sai.sin_family = AF_UNIX;
int res = bind(sock, (struct sockaddr *)&sai, sizeof(sai));
assert(!res);
char buf[200];
socklen_t addrlen;
EXPECT_UMR(getsockname(sock, (struct sockaddr *)&buf, &addrlen));
addrlen = sizeof(buf);
res = getsockname(sock, (struct sockaddr *)&buf, &addrlen);
EXPECT_NOT_POISONED(addrlen);
EXPECT_NOT_POISONED(buf[0]);
EXPECT_NOT_POISONED(buf[addrlen - 1]);
EXPECT_POISONED(buf[addrlen]);
close(sock);
}
TEST(MemorySanitizer, getcwd) {
char path[PATH_MAX + 1];
char* res = getcwd(path, sizeof(path));

View File

@ -779,6 +779,22 @@ INTERCEPTOR(int, getaddrinfo, char *node, char *service,
#define INIT_GETADDRINFO
#endif
#if SANITIZER_INTERCEPT_GETSOCKNAME
INTERCEPTOR(int, getsockname, int sock_fd, void *addr, int *addrlen) {
void *ctx;
COMMON_INTERCEPTOR_ENTER(ctx, getsockname, sock_fd, addr, addrlen);
COMMON_INTERCEPTOR_READ_RANGE(ctx, addrlen, sizeof(*addrlen));
int addrlen_in = *addrlen;
int res = REAL(getsockname)(sock_fd, addr, addrlen);
if (res == 0) {
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, addr, Min(addrlen_in, *addrlen));
}
return res;
}
#define INIT_GETSOCKNAME INTERCEPT_FUNCTION(getsockname);
#else
#define INIT_GETSOCKNAME
#endif
#define SANITIZER_COMMON_INTERCEPTORS_INIT \
INIT_STRCASECMP; \
@ -803,4 +819,5 @@ INTERCEPTOR(int, getaddrinfo, char *node, char *service,
INIT_WAIT; \
INIT_INET; \
INIT_PTHREAD_GETSCHEDPARAM; \
INIT_GETADDRINFO;
INIT_GETADDRINFO; \
INIT_GETSOCKNAME;

View File

@ -71,5 +71,6 @@
# define SANITIZER_INTERCEPT_INET SI_NOT_WINDOWS
# define SANITIZER_INTERCEPT_PTHREAD_GETSCHEDPARAM SI_NOT_WINDOWS
# define SANITIZER_INTERCEPT_GETADDRINFO SI_NOT_WINDOWS
# define SANITIZER_INTERCEPT_GETSOCKNAME SI_NOT_WINDOWS
#endif // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H

View File

@ -312,6 +312,7 @@ void StatOutput(u64 *stat) {
name[StatInt_inet_ntop] = " inet_ntop ";
name[StatInt_inet_pton] = " inet_pton ";
name[StatInt_getaddrinfo] = " getaddrinfo ";
name[StatInt_getsockname] = " getsockname ";
name[StatAnnotation] = "Dynamic annotations ";
name[StatAnnotateHappensBefore] = " HappensBefore ";

View File

@ -307,6 +307,7 @@ enum StatType {
StatInt_inet_ntop,
StatInt_inet_pton,
StatInt_getaddrinfo,
StatInt_getsockname,
// Dynamic annotations.
StatAnnotation,