Skip to content

unix: fail with ENAMETOOLONG in uv_pipe_*#1329

Closed
addaleax wants to merge 4 commits intolibuv:masterfrom
addaleax:pipe-bind-enametoolong
Closed

unix: fail with ENAMETOOLONG in uv_pipe_*#1329
addaleax wants to merge 4 commits intolibuv:masterfrom
addaleax:pipe-bind-enametoolong

Conversation

@addaleax
Copy link
Copy Markdown
Contributor

@addaleax addaleax commented Apr 27, 2017

Fail with ENAMETOOLONG when the name of a Unix socket exceeds
sizeof(saddr.sun_path). Previously the path was just truncated,
which could result in nasty bugs, and even though that behaviour
has been always been around, it’s hard to imagine a situation in
which ending up with an incorrect path is better than not creating
a socket at all.

Ref: nodejs/node#12601
Ref: nodejs/node#12708

This is targeting master because I wasn’t sure whether you’d consider this a breaking change (you probably do because it’s documented that way).

Fail with ENAMETOOLONG when the name of a Unix socket exceeds
`sizeof(saddr.sun_path)`. Previously the path was just truncated,
which could result in nasty bugs, and even though that behaviour
has been always been around, it’s hard to imagine a situation in
which ending up with an incorrect path is better than not creating
a socket at all.

Ref: nodejs/node#12601
Ref: nodejs/node#12708
@addaleax addaleax force-pushed the pipe-bind-enametoolong branch from 050f0f7 to 3da120b Compare April 27, 2017 23:50
Comment thread src/unix/pipe.c
memset(&saddr, 0, sizeof saddr);
strncpy(saddr.sun_path, pipe_fname, sizeof(saddr.sun_path) - 1);
saddr.sun_path[sizeof(saddr.sun_path) - 1] = '\0';
memcpy(saddr.sun_path, pipe_fname, name_len);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

woudn't memcpy(saddr.sun_path, pipe_fname, name_len - 1); work too?

Comment thread src/unix/pipe.c
memset(&saddr, 0, sizeof saddr);
strncpy(saddr.sun_path, name, sizeof(saddr.sun_path) - 1);
saddr.sun_path[sizeof(saddr.sun_path) - 1] = '\0';
memcpy(saddr.sun_path, name, name_len);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here?

Comment thread src/unix/pipe.c
name_len = strlen(name) + 1;

if (name_len > sizeof(saddr.sun_path))
return -ENAMETOOLONG;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could use UV_ENAMETOOLONG directly here

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we tend to use -errno in src/unix

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Got it.

Comment thread src/unix/pipe.c
name_len = strlen(name) + 1;

if (name_len > sizeof(saddr.sun_path)) {
err = -ENAMETOOLONG;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/-ENAMETOOLONG/UV_ENAMETOOLONG

Comment thread docs/src/pipe.rst
Paths on Unix get truncated to ``sizeof(sockaddr_un.sun_path)`` bytes, typically between
92 and 108 bytes.
If a path on Unix exceeds ``sizeof(sockaddr_un.sun_path)`` bytes, typically between
92 and 108 bytes, ``uv_pipe_bind`` will fail with ``UV_ENAMETOOLONG``.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a .. versionchanged:: section?

Comment thread docs/src/pipe.rst
Paths on Unix get truncated to ``sizeof(sockaddr_un.sun_path)`` bytes, typically between
92 and 108 bytes.
If a path on Unix exceeds ``sizeof(sockaddr_un.sun_path)`` bytes, typically between
92 and 108 bytes, ``uv_pipe_bind`` will fail with ``UV_ENAMETOOLONG``.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

@addaleax
Copy link
Copy Markdown
Contributor Author

@santigimeno @saghul addressed comments, PTAL

@santigimeno
Copy link
Copy Markdown
Member

@santigimeno
Copy link
Copy Markdown
Member

Some relevant failures in the windows bots:

not ok 25 - pipe_connect_to_long_path
# exit code 3
# Output from process `pipe_connect_to_long_path`:
# Assertion failed in test\test-pipe-connect-error.c on line 61: status == UV_ENAMETOOLONG

not ok 107 - pipe_bind_error_long_path
# exit code 3
# Output from process `pipe_bind_error_long_path`:
# Assertion failed in test\test-pipe-bind-error.c on line 151: r == UV_ENAMETOOLONG

@addaleax
Copy link
Copy Markdown
Contributor Author

Right, my bad, the tests should not have been added for Windows. Updated with #ifndef _WIN32 guards…

@santigimeno
Copy link
Copy Markdown
Member

@santigimeno
Copy link
Copy Markdown
Member

Some aix failures:

not ok 25 - pipe_connect_to_long_path
# exit code 393222
# Output from process `pipe_connect_to_long_path`:
# Assertion failed in test/test-pipe-connect-error.c on line 61: status == UV_ENAMETOOLONG

not ok 25 - pipe_connect_to_long_path
# exit code 393222
# Output from process `pipe_connect_to_long_path`:
# Assertion failed in test/test-pipe-connect-error.c on line 61: status == UV_ENAMETOOLONG

@addaleax
Copy link
Copy Markdown
Contributor Author

Okay, fixed up tests for AIX which seems to have an impressive sizeof(sockaddr_un.sun_path) value of 1023… could somebody start CI again?

@santigimeno
Copy link
Copy Markdown
Member

Okay, fixed up tests for AIX which seems to have an impressive sizeof(sockaddr_un.sun_path) value of 1023… could somebody start CI again?

😮
CI: https://ci.nodejs.org/view/libuv/job/libuv-test-commit/256/

@addaleax
Copy link
Copy Markdown
Contributor Author

Ci is green \o/

@santigimeno
Copy link
Copy Markdown
Member

AIX which seems to have an impressive sizeof(sockaddr_un.sun_path) value of 1023

I'm not sure but I'll ask, should we add this info to the docs? Right now we're saying that's typically between 92 and 108 bytes.

Regardless of that, still LGTM.

@addaleax
Copy link
Copy Markdown
Contributor Author

Tbh, I can’t really say just how niche AIX is, so I am not sure it’s worth pointing that out or not (also, libuv is about cross-platform abstraction, so I guess it should be okay if users know they can only rely on 90 bytes or so being available…?).

@santigimeno
Copy link
Copy Markdown
Member

libuv is about cross-platform abstraction, so I guess it should be okay if users know they can only rely on 90 bytes or so being available…?

Yes, it makes sense. Let's leave it as it is.

Copy link
Copy Markdown
Member

@saghul saghul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Good work Anna!

@cjihrig cjihrig added the v2 label May 1, 2017
santigimeno pushed a commit that referenced this pull request May 31, 2017
Fail with ENAMETOOLONG when the name of a Unix socket exceeds
`sizeof(saddr.sun_path)`. Previously the path was just truncated,
which could result in nasty bugs, and even though that behaviour
has been always been around, it’s hard to imagine a situation in
which ending up with an incorrect path is better than not creating
a socket at all.

Refs: nodejs/node#12601
Refs: nodejs/node#12708
PR-URL: #1329
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
@santigimeno
Copy link
Copy Markdown
Member

Landed in 66319cf. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants