Merge pull request #214 from chadwill/master

Nginx: fixbug, hijack `getpeername` and `getsockname`.
This commit is contained in:
logwang 2018-05-28 12:03:07 +08:00 committed by GitHub
commit e850874db3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 32 additions and 3 deletions

View File

@ -121,6 +121,9 @@ static int (*real_ioctl)(int, int, void *);
static int (*real_gettimeofday)(struct timeval *tv, struct timezone *tz); static int (*real_gettimeofday)(struct timeval *tv, struct timezone *tz);
static int (*real_getpeername)(int sockfd, struct sockaddr * name, socklen_t *namelen);
static int (*real_getsockname)(int s, struct sockaddr *name, socklen_t *namelen);
static __thread int inited; static __thread int inited;
#define SYSCALL(func) \ #define SYSCALL(func) \
@ -269,6 +272,32 @@ connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
return SYSCALL(connect)(sockfd, addr, addrlen); return SYSCALL(connect)(sockfd, addr, addrlen);
} }
int
getpeername(int sockfd, struct sockaddr * name,
socklen_t *namelen)
{
if(is_fstack_fd(sockfd)){
sockfd = restore_fstack_fd(sockfd);
return ff_getpeername(sockfd,
(struct linux_sockaddr *)name, namelen);
}
return SYSCALL(getpeername)(sockfd, name, namelen);
}
int
getsockname(int sockfd, struct sockaddr *name,
socklen_t *namelen)
{
if(is_fstack_fd(sockfd)){
sockfd = restore_fstack_fd(sockfd);
return ff_getsockname(sockfd,
(struct linux_sockaddr *)name, namelen);
}
return SYSCALL(getsockname)(sockfd, name, namelen);
}
ssize_t ssize_t
send(int sockfd, const void *buf, size_t len, int flags) send(int sockfd, const void *buf, size_t len, int flags)
{ {