-
Notifications
You must be signed in to change notification settings - Fork 3.7k
unix,doc: always copy process title when setting #1396
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
I haven't reviewed the code, but can you split this into two commits - one for the docs, and one for the code changes. |
Add a small warning about uv_get_process_title / uv_set_process_title not being thread safe on platforms other than Windows. Also adds a reminder for users to call `uv_setup_args` first.
Ensures that the user's argv is copied into a local buffer when calling uv_setup_args. Before, the argv was simply being pointed to, which meant that libuv could end up accessing invalid memory if the user decided to later edit the memory at that location. It also meant that a subsequent call to uv_set_process_title would never write more characters than the length of argv[0]. With the new changes, argv[0] is copied into a temporary buffer and any subsequent calls to uv_set_process_title will thus be able to copy as many characters as the call to uv__strdup permits. Note that on *BSD and AIX this behaviour was already in effect . Some error checking (specifically checking the result of uv__strdup) has been added, and calls to uv__free rearranged so that in case of ENOMEM uv__free can't be called erroneously.
Done. |
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
bump. |
@cjihrig can you PTAL too? |
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.
Thanks for the PR. LGTM modulo comment.
src/unix/proctitle.c
Outdated
process_title.str = argv[0]; | ||
process_title.str = uv__strdup(argv[0]); | ||
if (process_title.str == NULL) | ||
return argv; |
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.
Can you hoist the common code (everything up to and including the if statement) out of the #if
block?
Comment addressed. |
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.
https://ci.nodejs.org/job/libuv-test-commit-linux/357/nodes=armv7-wheezy/console - failures look unrelated, seems like a stray process hogging a port. |
Add a small warning about uv_get_process_title() and uv_set_process_title() not being thread safe on platforms other than Windows. Also add a reminder for users to call uv_setup_args() first. Fixes: #1395 PR-URL: #1396 Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Ensures that the user's argv is copied into a local buffer when calling uv_setup_args. Before, the argv was simply being pointed to, which meant that libuv could end up accessing invalid memory if the user decided to later edit the memory at that location. It also meant that a subsequent call to uv_set_process_title would never write more characters than the length of argv[0]. With the new changes, argv[0] is copied into a temporary buffer and any subsequent calls to uv_set_process_title will thus be able to copy as many characters as the call to uv__strdup permits. Note that on *BSD and AIX this behaviour was already in effect . Some error checking (specifically checking the result of uv__strdup) has been added, and calls to uv__free rearranged so that in case of ENOMEM uv__free can't be called erroneously. Fixes: #1395 PR-URL: #1396 Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This causes a test failure in Node. See nodejs/node#14866. The issue appears to be that overwriting |
I don't see |
So, the original post said:
and
My understanding is that with the changes in this PR, we are no longer pointing to That also leaves the question of what to do about it. |
You're right about the temporary buffer, but I don't believe that changing |
Changing |
My mistake then. So |
I don't think so. The Node CI lit up bright red when I updated the version of libuv. You can see the failures here: https://ci.nodejs.org/job/node-test-commit/11826/ |
Looks like you're right, although there are some unrelated Windows failures there too. I think just reverting the changes in |
There are some things that are significantly harder or more involved to test in C than they are from Node. A CI job or something similar to test libuv in Node before a release is cut might be nice, but are beyond the scope of this issue. |
That's indeed a very good idea. /cc @refack as I think he's now member of the nodejs build group |
Just another data point: current code works on Windows (because the whole |
|
OMG sorry :(. I'll edit the comment. |
|
P.S. I'm almost un-offendable |
I was thinking more like |
Ensures that the user's
argv
is copied into a local buffer when callinguv_setup_args
. Before, theargv
was simply being pointed to, which meant that libuv could end up accessing invalid memory if the user decided to later edit the memory at that location. It also meant that a subsequent call touv_set_process_title
would never write more characters than the length ofargv[0]
.With the new changes,
argv[0]
is copied into a temporary buffer and any subsequent calls touv_set_process_title
will thus be able to copy as many characters as the call touv__strdup
permits. Note that on *BSD and AIX this behaviour was already in effect .Some error checking (specifically checking the result of
uv__strdup
) has been added, and calls touv__free
rearranged so that in case ofENOMEM
uv__free
can't be called erroneously.Finally, a warning about the thread safety of
uv_get_process_title
anduv_set_process_title
was added to the docs.Note: I wasn't too sure how to add a test for this, since I don't believe the current test system exposes
argv
.Addresses #1395.