Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined behavior in posix ipc_dialer_dial #1675

Closed
JoshSalitSonos opened this issue Aug 7, 2023 · 2 comments
Closed

undefined behavior in posix ipc_dialer_dial #1675

JoshSalitSonos opened this issue Aug 7, 2023 · 2 comments
Labels

Comments

@JoshSalitSonos
Copy link
Contributor

JoshSalitSonos commented Aug 7, 2023

Describe the bug
In the ipc_dialer_dial implementation in src/platform/posix/posix_ipcdial.c, if nni_posix_pfd_init fails then goto error is executed, and nni_mtx_unlock(&d->mtx) is called without the mutex having been locked. this passes through to a pthread_mutex_unlock call, which is documented as having undefined behavior if the mutex is not locked.

if ((rv = nni_posix_pfd_init(&pfd, fd)) != 0) {
goto error;

It looks like this was introduced by PR #1111.

To Reproduce
This was found via code inspection.

** Environment Details **

  • NNG version - commit c5e9d8a
  • linux (various kernels)
@gdamore gdamore added the bug label Sep 14, 2023
@gdamore
Copy link
Contributor

gdamore commented Sep 14, 2023

The TCP code path suffers the same flaw.

@gdamore
Copy link
Contributor

gdamore commented Sep 14, 2023

One note for anyone looking at this -- short of running of out RAM, it's exceedingly unlikely that you've observed this particular bug. The failure path here should really not be one we expect to see executed.

gdamore added a commit that referenced this issue Sep 14, 2023
(This also affects TCP, and fixed there.)
gdamore added a commit that referenced this issue Sep 14, 2023
(This also affects TCP, and fixed there.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants