Skip to content

Commit 48a2d51

Browse files
aidangarskedanielinux
authored andcommitted
Fix rest of CI
1 parent c410a1c commit 48a2d51

3 files changed

Lines changed: 30 additions & 20 deletions

File tree

src/port/posix/bsd_socket.c

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -298,12 +298,14 @@ static int wolfip_fd_alloc(int internal_fd, int nonblock)
298298
host_fcntl(pipefds[0], F_SETFL, O_NONBLOCK);
299299
host_fcntl(pipefds[1], F_SETFL, O_NONBLOCK);
300300
} else {
301-
if (fcntl(pipefds[0], F_SETFD, FD_CLOEXEC) < 0 ||
302-
fcntl(pipefds[1], F_SETFD, FD_CLOEXEC) < 0 ||
303-
fcntl(pipefds[0], F_SETFL, O_NONBLOCK) < 0 ||
304-
fcntl(pipefds[1], F_SETFL, O_NONBLOCK) < 0) {
305-
/* Use host_close to avoid deadlock: close() is interposed and
306-
* wolfip_fd_alloc may be called with wolfIP_mutex held. */
301+
/* Resolve the real libc fcntl via dlsym to avoid recursing into our
302+
* interposed fcntl(), which would deadlock on wolfIP_mutex. */
303+
int (*real_fcntl)(int, int, ...) = (int (*)(int, int, ...))dlsym(RTLD_NEXT, "fcntl");
304+
if (!real_fcntl ||
305+
real_fcntl(pipefds[0], F_SETFD, FD_CLOEXEC) < 0 ||
306+
real_fcntl(pipefds[1], F_SETFD, FD_CLOEXEC) < 0 ||
307+
real_fcntl(pipefds[0], F_SETFL, O_NONBLOCK) < 0 ||
308+
real_fcntl(pipefds[1], F_SETFL, O_NONBLOCK) < 0) {
307309
if (host_close) {
308310
host_close(pipefds[0]);
309311
host_close(pipefds[1]);
@@ -1649,15 +1651,18 @@ void *wolfIP_sock_posix_ip_loop(void *arg) {
16491651

16501652
static int wolfip_validate_ipv4(const char *s)
16511653
{
1652-
int parts = 0, digits = 0, val = 0;
1654+
int parts = 0, digits = 0;
1655+
unsigned int val = 0;
16531656
if (!s || !*s)
16541657
return 0;
16551658
while (*s) {
16561659
if (*s >= '0' && *s <= '9') {
1657-
val = val * 10 + (*s - '0');
1660+
digits++;
1661+
if (digits > 3)
1662+
return 0;
1663+
val = val * 10 + (unsigned int)(*s - '0');
16581664
if (val > 255)
16591665
return 0;
1660-
digits++;
16611666
} else if (*s == '.') {
16621667
if (digits == 0)
16631668
return 0;
@@ -1764,13 +1769,15 @@ void __attribute__((constructor)) init_wolfip_posix() {
17641769
}
17651770
wolfIP_start_tcpdump((tapdev && tapdev->ifname[0]) ? tapdev->ifname : "wtcp0");
17661771
#endif
1767-
if (wolfip_validate_ipv4(wolfip_ip_str) && wolfip_validate_ipv4(wolfip_mask_str) &&
1768-
wolfip_validate_ipv4(host_stack_ip_str)) {
1769-
wolfIP_ipconfig_set(IPSTACK, atoip4(wolfip_ip_str), atoip4(wolfip_mask_str),
1770-
atoip4(host_stack_ip_str));
1771-
} else {
1772-
fprintf(stderr, "Invalid IP configuration, using defaults\n");
1772+
if (!wolfip_validate_ipv4(wolfip_ip_str) || !wolfip_validate_ipv4(wolfip_mask_str) ||
1773+
!wolfip_validate_ipv4(host_stack_ip_str)) {
1774+
fprintf(stderr, "Invalid IP configuration, falling back to defaults\n");
1775+
wolfip_ip_str = WOLFIP_IP;
1776+
wolfip_mask_str = "255.255.255.0";
1777+
host_stack_ip_str = HOST_STACK_IP;
17731778
}
1779+
wolfIP_ipconfig_set(IPSTACK, atoip4(wolfip_ip_str), atoip4(wolfip_mask_str),
1780+
atoip4(host_stack_ip_str));
17741781
pthread_mutex_unlock(&wolfIP_mutex);
17751782
fprintf(stderr, "IP: manually configured - %s\n", wolfip_ip_str);
17761783
/* Avoid penalizing startup fairness across stacks: once init is done,

src/test/test_ttl_expired.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,14 @@ uint32_t wolfIP_getrandom(void)
116116
{
117117
uint32_t ret;
118118
#ifdef __linux__
119-
if (getrandom(&ret, sizeof(ret), 0) >= 0)
120-
return ret;
119+
{
120+
ssize_t n;
121+
do {
122+
n = getrandom(&ret, sizeof(ret), 0);
123+
} while (n < 0 && errno == EINTR);
124+
if (n == (ssize_t)sizeof(ret))
125+
return ret;
126+
}
121127
#endif
122128
ret = (uint32_t)rand();
123129
return ret;

src/wolfip.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,9 +1807,6 @@ static struct tsocket *tcp_new_socket(struct wolfIP *s)
18071807
{
18081808
uint32_t space = RXBUF_SIZE;
18091809
uint8_t shift = 0;
1810-
/* Note: with the default RXBUF_SIZE (20480), space fits in a
1811-
* uint16_t so the loop body never executes and shift stays 0.
1812-
* Kept for configurations that define a larger RXBUF_SIZE. */
18131810
while (shift < 14 && (space >> shift) > 0xFFFF)
18141811
shift++;
18151812
t->sock.tcp.rcv_wscale = shift;

0 commit comments

Comments
 (0)