Fix #38: nginx crash on Suse12.

The newer version of libcrypto will invoke read and close function when
dl_init, the real address of read/close function can’t be determined in
compilation phase and libcrypto will seek read/close symbol in ELF
files and other libraries. However nginx_fstack redefined these two
functions, this causes these symbols to be found in nginx_fstack. But the real read/close function is NULL before ff_mod_init, this leads to crash.

Changes:
1.if real_close is NULL, assign it with the address of close function in Glibc.
2.remove unnecessary read/readv/write.
dev
logwang 2017-06-20 10:48:26 +08:00
parent 3132126c98
commit 10c5711ed2
1 changed files with 3 additions and 40 deletions

View File

@ -45,11 +45,7 @@ static int (*real_accept)(int, struct sockaddr *, socklen_t *);
static int (*real_accept4)(int, struct sockaddr *, socklen_t *, int);
static ssize_t (*real_recv)(int, void *, size_t, int);
static ssize_t (*real_send)(int, const void *, size_t, int);
static ssize_t (*real_writev)(int, const struct iovec *, int);
static ssize_t (*real_write)(int, const void *, size_t );
static ssize_t (*real_read)(int, void *, size_t );
static ssize_t (*real_readv)(int, const struct iovec *, int);
static int (*real_ioctl)(int, int, void *);
@ -74,9 +70,6 @@ ff_mod_init(int argc, char * const *argv) {
INIT_FUNCTION(recv);
INIT_FUNCTION(send);
INIT_FUNCTION(writev);
INIT_FUNCTION(write);
INIT_FUNCTION(read);
INIT_FUNCTION(readv);
INIT_FUNCTION(ioctl);
INIT_FUNCTION(select);
@ -139,17 +132,6 @@ send(int sockfd, const void *buf, size_t len, int flags)
}
}
ssize_t
write(int sockfd, const void *buf, size_t count)
{
if (CHK_FD_BIT(sockfd)) {
sockfd = CLR_FD_BIT(sockfd);
return ff_write(sockfd, buf, count);
} else {
return real_write(sockfd, buf, count);
}
}
ssize_t
recv(int sockfd, void *buf, size_t len, int flags)
{
@ -161,17 +143,6 @@ recv(int sockfd, void *buf, size_t len, int flags)
}
}
ssize_t
read(int sockfd, void *buf, size_t count)
{
if (CHK_FD_BIT(sockfd)) {
sockfd = CLR_FD_BIT(sockfd);
return ff_read(sockfd, buf, count);
} else {
return real_read(sockfd, buf, count);
}
}
int
listen(int sockfd, int backlog)
{
@ -229,6 +200,9 @@ close(int sockfd)
sockfd = CLR_FD_BIT(sockfd);
return ff_close(sockfd);
} else {
if (__builtin_expect(!!(real_close == NULL), 0)) {
real_close = dlsym(RTLD_NEXT, "close");
}
return real_close(sockfd);
}
}
@ -244,17 +218,6 @@ writev(int sockfd, const struct iovec *iov, int iovcnt)
}
}
ssize_t
readv(int sockfd, const struct iovec *iov, int iovcnt)
{
if (CHK_FD_BIT(sockfd)) {
sockfd = CLR_FD_BIT(sockfd);
return ff_readv(sockfd, iov, iovcnt);
} else {
return real_readv(sockfd, iov, iovcnt);
}
}
int
ioctl(int sockfd, int request, void *p)
{