From a9e742489ae4db42352796e985abcaf57edb745e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20T=C3=B6rnblom?= Date: Sun, 2 Aug 2026 16:08:19 +0200 Subject: [PATCH] crt: fix potential bug in designated initializers with union members --- crt/kernel.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/crt/kernel.c b/crt/kernel.c index 1a6a0ca..0979fee 100644 --- a/crt/kernel.c +++ b/crt/kernel.c @@ -502,9 +502,7 @@ __kernel_init(payload_args_t* args) { **/ static int kernel_write(unsigned long kaddr, void* data, unsigned long len) { - kernel_pipebuf_t buf = { - .vbuf.kaddr = kaddr - }; + kernel_pipebuf_t buf = {0}; // sanity check for invalid kernel pointers if(!(kaddr & 0xffff000000000000)) { @@ -512,6 +510,8 @@ kernel_write(unsigned long kaddr, void* data, unsigned long len) { return -1; } + buf.vbuf.kaddr = kaddr; + if(__crt_syscall(SYS_setsockopt, MASTER_SOCK, IPPROTO_IPV6, IPV6_PKTINFO, &buf, sizeof(buf))) { return -1; @@ -528,15 +528,15 @@ kernel_write(unsigned long kaddr, void* data, unsigned long len) { int kernel_copyin(const void *uaddr, unsigned long kaddr, unsigned long len) { - kernel_pipebuf_t buf = { - .flags.reserved = 0x40000000 - }; + kernel_pipebuf_t buf = {0}; if(!kaddr || !uaddr || !len) { SET_ERRNO(EINVAL); return -1; } + buf.flags.reserved = 0x40000000; + if(kernel_write(pipe_addr, &buf, sizeof(buf))) { return -1; } @@ -559,16 +559,16 @@ kernel_copyin(const void *uaddr, unsigned long kaddr, unsigned long len) { int kernel_copyout(unsigned long kaddr, void *uaddr, unsigned long len) { - kernel_pipebuf_t buf = { - .flags.cnt = 0x40000000, - .flags.in = 0x40000000, - }; + kernel_pipebuf_t buf = {0}; if(!kaddr || !uaddr || !len) { SET_ERRNO(EINVAL); return -1; } + buf.flags.cnt = 0x40000000; + buf.flags.in = 0x40000000; + if(kernel_write(pipe_addr, &buf, sizeof(buf))) { return -1; }