OpenJDK / jdk / jdk
changeset 57402:ed442869a2fc
8235489: handle return values of sscanf calls in hotspot
Reviewed-by: clanger, kbarrett
author | mbaesken |
---|---|
date | Wed, 11 Dec 2019 09:42:52 +0100 |
parents | d226c74fd68f |
children | 9b157392afd6 |
files | src/hotspot/os/linux/os_linux.cpp src/hotspot/share/compiler/compilerOracle.cpp |
diffstat | 2 files changed, 11 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/src/hotspot/os/linux/os_linux.cpp Thu Dec 12 07:48:08 2019 +0100 +++ b/src/hotspot/os/linux/os_linux.cpp Wed Dec 11 09:42:52 2019 +0100 @@ -2081,11 +2081,14 @@ u8 base, top, offset, inode; char permissions[5]; char device[6]; - char name[PATH_MAX + 1]; + char name[sizeof(line)]; // Parse fields from line - sscanf(line, UINT64_FORMAT_X "-" UINT64_FORMAT_X " %4s " UINT64_FORMAT_X " %7s " INT64_FORMAT " %s", + int matches = sscanf(line, UINT64_FORMAT_X "-" UINT64_FORMAT_X " %4s " UINT64_FORMAT_X " %5s " INT64_FORMAT " %s", &base, &top, permissions, &offset, device, &inode, name); + // the last entry 'name' is empty for some entries, so we might have 6 matches instead of 7 for some lines + if (matches < 6) continue; + if (matches == 6) name[0] = '\0'; // Filter by device id '00:00' so that we only get file system mapped files. if (strcmp(device, "00:00") != 0) {
--- a/src/hotspot/share/compiler/compilerOracle.cpp Thu Dec 12 07:48:08 2019 +0100 +++ b/src/hotspot/share/compiler/compilerOracle.cpp Wed Dec 11 09:42:52 2019 +0100 @@ -380,10 +380,12 @@ *bytes_read = 0; char command[33]; - int result = sscanf(line, "%32[a-z]%n", command, bytes_read); - for (uint i = 0; i < ARRAY_SIZE(command_names); i++) { - if (strcmp(command, command_names[i]) == 0) { - return (OracleCommand)i; + int matches = sscanf(line, "%32[a-z]%n", command, bytes_read); + if (matches > 0) { + for (uint i = 0; i < ARRAY_SIZE(command_names); i++) { + if (strcmp(command, command_names[i]) == 0) { + return (OracleCommand)i; + } } } return UnknownCommand;