mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-09 00:00:04 +01:00
LWS_ERRNO: audit uses for case logging may destroy errno
On some platforms, it's possible that logging flow may reset errno. In the case where we try to log errno on those platforms and afterwards try to query it, we will get a nasty surprise that the logged errno is destroyed by the time we come to test it. In the two cases of this in the tree at the moment, sample errno into a temp and log and test the temp. Thanks to Sakthi Ramabadran for finding this.
This commit is contained in:
parent
fb54b590c7
commit
392dfe186b
2 changed files with 11 additions and 7 deletions
|
@ -297,12 +297,14 @@ lws_socket_bind(struct lws_vhost *vhost, lws_sockfd_type sockfd, int port,
|
|||
} else
|
||||
#endif
|
||||
if (n < 0) {
|
||||
int _lws_errno = LWS_ERRNO;
|
||||
|
||||
lwsl_err("ERROR on binding fd %d to port %d (%d %d)\n",
|
||||
sockfd, port, n, LWS_ERRNO);
|
||||
sockfd, port, n, _lws_errno);
|
||||
|
||||
/* if something already listening, tell caller to fail permanently */
|
||||
|
||||
if (LWS_ERRNO == LWS_EADDRINUSE)
|
||||
if (_lws_errno == LWS_EADDRINUSE)
|
||||
return LWS_ITOSA_BUSY;
|
||||
|
||||
/* otherwise ask caller to retry later */
|
||||
|
|
|
@ -582,13 +582,15 @@ ads_known:
|
|||
|
||||
m = connect(wsi->desc.sockfd, (const struct sockaddr *)psa, n);
|
||||
if (m == -1) {
|
||||
lwsl_debug("%s: connect says errno: %d\n", __func__, LWS_ERRNO);
|
||||
int errno_copy = LWS_ERRNO;
|
||||
|
||||
if (LWS_ERRNO != LWS_EALREADY &&
|
||||
LWS_ERRNO != LWS_EINPROGRESS &&
|
||||
LWS_ERRNO != LWS_EWOULDBLOCK
|
||||
lwsl_debug("%s: connect says errno: %d\n", __func__, errno_copy);
|
||||
|
||||
if (errno_copy != LWS_EALREADY &&
|
||||
errno_copy != LWS_EINPROGRESS &&
|
||||
errno_copy != LWS_EWOULDBLOCK
|
||||
#ifdef _WIN32
|
||||
&& LWS_ERRNO != WSAEINVAL
|
||||
&& errno_copy != WSAEINVAL
|
||||
#endif
|
||||
) {
|
||||
#if defined(_DEBUG)
|
||||
|
|
Loading…
Add table
Reference in a new issue