Skip to content

Commit

Permalink
- Linux socket: Fix uninitialized variable use in Socket_connect() (m…
Browse files Browse the repository at this point in the history
…z-automation#57)

getsockopt() may return -1, set ERRNO = EINPROGRESS (115: Operation now in progress)
and not initialze so_error on Kubuntu 19.10 AMD64 with kernel 5.3.0-23-generic

So, initialize the value to -1, and add check for getsockopt() result
(and add log message if DEBUG_SOCKET is set).

Fixes mz-automation#57
  • Loading branch information
S-trace committed Nov 18, 2019
1 parent 21cfbd6 commit 7431c6a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib60870-C/src/hal/socket/linux/socket_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,17 @@ Socket_connect(Socket self, const char* address, int port)
timeout.tv_usec = (self->connectTimeout % 1000) * 1000;

if (select(self->fd + 1, NULL, &fdSet , NULL, &timeout) == 1) {
int so_error;
int so_error = -1;
socklen_t len = sizeof so_error;

getsockopt(self->fd, SOL_SOCKET, SO_ERROR, &so_error, &len);
if (!getsockopt(self->fd, SOL_SOCKET, SO_ERROR, &so_error, &len) && DEBUG_SOCKET) {

char errno_message[256];

strerror_r(errno, errno_message, sizeof(errno_message));

fprintf(stderr, "%s: getsockopt failed for socket fd %d: %d (%s)\n", __func__, self->fd, errno, errno_message);
}

if (so_error == 0)
return true;
Expand Down

0 comments on commit 7431c6a

Please sign in to comment.