Skip to content

Commit 26dc8a5

Browse files
authored
Check if ai_list is null before freeing it (#831)
Passing null to freeaddrinfo is undefined behaviour. While glibc and uClibc both handle it safely, musl does not, so a bad nodename or servname causes a segfault. This change ensures that the ai_list is non-null before trying to free it. In musl and glibc this condition will never be met, but there are some paths for it to be met in uClibc.
1 parent b2b37ef commit 26dc8a5

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/modbus-tcp.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,9 @@ int modbus_tcp_pi_listen(modbus_t *ctx, int nb_connection)
693693
fprintf(stderr, "Error returned by getaddrinfo: %d\n", rc);
694694
#endif
695695
}
696-
freeaddrinfo(ai_list);
696+
if (ai_list != NULL) {
697+
freeaddrinfo(ai_list);
698+
}
697699
errno = ECONNREFUSED;
698700
return -1;
699701
}

0 commit comments

Comments
 (0)