Skip to content

Commit

Permalink
Fix undefined behavior in tcp.c
Browse files Browse the repository at this point in the history
  • Loading branch information
squeek502 committed Mar 1, 2024
1 parent eb89959 commit bb44a8c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,13 @@ static int luv_tcp_bind(lua_State* L) {
static void parse_sockaddr(lua_State* L, struct sockaddr_storage* address) {
char ip[INET6_ADDRSTRLEN];
int port = 0;
const struct sockaddr* addr = (const struct sockaddr*)address;
lua_newtable(L);
if (address->ss_family == AF_INET) {
if (addr->sa_family == AF_INET) {
struct sockaddr_in* addrin = (struct sockaddr_in*)address;
uv_inet_ntop(AF_INET, &(addrin->sin_addr), ip, INET6_ADDRSTRLEN);
port = ntohs(addrin->sin_port);
} else if (address->ss_family == AF_INET6) {
} else if (addr->sa_family == AF_INET6) {
struct sockaddr_in6* addrin6 = (struct sockaddr_in6*)address;
uv_inet_ntop(AF_INET6, &(addrin6->sin6_addr), ip, INET6_ADDRSTRLEN);
port = ntohs(addrin6->sin6_port);
Expand Down

0 comments on commit bb44a8c

Please sign in to comment.