[#135] Fix DeviceInfoCollector's handling of C-Style Strings

This commit is contained in:
apldev3 2019-05-10 12:34:52 -04:00 committed by apldev6
parent 3bebec1154
commit d26a3da5ea

View File

@ -293,10 +293,15 @@ public class DeviceInfoCollector extends AbstractCollector {
&& tokens[VERSION_INDEX].equals("Version")) {
String[] versionTokens = tokens[VERSION_TOKEN_INDEX].split("\\.");
if (versionTokens.length == VERSION_TOKEN_LENGTH) {
tpmVersionMajor = Short.parseShort(versionTokens[TPM_MAJOR_INDEX]);
tpmVersionMinor = Short.parseShort(versionTokens[TPM_MINOR_INDEX]);
tpmVersionRevMajor = Short.parseShort(versionTokens[TPM_REV_MAJOR_INDEX]);
tpmVersionRevMinor = Short.parseShort(versionTokens[TPM_REV_MINOR_INDEX]);
// Trim version tokens to avoid C-style strings w/ null characters
tpmVersionMajor = Short.parseShort(
versionTokens[TPM_MAJOR_INDEX].trim());
tpmVersionMinor = Short.parseShort(
versionTokens[TPM_MINOR_INDEX].trim());
tpmVersionRevMajor = Short.parseShort(
versionTokens[TPM_REV_MAJOR_INDEX].trim());
tpmVersionRevMinor = Short.parseShort(
versionTokens[TPM_REV_MINOR_INDEX].trim());
LOGGER.debug("Found TPM version {}.{}.{}.{}",
tpmVersionMajor, tpmVersionMinor,
tpmVersionRevMajor, tpmVersionRevMinor);