fs, pipe: no trailing terminator in exact sized buffers
uv_fs_poll_getpath, uv_pipe_getsockname, uv_fs_event_getpath used to return the trailing null terminator, even though the functions returned the size. Fixes: https://github.com/libuv/libuv/issues/155 PR-URL: https://github.com/libuv/libuv/pull/159 Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
This commit is contained in:
parent
79e69fd555
commit
1e59ab1d49
@ -102,4 +102,7 @@ API
|
|||||||
is not big enough UV_ENOBUFS will be returned and len will be set to the
|
is not big enough UV_ENOBUFS will be returned and len will be set to the
|
||||||
required size.
|
required size.
|
||||||
|
|
||||||
|
.. versionchanged:: 1.3.0 the returned length no longer includes the terminating null byte,
|
||||||
|
and the buffer is not null terminated.
|
||||||
|
|
||||||
.. seealso:: The :c:type:`uv_handle_t` API functions also apply.
|
.. seealso:: The :c:type:`uv_handle_t` API functions also apply.
|
||||||
|
|||||||
@ -66,4 +66,7 @@ API
|
|||||||
is not big enough UV_ENOBUFS will be returned and len will be set to the
|
is not big enough UV_ENOBUFS will be returned and len will be set to the
|
||||||
required size.
|
required size.
|
||||||
|
|
||||||
|
.. versionchanged:: 1.3.0 the returned length no longer includes the terminating null byte,
|
||||||
|
and the buffer is not null terminated.
|
||||||
|
|
||||||
.. seealso:: The :c:type:`uv_handle_t` API functions also apply.
|
.. seealso:: The :c:type:`uv_handle_t` API functions also apply.
|
||||||
|
|||||||
@ -65,6 +65,9 @@ API
|
|||||||
output. If the buffer is not big enough ``UV_ENOBUFS`` will be returned and
|
output. If the buffer is not big enough ``UV_ENOBUFS`` will be returned and
|
||||||
len will contain the required size.
|
len will contain the required size.
|
||||||
|
|
||||||
|
.. versionchanged:: 1.3.0 the returned length no longer includes the terminating null byte,
|
||||||
|
and the buffer is not null terminated.
|
||||||
|
|
||||||
.. c:function:: void uv_pipe_pending_instances(uv_pipe_t* handle, int count)
|
.. c:function:: void uv_pipe_pending_instances(uv_pipe_t* handle, int count)
|
||||||
|
|
||||||
Set the number of pending pipe instance handles when the pipe server is
|
Set the number of pending pipe instance handles when the pipe server is
|
||||||
|
|||||||
@ -137,7 +137,7 @@ int uv_fs_poll_getpath(uv_fs_poll_t* handle, char* buf, size_t* len) {
|
|||||||
ctx = handle->poll_ctx;
|
ctx = handle->poll_ctx;
|
||||||
assert(ctx != NULL);
|
assert(ctx != NULL);
|
||||||
|
|
||||||
required_len = strlen(ctx->path) + 1;
|
required_len = strlen(ctx->path);
|
||||||
if (required_len > *len) {
|
if (required_len > *len) {
|
||||||
*len = required_len;
|
*len = required_len;
|
||||||
return UV_ENOBUFS;
|
return UV_ENOBUFS;
|
||||||
|
|||||||
@ -223,7 +223,7 @@ int uv_pipe_getsockname(const uv_pipe_t* handle, char* buf, size_t* len) {
|
|||||||
/* Linux abstract namespace */
|
/* Linux abstract namespace */
|
||||||
addrlen -= offsetof(struct sockaddr_un, sun_path);
|
addrlen -= offsetof(struct sockaddr_un, sun_path);
|
||||||
else
|
else
|
||||||
addrlen = strlen(sa.sun_path) + 1;
|
addrlen = strlen(sa.sun_path);
|
||||||
|
|
||||||
|
|
||||||
if (addrlen > *len) {
|
if (addrlen > *len) {
|
||||||
|
|||||||
@ -367,7 +367,7 @@ int uv_fs_event_getpath(uv_fs_event_t* handle, char* buf, size_t* len) {
|
|||||||
return UV_EINVAL;
|
return UV_EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
required_len = strlen(handle->path) + 1;
|
required_len = strlen(handle->path);
|
||||||
if (required_len > *len) {
|
if (required_len > *len) {
|
||||||
*len = required_len;
|
*len = required_len;
|
||||||
return UV_ENOBUFS;
|
return UV_ENOBUFS;
|
||||||
|
|||||||
@ -1987,9 +1987,9 @@ int uv_pipe_getsockname(const uv_pipe_t* handle, char* buf, size_t* len) {
|
|||||||
*len = 0;
|
*len = 0;
|
||||||
err = uv_translate_sys_error(GetLastError());
|
err = uv_translate_sys_error(GetLastError());
|
||||||
goto error;
|
goto error;
|
||||||
} else if (pipe_prefix_len + addrlen + 1 > *len) {
|
} else if (pipe_prefix_len + addrlen > *len) {
|
||||||
/* "\\\\.\\pipe" + name + '\0' */
|
/* "\\\\.\\pipe" + name */
|
||||||
*len = pipe_prefix_len + addrlen + 1;
|
*len = pipe_prefix_len + addrlen;
|
||||||
err = UV_ENOBUFS;
|
err = UV_ENOBUFS;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
@ -2010,7 +2010,6 @@ int uv_pipe_getsockname(const uv_pipe_t* handle, char* buf, size_t* len) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addrlen += pipe_prefix_len;
|
addrlen += pipe_prefix_len;
|
||||||
buf[addrlen++] = '\0';
|
|
||||||
*len = addrlen;
|
*len = addrlen;
|
||||||
|
|
||||||
err = 0;
|
err = 0;
|
||||||
|
|||||||
@ -642,6 +642,7 @@ TEST_IMPL(fs_event_getpath) {
|
|||||||
len = sizeof buf;
|
len = sizeof buf;
|
||||||
r = uv_fs_event_getpath(&fs_event, buf, &len);
|
r = uv_fs_event_getpath(&fs_event, buf, &len);
|
||||||
ASSERT(r == 0);
|
ASSERT(r == 0);
|
||||||
|
ASSERT(buf[len - 1] != 0);
|
||||||
ASSERT(memcmp(buf, "watch_dir", len) == 0);
|
ASSERT(memcmp(buf, "watch_dir", len) == 0);
|
||||||
r = uv_fs_event_stop(&fs_event);
|
r = uv_fs_event_stop(&fs_event);
|
||||||
ASSERT(r == 0);
|
ASSERT(r == 0);
|
||||||
|
|||||||
@ -172,6 +172,7 @@ TEST_IMPL(fs_poll_getpath) {
|
|||||||
ASSERT(0 == uv_fs_poll_start(&poll_handle, poll_cb_fail, FIXTURE, 100));
|
ASSERT(0 == uv_fs_poll_start(&poll_handle, poll_cb_fail, FIXTURE, 100));
|
||||||
len = sizeof buf;
|
len = sizeof buf;
|
||||||
ASSERT(0 == uv_fs_poll_getpath(&poll_handle, buf, &len));
|
ASSERT(0 == uv_fs_poll_getpath(&poll_handle, buf, &len));
|
||||||
|
ASSERT(buf[len - 1] != 0);
|
||||||
ASSERT(0 == memcmp(buf, FIXTURE, len));
|
ASSERT(0 == memcmp(buf, FIXTURE, len));
|
||||||
|
|
||||||
uv_close((uv_handle_t*) &poll_handle, close_cb);
|
uv_close((uv_handle_t*) &poll_handle, close_cb);
|
||||||
|
|||||||
@ -60,6 +60,7 @@ TEST_IMPL(pipe_getsockname) {
|
|||||||
len = sizeof buf;
|
len = sizeof buf;
|
||||||
r = uv_pipe_getsockname(&server, buf, &len);
|
r = uv_pipe_getsockname(&server, buf, &len);
|
||||||
ASSERT(r == 0);
|
ASSERT(r == 0);
|
||||||
|
ASSERT(buf[len - 1] != 0);
|
||||||
|
|
||||||
ASSERT(memcmp(buf, TEST_PIPENAME, len) == 0);
|
ASSERT(memcmp(buf, TEST_PIPENAME, len) == 0);
|
||||||
|
|
||||||
@ -149,6 +150,7 @@ TEST_IMPL(pipe_getsockname_blocking) {
|
|||||||
len1 = sizeof buf1;
|
len1 = sizeof buf1;
|
||||||
r = uv_pipe_getsockname(&reader, buf1, &len1);
|
r = uv_pipe_getsockname(&reader, buf1, &len1);
|
||||||
ASSERT(r == 0);
|
ASSERT(r == 0);
|
||||||
|
ASSERT(buf1[len1 - 1] != 0);
|
||||||
|
|
||||||
r = uv_read_start((uv_stream_t*)&reader, NULL, NULL);
|
r = uv_read_start((uv_stream_t*)&reader, NULL, NULL);
|
||||||
ASSERT(r == 0);
|
ASSERT(r == 0);
|
||||||
@ -157,6 +159,7 @@ TEST_IMPL(pipe_getsockname_blocking) {
|
|||||||
len2 = sizeof buf2;
|
len2 = sizeof buf2;
|
||||||
r = uv_pipe_getsockname(&reader, buf2, &len2);
|
r = uv_pipe_getsockname(&reader, buf2, &len2);
|
||||||
ASSERT(r == 0);
|
ASSERT(r == 0);
|
||||||
|
ASSERT(buf2[len2 - 1] != 0);
|
||||||
|
|
||||||
r = uv_read_stop((uv_stream_t*)&reader);
|
r = uv_read_stop((uv_stream_t*)&reader);
|
||||||
ASSERT(r == 0);
|
ASSERT(r == 0);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user