From a54820ff0e1b74554c7f649e8386ee8c4ecd98f5 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Thu, 14 Sep 2023 01:29:55 -0700 Subject: [PATCH] fixes #1675 undefined behavior in posix ipc_dialer_dial (This also affects TCP, and fixed there.) --- src/platform/posix/posix_ipcdial.c | 4 +++- src/platform/posix/posix_tcpdial.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/platform/posix/posix_ipcdial.c b/src/platform/posix/posix_ipcdial.c index 464179a01..6cbd7c175 100644 --- a/src/platform/posix/posix_ipcdial.c +++ b/src/platform/posix/posix_ipcdial.c @@ -1,5 +1,5 @@ // -// Copyright 2020 Staysail Systems, Inc. +// Copyright 2023 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // Copyright 2019 Devolutions // @@ -188,6 +188,8 @@ ipc_dialer_dial(void *arg, nni_aio *aio) // This arranges for the fd to be in non-blocking mode, and adds the // poll fd to the list. if ((rv = nni_posix_pfd_init(&pfd, fd)) != 0) { + // the error label unlocks this + nni_mtx_lock(&d->mtx); goto error; } diff --git a/src/platform/posix/posix_tcpdial.c b/src/platform/posix/posix_tcpdial.c index d9b58210b..0af72cfa7 100644 --- a/src/platform/posix/posix_tcpdial.c +++ b/src/platform/posix/posix_tcpdial.c @@ -1,5 +1,5 @@ // -// Copyright 2021 Staysail Systems, Inc. +// Copyright 2023 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // Copyright 2018 Devolutions // @@ -207,6 +207,8 @@ nni_tcp_dial(nni_tcp_dialer *d, const nni_sockaddr *sa, nni_aio *aio) // poll fd to the list. if ((rv = nni_posix_pfd_init(&pfd, fd)) != 0) { (void) close(fd); + // the error label unlocks this + nni_mtx_lock(&d->mtx); goto error; }