Skip to content

Commit e286454

Browse files
Fix SelectInterruptPipe::read() being called with fd -1 (#573)
* Fix SelectInterruptPipe::read() being called with fd -1 * Fix build sometimes choosing mbedtls4 instead of mbedtls3
1 parent 66936b3 commit e286454

4 files changed

Lines changed: 13 additions & 11 deletions

File tree

.github/workflows/unittest_mac_tsan_mbedtls.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
steps:
1212
- uses: actions/checkout@v1
1313
- uses: seanmiddleditch/gha-setup-ninja@master
14-
- name: install mbedtls
14+
- name: install mbedtls@3
1515
run: brew install mbedtls@3
1616
- name: make test
1717
run: make -f makefile.dev test_tsan_mbedtls

ixwebsocket/IXSelectInterruptPipe.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ namespace ix
131131
return ret == 8;
132132
}
133133

134-
// TODO: return max uint64_t for errors ?
135134
uint64_t SelectInterruptPipe::read()
136135
{
137136
std::lock_guard<std::mutex> lock(_fildesMutex);
@@ -140,11 +139,11 @@ namespace ix
140139

141140
uint64_t value = 0;
142141

143-
ssize_t ret = -1;
142+
ssize_t readret = -1;
144143
do
145144
{
146-
ret = ::read(fd, &value, sizeof(value));
147-
} while (ret == -1 && errno == EINTR);
145+
readret = ::read(fd, &value, sizeof(value));
146+
} while (readret == -1 && errno == EINTR);
148147

149148
return value;
150149
}

ixwebsocket/IXSocketConnect.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include <linux/in.h>
2121
#include <linux/tcp.h>
2222
#endif
23-
#include <ixwebsocket/IXSelectInterruptFactory.h>
2423

2524
namespace ix
2625
{
@@ -67,8 +66,7 @@ namespace ix
6766

6867
int timeoutMs = 10;
6968
bool readyToRead = false;
70-
SelectInterruptPtr selectInterrupt = ix::createSelectInterrupt();
71-
PollResultType pollResult = Socket::poll(readyToRead, timeoutMs, fd, selectInterrupt);
69+
PollResultType pollResult = Socket::poll(readyToRead, timeoutMs, fd, nullptr);
7270

7371
if (pollResult == PollResultType::Timeout)
7472
{

makefile.dev

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ all: brew
1313

1414
install: brew
1515

16+
MBEDTLS_CMAKE_PREFIX :=
17+
ifeq ($(shell uname),Darwin)
18+
MBEDTLS_CMAKE_PREFIX := -DCMAKE_PREFIX_PATH=$$(brew --prefix mbedtls@3)
19+
endif
20+
1621
-DCMAKE_INSTALL_PREFIX=/opt/homebrew
1722

1823
# Use -DCMAKE_INSTALL_PREFIX= to install into another location
@@ -36,7 +41,7 @@ endif
3641
# server side ?) and I can't work-around it easily, so we're using mbedtls on
3742
# Linux for the SSL backend, which works great.
3843
ws_mbedtls_install:
39-
mkdir -p build && (cd build ; cmake -GNinja -DCMAKE_UNITY_BUILD=ON -DCMAKE_INSTALL_MESSAGE=LAZY -DCMAKE_BUILD_TYPE=MinSizeRel -DUSE_ZLIB=OFF -DUSE_TLS=1 -DUSE_WS=1 -DUSE_MBED_TLS=1 .. ; ninja install)
44+
mkdir -p build && (cd build ; cmake -GNinja -DCMAKE_UNITY_BUILD=ON -DCMAKE_INSTALL_MESSAGE=LAZY -DCMAKE_BUILD_TYPE=MinSizeRel -DUSE_ZLIB=OFF -DUSE_TLS=1 -DUSE_WS=1 -DUSE_MBED_TLS=1 $(MBEDTLS_CMAKE_PREFIX) .. ; ninja install)
4045

4146
ws:
4247
mkdir -p build && (cd build ; cmake -GNinja -DCMAKE_INSTALL_MESSAGE=LAZY -DCMAKE_BUILD_TYPE=Debug -DUSE_TLS=1 -DUSE_WS=1 .. && ninja)
@@ -54,7 +59,7 @@ ws_openssl_install:
5459
mkdir -p build && (cd build ; cmake -GNinja -DCMAKE_INSTALL_MESSAGE=LAZY -DCMAKE_BUILD_TYPE=Debug -DUSE_TLS=1 -DUSE_WS=1 -DUSE_OPEN_SSL=1 .. ; ninja install)
5560

5661
ws_mbedtls:
57-
mkdir -p build && (cd build ; cmake -DCMAKE_INSTALL_MESSAGE=LAZY -DCMAKE_BUILD_TYPE=Debug -DUSE_TLS=1 -DUSE_WS=1 -DUSE_MBED_TLS=1 .. ; ninja)
62+
mkdir -p build && (cd build ; cmake -DCMAKE_INSTALL_MESSAGE=LAZY -DCMAKE_BUILD_TYPE=Debug -DUSE_TLS=1 -DUSE_WS=1 -DUSE_MBED_TLS=1 $(MBEDTLS_CMAKE_PREFIX) .. ; ninja)
5863

5964
ws_no_ssl:
6065
mkdir -p build && (cd build ; cmake -DCMAKE_INSTALL_MESSAGE=LAZY -DCMAKE_BUILD_TYPE=Debug -DUSE_WS=1 .. ; ninja)
@@ -129,7 +134,7 @@ test_asan:
129134
(cd build ; ctest -V .)
130135

131136
test_tsan_mbedtls:
132-
mkdir -p build && (cd build ; cmake -GNinja -DCMAKE_INSTALL_MESSAGE=LAZY -DCMAKE_UNITY_BUILD=ON -DCMAKE_BUILD_TYPE=Debug -DUSE_TLS=1 -DUSE_MBED_TLS=1 -DUSE_TEST=1 .. -DCMAKE_C_FLAGS="-fsanitize=thread -fno-omit-frame-pointer" -DCMAKE_CXX_FLAGS="-fsanitize=thread -fno-omit-frame-pointer" -DCMAKE_PREFIX_PATH="$(shell brew --prefix mbedtls@3 2>/dev/null || echo /opt/homebrew/opt/mbedtls@3)")
137+
mkdir -p build && (cd build ; cmake -GNinja -DCMAKE_INSTALL_MESSAGE=LAZY -DCMAKE_UNITY_BUILD=ON -DCMAKE_BUILD_TYPE=Debug -DUSE_TLS=1 -DUSE_MBED_TLS=1 -DUSE_TEST=1 $(MBEDTLS_CMAKE_PREFIX) .. -DCMAKE_C_FLAGS="-fsanitize=thread -fno-omit-frame-pointer" -DCMAKE_CXX_FLAGS="-fsanitize=thread -fno-omit-frame-pointer")
133138
(cd build ; ninja)
134139
(cd build ; ninja test)
135140

0 commit comments

Comments
 (0)