unix: fail with ENAMETOOLONG in uv_pipe_*#1329
unix: fail with ENAMETOOLONG in uv_pipe_*#1329addaleax wants to merge 4 commits intolibuv:masterfrom
uv_pipe_*#1329Conversation
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
050f0f7 to
3da120b
Compare
| 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); |
There was a problem hiding this comment.
woudn't memcpy(saddr.sun_path, pipe_fname, name_len - 1); work too?
| 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); |
| name_len = strlen(name) + 1; | ||
|
|
||
| if (name_len > sizeof(saddr.sun_path)) | ||
| return -ENAMETOOLONG; |
There was a problem hiding this comment.
we could use UV_ENAMETOOLONG directly here
There was a problem hiding this comment.
we tend to use -errno in src/unix
| name_len = strlen(name) + 1; | ||
|
|
||
| if (name_len > sizeof(saddr.sun_path)) { | ||
| err = -ENAMETOOLONG; |
There was a problem hiding this comment.
s/-ENAMETOOLONG/UV_ENAMETOOLONG
| 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``. |
There was a problem hiding this comment.
Can you add a .. versionchanged:: section?
| 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``. |
|
@santigimeno @saghul addressed comments, PTAL |
|
Some relevant failures in the windows bots: |
|
Right, my bad, the tests should not have been added for Windows. Updated with |
|
Some aix failures: |
|
Okay, fixed up tests for AIX which seems to have an impressive |
😮 |
|
Ci is green \o/ |
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. |
|
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…?). |
Yes, it makes sense. Let's leave it as it is. |
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>
|
Landed in 66319cf. Thanks! |
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
masterbecause I wasn’t sure whether you’d consider this a breaking change (you probably do because it’s documented that way).