-
Notifications
You must be signed in to change notification settings - Fork 6.1k
8347707: Standardise the use of os::snprintf and os::snprintf_checked #26849
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
Changes from all commits
6fdfe1e
c63d4bb
f7fe658
e2f51fc
9c2ffb7
615a59d
c10b6d8
2de6ac9
38003a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -209,10 +209,10 @@ int AixAttachListener::init() { | |
| ::atexit(listener_cleanup); | ||
| } | ||
|
|
||
| int n = snprintf(path, UNIX_PATH_MAX, "%s/.java_pid%d", | ||
| os::get_temp_directory(), os::current_process_id()); | ||
| int n = os::snprintf(path, UNIX_PATH_MAX, "%s/.java_pid%d", | ||
| os::get_temp_directory(), os::current_process_id()); | ||
| if (n < (int)UNIX_PATH_MAX) { | ||
| n = snprintf(initial_path, UNIX_PATH_MAX, "%s.tmp", path); | ||
| n = os::snprintf(initial_path, UNIX_PATH_MAX, "%s.tmp", path); | ||
| } | ||
| if (n >= (int)UNIX_PATH_MAX) { | ||
| return -1; | ||
|
|
@@ -349,9 +349,8 @@ void AttachListener::vm_start() { | |
| struct stat st; | ||
| int ret; | ||
|
|
||
| int n = snprintf(fn, UNIX_PATH_MAX, "%s/.java_pid%d", | ||
| os::get_temp_directory(), os::current_process_id()); | ||
| assert(n < (int)UNIX_PATH_MAX, "java_pid file name buffer overflow"); | ||
| os::snprintf_checked(fn, UNIX_PATH_MAX, "%s/.java_pid%d", | ||
| os::get_temp_directory(), os::current_process_id()); | ||
|
|
||
| RESTARTABLE(::stat(fn, &st), ret); | ||
| if (ret == 0) { | ||
|
|
@@ -419,8 +418,8 @@ bool AttachListener::is_init_trigger() { | |
| RESTARTABLE(::stat(fn, &st), ret); | ||
| if (ret == -1) { | ||
| log_trace(attach)("Failed to find attach file: %s, trying alternate", fn); | ||
| snprintf(fn, sizeof(fn), "%s/.attach_pid%d", | ||
| os::get_temp_directory(), os::current_process_id()); | ||
| os::snprintf_checked(fn, sizeof(fn), "%s/.attach_pid%d", | ||
| os::get_temp_directory(), os::current_process_id()); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could fail if os::get_temp_directory() returns an extremely long path. How about doing a truncation check like at line 354? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nevermind, same thing. We would need to fix a lot of code if os::get_temp_directory() returned a pathologically long string. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've changed line 352 as per Kim's comment above because Again the question to ask is: if we hit this during testing do we think it indicates we need to increase the buffer size. Again I am initially in the yes camp. |
||
| RESTARTABLE(::stat(fn, &st), ret); | ||
| if (ret == -1) { | ||
| log_debug(attach)("Failed to find attach file: %s", fn); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.