Switch from using sockaddr to sockaddr_storage.

This is to ensure sufficient space is always available.

Change-Id: Ifa87b93ecdc90dcacbfb24446c872344da6703d3
This commit is contained in:
Erik Kline 2015-12-01 17:27:59 +09:00
parent 1462c78c9c
commit 7e16cc15b5
7 changed files with 39 additions and 32 deletions

View file

@ -228,13 +228,13 @@ void adb_auth_confirm_key(unsigned char *key, size_t len, atransport *t)
static void adb_auth_listener(int fd, unsigned events, void *data)
{
struct sockaddr addr;
sockaddr_storage addr;
socklen_t alen;
int s;
alen = sizeof(addr);
s = adb_socket_accept(fd, &addr, &alen);
s = adb_socket_accept(fd, reinterpret_cast<sockaddr*>(&addr), &alen);
if (s < 0) {
D("Failed to accept: errno=%d", errno);
return;

View file

@ -34,9 +34,10 @@ static alistener listener_list = {
static void ss_listener_event_func(int _fd, unsigned ev, void *_l) {
if (ev & FDE_READ) {
struct sockaddr addr;
socklen_t alen = sizeof(addr);
int fd = adb_socket_accept(_fd, &addr, &alen);
sockaddr_storage ss;
sockaddr* addrp = reinterpret_cast<sockaddr*>(&ss);
socklen_t alen = sizeof(ss);
int fd = adb_socket_accept(_fd, addrp, &alen);
if (fd < 0) return;
int rcv_buf_size = CHUNK_SIZE;
@ -58,12 +59,13 @@ static void listener_event_func(int _fd, unsigned ev, void* _l)
asocket *s;
if (ev & FDE_READ) {
struct sockaddr addr;
sockaddr_storage ss;
sockaddr* addrp = reinterpret_cast<sockaddr*>(&ss);
socklen_t alen;
int fd;
alen = sizeof(addr);
fd = adb_socket_accept(_fd, &addr, &alen);
alen = sizeof(ss);
fd = adb_socket_accept(_fd, addrp, &alen);
if (fd < 0) {
return;
}
@ -79,7 +81,7 @@ static void listener_event_func(int _fd, unsigned ev, void* _l)
}
}
static void free_listener(alistener* l)
static void free_listener(alistener* l)
{
if (l->next) {
l->next->prev = l->prev;

View file

@ -460,11 +460,11 @@ jdwp_control_init( JdwpControl* control,
const char* sockname,
int socknamelen )
{
struct sockaddr_un addr;
socklen_t addrlen;
int s;
int maxpath = sizeof(addr.sun_path);
int pathlen = socknamelen;
sockaddr_un addr;
socklen_t addrlen;
int s;
int maxpath = sizeof(addr.sun_path);
int pathlen = socknamelen;
if (pathlen >= maxpath) {
D( "vm debug control socket name too long (%d extra chars)",
@ -485,7 +485,7 @@ jdwp_control_init( JdwpControl* control,
addrlen = (pathlen + sizeof(addr.sun_family));
if (bind(s, (struct sockaddr*)&addr, addrlen) < 0) {
if (bind(s, reinterpret_cast<sockaddr*>(&addr), addrlen) < 0) {
D( "could not bind vm debug control socket: %d: %s",
errno, strerror(errno) );
adb_close(s);
@ -523,13 +523,14 @@ jdwp_control_event( int s, unsigned events, void* _control )
JdwpControl* control = (JdwpControl*) _control;
if (events & FDE_READ) {
struct sockaddr addr;
socklen_t addrlen = sizeof(addr);
int s = -1;
JdwpProcess* proc;
sockaddr_storage ss;
sockaddr* addrp = reinterpret_cast<sockaddr*>(&ss);
socklen_t addrlen = sizeof(ss);
int s = -1;
JdwpProcess* proc;
do {
s = adb_socket_accept( control->listen_socket, &addr, &addrlen );
s = adb_socket_accept(control->listen_socket, addrp, &addrlen);
if (s < 0) {
if (errno == EINTR)
continue;

View file

@ -143,7 +143,8 @@ static void *client_socket_thread(void *x)
static void *server_socket_thread(void * arg)
{
int serverfd, fd;
struct sockaddr addr;
sockaddr_storage ss;
sockaddr *addrp = reinterpret_cast<sockaddr*>(&ss);
socklen_t alen;
int port = (int) (uintptr_t) arg;
@ -162,9 +163,9 @@ static void *server_socket_thread(void * arg)
close_on_exec(serverfd);
}
alen = sizeof(addr);
alen = sizeof(ss);
D("server: trying to get new connection from %d", port);
fd = adb_socket_accept(serverfd, &addr, &alen);
fd = adb_socket_accept(serverfd, addrp, &alen);
if(fd >= 0) {
D("server: new connection on fd %d", fd);
close_on_exec(fd);

View file

@ -518,11 +518,12 @@ static int do_server() {
ALOGI("debuggerd: starting\n");
for (;;) {
sockaddr addr;
socklen_t alen = sizeof(addr);
sockaddr_storage ss;
sockaddr* addrp = reinterpret_cast<sockaddr*>(&ss);
socklen_t alen = sizeof(ss);
ALOGV("waiting for connection\n");
int fd = accept(s, &addr, &alen);
int fd = accept(s, addrp, &alen);
if (fd < 0) {
ALOGV("accept failed: %s\n", strerror(errno));
continue;

View file

@ -199,13 +199,14 @@ void SocketListener::runListener() {
continue;
}
if (mListen && FD_ISSET(mSock, &read_fds)) {
struct sockaddr addr;
sockaddr_storage ss;
sockaddr* addrp = reinterpret_cast<sockaddr*>(&ss);
socklen_t alen;
int c;
do {
alen = sizeof(addr);
c = accept(mSock, &addr, &alen);
alen = sizeof(ss);
c = accept(mSock, addrp, &alen);
SLOGV("%s got %d from accept", mSocketName, c);
} while (c < 0 && errno == EINTR);
if (c < 0) {

View file

@ -410,7 +410,8 @@ static void ctrl_data_handler(uint32_t events) {
}
static void ctrl_connect_handler(uint32_t events __unused) {
struct sockaddr addr;
struct sockaddr_storage ss;
struct sockaddr *addrp = (struct sockaddr *)&ss;
socklen_t alen;
struct epoll_event epev;
@ -419,8 +420,8 @@ static void ctrl_connect_handler(uint32_t events __unused) {
ctrl_dfd_reopened = 1;
}
alen = sizeof(addr);
ctrl_dfd = accept(ctrl_lfd, &addr, &alen);
alen = sizeof(ss);
ctrl_dfd = accept(ctrl_lfd, addrp, &alen);
if (ctrl_dfd < 0) {
ALOGE("lmkd control socket accept failed; errno=%d", errno);