mirror of
https://github.com/nsacyber/HIRS.git
synced 2024-12-20 21:43:18 +00:00
Fixed an issue that caused Process to drop data
This commit is contained in:
parent
0c2005c8df
commit
41923b7337
@ -44,6 +44,11 @@ class Process {
|
||||
const std::string& sourceFileName,
|
||||
int sourceLineNumber);
|
||||
|
||||
static std::string runData(const std::string& executable,
|
||||
const std::string& arguments,
|
||||
const std::string& sourceFileName,
|
||||
int sourceLineNumber);
|
||||
|
||||
static bool isRunning(const std::string& executable);
|
||||
};
|
||||
|
||||
|
@ -814,8 +814,13 @@ string CommandTpm2::runTpm2CommandWithRetry(const string& command,
|
||||
string tpmErrorCode;
|
||||
for (int i = 0;; ++i) {
|
||||
try {
|
||||
return hirs::utils::Process::run(command, args, "CommandTpm2.cpp",
|
||||
sourceCodeLineNumber);
|
||||
if (command.compare(kTpm2ToolsNvReadCommand) == 0) {
|
||||
return hirs::utils::Process::runData(command, args,
|
||||
"CommandTpm2.cpp", sourceCodeLineNumber);
|
||||
} else {
|
||||
return hirs::utils::Process::run(command, args,
|
||||
"CommandTpm2.cpp", sourceCodeLineNumber);
|
||||
}
|
||||
} catch (HirsRuntimeException& ex) {
|
||||
tpmErrorCode = Tpm2ToolsOutputParser::parseTpmErrorCode(ex.what());
|
||||
|
||||
|
@ -144,6 +144,37 @@ string Process::run(const string& executable,
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* * Static function for calling a process that must succeed or throw
|
||||
* * a HirsRuntimeException. This function is meant to be used with the
|
||||
* * RUN_PROCESS_OR_THROW macro in order to capture the source file name
|
||||
* * and source file line number for use in the exception message. Does not
|
||||
* * drop any characters.
|
||||
* * @param executable the executable to be run
|
||||
* * @param arguments the arguments including options to be passed to the
|
||||
* * @param sourceFileName source file from which this method was called
|
||||
* * @param sourceLineNumber line number of source file from which this method
|
||||
* * was called
|
||||
* * executable (defaults to empty string)
|
||||
* */
|
||||
string Process::runData(const string& executable,
|
||||
const string& arguments,
|
||||
const string& sourceFileName,
|
||||
int sourceLineNumber) {
|
||||
stringstream errorStream;
|
||||
Process p(executable, arguments);
|
||||
if (p.run(errorStream) != 0) {
|
||||
errorStream << "\n\n"
|
||||
<< "Process Output: "
|
||||
<< p.getOutputString();
|
||||
throw HirsRuntimeException(errorStream.str(),
|
||||
sourceFileName + ": " + to_string(sourceLineNumber));
|
||||
}
|
||||
|
||||
string str = p.getOutputString();
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Static function to check if a specified process is currently running in the
|
||||
* local environment.
|
||||
|
Loading…
Reference in New Issue
Block a user