Skip to content

Commit ca286ba

Browse files
committed
socket-util: Correctly return negative values for errors.
The comment on this function says that negative values indicate errors, and the callers assume that too, but in fact it was returning positive errno values, which are indistinguishable from valid fd numbers. It really seems to me that this should have been found pretty quickly in the field, since stream-tcp and stream-ssl both use inet_open_passive to implement their passive listeners. I'm surprised that no one has reported it.
1 parent 799d2bf commit ca286ba

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

lib/socket-util.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -673,15 +673,15 @@ inet_open_passive(int style, const char *target, int default_port,
673673
unsigned int yes = 1;
674674

675675
if (!inet_parse_passive(target, default_port, &sin)) {
676-
return EAFNOSUPPORT;
676+
return -EAFNOSUPPORT;
677677
}
678678

679679
/* Create non-blocking socket, set SO_REUSEADDR. */
680680
fd = socket(AF_INET, style, 0);
681681
if (fd < 0) {
682682
error = errno;
683683
VLOG_ERR("%s: socket: %s", target, strerror(error));
684-
return error;
684+
return -error;
685685
}
686686
error = set_nonblocking(fd);
687687
if (error) {
@@ -716,6 +716,7 @@ inet_open_passive(int style, const char *target, int default_port,
716716
goto error;
717717
}
718718
if (sin.sin_family != AF_INET || sin_len != sizeof sin) {
719+
error = EAFNOSUPPORT;
719720
VLOG_ERR("%s: getsockname: invalid socket name", target);
720721
goto error;
721722
}
@@ -726,7 +727,7 @@ inet_open_passive(int style, const char *target, int default_port,
726727

727728
error:
728729
close(fd);
729-
return error;
730+
return -error;
730731
}
731732

732733
/* Returns a readable and writable fd for /dev/null, if successful, otherwise

0 commit comments

Comments
 (0)