-
Notifications
You must be signed in to change notification settings - Fork 3.8k
unix,windows: init all requests in fs calls #1509
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
Conversation
| int r; | ||
|
|
||
| r = uv_fs_read(NULL, NULL, 0, NULL, 0, -1, NULL); | ||
| r = uv_fs_read(NULL, &read_req, 0, NULL, 0, -1, NULL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hum, what should happen now if someone passes a NULL pointer then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess nothing? Since uv_fs_cleanup would also do nothing if a NULL pointer is passed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It crashes because none of the req init logic checks for NULL. That would happen for other calls too though. I think we should either crash consistently or update the init logic to handle NULL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the more I think about this, the more I think we should just assert on req for these functions. If we return UV_EINVAL in these cases, there is no way for the consumer to know if they can cleanup the request or not. It also seems pretty nonsensical to call any of these without a request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@saghul I added a second commit to support NULL requests for all of the fs functions. The new logic is "if the request is NULL, immediately return UV_EINVAL. Otherwise, initialize the request before doing anything else." I think that should allow all requests to be cleaned up. PTAL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also add some tests which use a NULL req.
|
@saghul ping |
saghul
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay Colin! Left some comments.
|
|
||
| #define INIT(subtype) \ | ||
| do { \ | ||
| if (req == NULL) \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then uv_fs_req_cleanup should check if req is null and not do anything: https://github.com/libuv/libuv/blob/v1.x/src/unix/fs.c#L1452
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same on Windows.
src/win/fs.c
Outdated
|
|
||
|
|
||
| int uv_fs_close(uv_loop_t* loop, uv_fs_t* req, uv_file fd, uv_fs_cb cb) { | ||
| if (req == NULL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see every function looks like this now on Windows:
if (req == NULL)
return UV_EINVAL;
uv_fs_req_init(loop, req, UV_FS_FOO, cb);
Maybe use a macro to save some lines?
| int r; | ||
|
|
||
| r = uv_fs_read(NULL, NULL, 0, NULL, 0, -1, NULL); | ||
| r = uv_fs_read(NULL, &read_req, 0, NULL, 0, -1, NULL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also add some tests which use a NULL req.
|
@saghul addressed all of your comments. Update: CI was all 💚 |
saghul
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. One minor nit (which you are free to ignore): I think I'd combine the last and 2nd commits into a single one.
149d609 to
d70385f
Compare
Prior to this change, several of the fs functions checked for invalid arguments before initializing the fs request. If a consumer received a UV_EINVAL from one of these functions, and then called uv_fs_req_cleanup(), the application would crash, as the pointer being freed was not allocated. This commit makes sure that all fs functions initialize the request before returning. Fixes: libuv#1508 PR-URL: libuv#1509 Reviewed-By: Bartosz Sosnowski <[email protected]> Reviewed-By: Saúl Ibarra Corretgé <[email protected]>
This commit introduces an INIT macro to file system functions on Windows, similar to the one used on Unix platforms. The macro checks for NULL requests, and returns UV_EINVAL in such scenarios. This commit also adds support for passing NULL to uv_fs_req_cleanup(). In this scenario, the function is a no-op. Fixes: libuv#1508 PR-URL: libuv#1509 Reviewed-By: Bartosz Sosnowski <[email protected]> Reviewed-By: Saúl Ibarra Corretgé <[email protected]>
This commit adds a POST macro to the Windows fs functions, similar to the one used on Unix platforms. PR-URL: libuv#1509 Reviewed-By: Saúl Ibarra Corretgé <[email protected]>
Prior to this change, several of the fs functions checked for invalid arguments before initializing the fs request. If a consumer received a UV_EINVAL from one of these functions, and then called uv_fs_req_cleanup(), the application would crash, as the pointer being freed was not allocated. This commit makes sure that all fs functions initialize the request before returning. Fixes: #1508 PR-URL: #1509 Reviewed-By: Bartosz Sosnowski <[email protected]> Reviewed-By: Saúl Ibarra Corretgé <[email protected]>
This commit introduces an INIT macro to file system functions on Windows, similar to the one used on Unix platforms. The macro checks for NULL requests, and returns UV_EINVAL in such scenarios. This commit also adds support for passing NULL to uv_fs_req_cleanup(). In this scenario, the function is a no-op. Fixes: #1508 PR-URL: #1509 Reviewed-By: Bartosz Sosnowski <[email protected]> Reviewed-By: Saúl Ibarra Corretgé <[email protected]>
This commit adds a POST macro to the Windows fs functions, similar to the one used on Unix platforms. PR-URL: #1509 Reviewed-By: Saúl Ibarra Corretgé <[email protected]>
Prior to this change, several of the fs functions checked for invalid arguments before initializing the fs request. If a consumer received a UV_EINVAL from one of these functions, and then called uv_fs_req_cleanup(), the application would crash, as the pointer being freed was not allocated. This commit makes sure that all fs functions initialize the request before returning.
Fixes: #1508