-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8333871: Check sysinfo return values #28317
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
2d574f7
e9d2b1b
6284ef2
2f4c7c9
e498891
22a2f6a
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 |
|---|---|---|
|
|
@@ -510,7 +510,11 @@ pid_t os::Linux::gettid() { | |
| // This can change at any time. | ||
| julong os::Linux::host_swap() { | ||
| struct sysinfo si; | ||
| sysinfo(&si); | ||
| int ret = sysinfo(&si); | ||
| if (ret != 0) { | ||
| assert(false, "sysinfo failed in host_swap(): %s", os::strerror(errno)); | ||
| return 0; | ||
| } | ||
| return (julong)(si.totalswap * si.mem_unit); | ||
| } | ||
|
|
||
|
|
@@ -2447,6 +2451,8 @@ void os::Linux::print_uptime_info(outputStream* st) { | |
| int ret = sysinfo(&sinfo); | ||
| if (ret == 0) { | ||
| os::print_dhm(st, "OS uptime:", (long) sinfo.uptime); | ||
| } else { | ||
| st->print_cr("OS uptime could not be retrieved."); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -2570,18 +2576,22 @@ void os::print_memory_info(outputStream* st) { | |
|
|
||
| // values in struct sysinfo are "unsigned long" | ||
| struct sysinfo si; | ||
| sysinfo(&si); | ||
| int ret = sysinfo(&si); | ||
| physical_memory_size_type phys_mem = physical_memory(); | ||
| st->print(", physical " PHYS_MEM_TYPE_FORMAT "k", | ||
| phys_mem >> 10); | ||
| physical_memory_size_type avail_mem = 0; | ||
| (void)os::available_memory(avail_mem); | ||
| st->print("(" PHYS_MEM_TYPE_FORMAT "k free)", | ||
| avail_mem >> 10); | ||
| st->print(", swap " UINT64_FORMAT "k", | ||
| ((jlong)si.totalswap * si.mem_unit) >> 10); | ||
| st->print("(" UINT64_FORMAT "k free)", | ||
| ((jlong)si.freeswap * si.mem_unit) >> 10); | ||
| if (ret == 0) { | ||
| st->print(", swap " UINT64_FORMAT "k", | ||
| ((jlong)si.totalswap * si.mem_unit) >> 10); | ||
| st->print("(" UINT64_FORMAT "k free)", | ||
| ((jlong)si.freeswap * si.mem_unit) >> 10); | ||
| } else { | ||
| st->print(", swap could not be determined"); | ||
| } | ||
|
||
| st->cr(); | ||
| st->print("Page Sizes: "); | ||
| _page_sizes.print_on(st); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -388,8 +388,13 @@ GetJavaProperties(JNIEnv *env) | |||||
| /* supported instruction sets */ | ||||||
| { | ||||||
| char list[258]; | ||||||
| sysinfo(SI_ISALIST, list, sizeof(list)); | ||||||
| sprops.cpu_isalist = strdup(list); | ||||||
| int ret = sysinfo(SI_ISALIST, list, sizeof(list)); | ||||||
| if (ret == 0) { | ||||||
| sprops.cpu_isalist = strdup(list); | ||||||
| list[sizeof(list) - 1] = '\0'; | ||||||
MBaesken marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| } else { | ||||||
| sprops.cpu_isalist = NULL; | ||||||
|
Contributor
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. Would you mind checking the code that puts this in a system property can tolerate NULL? I don't suppose sysinfo will fail here (unless you found a case?) but it would be good to confirm that it won't blow up somewhere else.
Member
Author
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. We do PUTPROP here
with 3rd parameter == NULL in this case. PUTPROP checks for this so I do not see issues with this
|
||||||
| } | ||||||
| } | ||||||
| #else | ||||||
| sprops.cpu_isalist = 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 think an assert would be preferable here. This code can't be parsed so I think it better not to inject it.