Hello! In these places, the value returned by the mach_port_allocate function was not checked.
Thanks, -- Mikhail Karpov
From d93c5449c7ca8d72e9815d55a090b918f7fe14fc Mon Sep 17 00:00:00 2001 From: Mikhail Karpov <[email protected]> Date: Tue, 20 Oct 2026 22:06:27 +0700 Subject: [PATCH 2/2] Added checks for mach_port_allocate return value in several place --- libnetfs/init-init.c | 6 ++++-- lwip/main.c | 6 ++++-- pfinet/main.c | 6 ++++-- pflocal/io.c | 12 ++++++++++-- term/users.c | 13 ++++++++++--- trans/bogus-fifo.c | 6 +++++- trans/symlink.c | 6 +++++- 7 files changed, 42 insertions(+), 13 deletions(-) diff --git a/libnetfs/init-init.c b/libnetfs/init-init.c index f64c7bb..1b06260 100644 --- a/libnetfs/init-init.c +++ b/libnetfs/init-init.c @@ -48,6 +48,8 @@ netfs_init (void) netfs_control_class = ports_create_class (0, 0); netfs_port_bucket = ports_create_bucket (); netfs_auth_server_port = getauth (); - mach_port_allocate (mach_task_self (), MACH_PORT_RIGHT_RECEIVE, - &netfs_fsys_identity); + err = mach_port_allocate (mach_task_self (), MACH_PORT_RIGHT_RECEIVE, + &netfs_fsys_identity); + if (err) + error (2, err, "mach_port_allocate"); } diff --git a/lwip/main.c b/lwip/main.c index 0d92589..f52f80f 100644 --- a/lwip/main.c +++ b/lwip/main.c @@ -205,8 +205,10 @@ main (int argc, char **argv) socketport_class = ports_create_class (clean_socketport, 0); lwip_bootstrap_portclass = PORTCLASS_INET; - mach_port_allocate (mach_task_self (), - MACH_PORT_RIGHT_RECEIVE, &fsys_identity); + err = mach_port_allocate (mach_task_self (), + MACH_PORT_RIGHT_RECEIVE, &fsys_identity); + if (err) + error (1, err, "mach_port_allocate"); /* Init the device modules */ hurdethif_module_init (); diff --git a/pfinet/main.c b/pfinet/main.c index cd50950..5d9a112 100644 --- a/pfinet/main.c +++ b/pfinet/main.c @@ -296,8 +296,10 @@ main (int argc, pfinet_bucket = ports_create_bucket (); addrport_class = ports_create_class (clean_addrport, 0); socketport_class = ports_create_class (clean_socketport, 0); - mach_port_allocate (mach_task_self (), MACH_PORT_RIGHT_RECEIVE, - &fsys_identity); + err = mach_port_allocate (mach_task_self (), MACH_PORT_RIGHT_RECEIVE, + &fsys_identity); + if (err) + error (1, err, "mach_port_allocate"); /* Generic initialization */ diff --git a/pflocal/io.c b/pflocal/io.c index 6a85870..991917c 100644 --- a/pflocal/io.c +++ b/pflocal/io.c @@ -335,8 +335,16 @@ S_io_stat (struct sock_user *user, struct stat *st) pthread_mutex_lock (&sock->lock); /* Make sure the pipes don't go away... */ if (sock->id == MACH_PORT_NULL) - mach_port_allocate (mach_task_self (), MACH_PORT_RIGHT_RECEIVE, - &sock->id); + { + error_t err = mach_port_allocate (mach_task_self (), + MACH_PORT_RIGHT_RECEIVE, &sock->id); + if (err) + { + pthread_mutex_unlock (&sock->lock); + return err; + } + } + st->st_ino = sock->id; rpipe = sock->read_pipe; diff --git a/term/users.c b/term/users.c index 2b6db3b..445196a 100644 --- a/term/users.c +++ b/term/users.c @@ -95,14 +95,21 @@ init_users (void) if (err) error (1, err, "Allocating cttyid"); - mach_port_allocate (mach_task_self (), MACH_PORT_RIGHT_RECEIVE, - &async_icky_id); + err = mach_port_allocate (mach_task_self (), MACH_PORT_RIGHT_RECEIVE, + &async_icky_id); + if (err) + error (1, err, "mach_port_allocate"); + /* Add a send right, since hurd_sig_post needs one. */ mach_port_insert_right (mach_task_self (), async_icky_id, async_icky_id, MACH_MSG_TYPE_MAKE_SEND); - mach_port_allocate (mach_task_self (), MACH_PORT_RIGHT_RECEIVE, &async_id); + err = mach_port_allocate (mach_task_self (), MACH_PORT_RIGHT_RECEIVE, + &async_id); + if (err) + error (1, err, "mach_port_allocate"); + /* Add a send right, since hurd_sig_post needs one. */ mach_port_insert_right (mach_task_self (), async_id, async_id, MACH_MSG_TYPE_MAKE_SEND); diff --git a/trans/bogus-fifo.c b/trans/bogus-fifo.c index 3e1dd9e..86610c0 100644 --- a/trans/bogus-fifo.c +++ b/trans/bogus-fifo.c @@ -53,7 +53,11 @@ main (int argc, char **argv) error(3, 0, "Must be started as a translator"); /* Reply to our parent */ - mach_port_allocate (mach_task_self (), MACH_PORT_RIGHT_RECEIVE, &fsys); + err = mach_port_allocate (mach_task_self (), MACH_PORT_RIGHT_RECEIVE, + &fsys); + if (err) + error (1, err, "mach_port_allocate"); + err = fsys_startup (bootstrap, fsys, MACH_MSG_TYPE_MAKE_SEND, &realnode); mach_port_deallocate (mach_task_self (), bootstrap); if (err) diff --git a/trans/symlink.c b/trans/symlink.c index 0046378..05612db 100644 --- a/trans/symlink.c +++ b/trans/symlink.c @@ -85,7 +85,11 @@ main (int argc, char **argv) linktarget = argv[1]; /* Reply to our parent */ - mach_port_allocate (mach_task_self (), MACH_PORT_RIGHT_RECEIVE, &control); + err = mach_port_allocate (mach_task_self (), MACH_PORT_RIGHT_RECEIVE, + &control); + if (err) + error (1, err, "mach_port_allocate"); + mach_port_insert_right (mach_task_self (), control, control, MACH_MSG_TYPE_MAKE_SEND); err = -- 2.43.0
