From b747eb399c556858e05de51b1bb3e875c834c8e0 Mon Sep 17 00:00:00 2001 From: Anton Kling Date: Fri, 28 Jun 2024 17:56:53 +0200 Subject: Bug fix: Fix undefined behavior of ipv4_t type. Turns out unions that include arrays and a integer can have UB due to endianess not being the same across systems. --- kernel/socket.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'kernel/socket.c') diff --git a/kernel/socket.c b/kernel/socket.c index d4e86a9..689e2ac 100644 --- a/kernel/socket.c +++ b/kernel/socket.c @@ -26,10 +26,7 @@ void global_socket_init(void) { OPEN_UNIX_SOCKET *un_sockets[100] = {0}; void gen_ipv4(ipv4_t *ip, u8 i1, u8 i2, u8 i3, u8 i4) { - ip->a[0] = i1; - ip->a[1] = i2; - ip->a[2] = i3; - ip->a[3] = i4; + ip->d = (i1 << (8 * 0)) | (i2 << (8 * 1)) | (i3 << (8 * 2)) | (i4 << (8 * 3)); } void tcp_remove_connection(struct TcpConnection *con) { -- cgit v1.2.3