Skip to content

Commit

Permalink
Hardening commonutils!DeviceUtils functions for cases when ExecuteCom…
Browse files Browse the repository at this point in the history
…mand succeeds without any text results (#783)
  • Loading branch information
MariusNi authored Oct 29, 2024
1 parent 007209b commit 1724674
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/common/commonutils/DeviceInfoUtils.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ char* GetOsPrettyName(void* log)
const char* osPrettyNameCommand = "cat /etc/os-release | grep PRETTY_NAME=";
char* textResult = NULL;

if (0 == ExecuteCommand(NULL, osPrettyNameCommand, true, true, 0, 0, &textResult, NULL, log))
if ((0 == ExecuteCommand(NULL, osPrettyNameCommand, true, true, 0, 0, &textResult, NULL, log)) && textResult)
{
RemovePrefixBlanks(textResult);
RemoveTrailingBlanks(textResult);
Expand Down Expand Up @@ -136,7 +136,7 @@ char* GetOsName(void* log)
else
{
// PRETTY_NAME did not work, try ID
if (0 == ExecuteCommand(NULL, osNameCommand, true, true, 0, 0, &textResult, NULL, log))
if ((0 == ExecuteCommand(NULL, osNameCommand, true, true, 0, 0, &textResult, NULL, log)) && textResult)
{
RemovePrefixBlanks(textResult);
RemoveTrailingBlanks(textResult);
Expand All @@ -163,7 +163,7 @@ char* GetOsVersion(void* log)
const char* osVersionCommand = "cat /etc/os-release | grep VERSION=";
char* textResult = NULL;

if (0 == ExecuteCommand(NULL, osVersionCommand, true, true, 0, 0, &textResult, NULL, log))
if ((0 == ExecuteCommand(NULL, osVersionCommand, true, true, 0, 0, &textResult, NULL, log)) && textResult)
{
RemovePrefixBlanks(textResult);
RemoveTrailingBlanks(textResult);
Expand All @@ -188,7 +188,7 @@ static char* GetHardwareProperty(const char* command, bool truncateAtFirstSpace,
{
char* textResult = NULL;

if (0 == ExecuteCommand(NULL, command, true, true, 0, 0, &textResult, NULL, log))
if ((0 == ExecuteCommand(NULL, command, true, true, 0, 0, &textResult, NULL, log)) && textResult)
{
RemovePrefixUpTo(textResult, ':');
RemovePrefixBlanks(textResult);
Expand Down Expand Up @@ -219,7 +219,7 @@ static char* GetAnotherOsProperty(const char* command, void* log)
return NULL;
}

if (0 == ExecuteCommand(NULL, command, true, true, 0, 0, &textResult, NULL, log))
if ((0 == ExecuteCommand(NULL, command, true, true, 0, 0, &textResult, NULL, log)) && textResult)
{
RemovePrefixBlanks(textResult);
RemoveTrailingBlanks(textResult);
Expand Down Expand Up @@ -496,7 +496,7 @@ static char* GetOsReleaseEntry(const char* commandTemplate, const char* name, ch
memset(command, 0, commandLength);
snprintf(command, commandLength, commandTemplate, name);

if (0 == (status = ExecuteCommand(NULL, command, true, false, 0, 0, &result, NULL, log)))
if ((0 == (status = ExecuteCommand(NULL, command, true, false, 0, 0, &result, NULL, log))) && result)
{
RemovePrefixBlanks(result);
RemoveTrailingBlanks(result);
Expand Down Expand Up @@ -652,7 +652,7 @@ char* GetLoginUmask(char** reason, void* log)
const char* command = "grep -v '^#' /etc/login.defs | grep UMASK";
char* result = NULL;

if (0 == ExecuteCommand(NULL, command, true, true, 0, 0, &result, NULL, log))
if ((0 == ExecuteCommand(NULL, command, true, true, 0, 0, &result, NULL, log)) && result)
{
RemovePrefixUpTo(result, ' ');
RemovePrefixBlanks(result);
Expand Down Expand Up @@ -734,7 +734,7 @@ static long GetPasswordDays(const char* name, void* log)
memset(command, 0, commandLength);
snprintf(command, commandLength, commandTemplate, name);

if (0 == ExecuteCommand(NULL, command, true, false, 0, 0, &result, NULL, log))
if ((0 == ExecuteCommand(NULL, command, true, false, 0, 0, &result, NULL, log)) && result)
{
RemovePrefixBlanks(result);
RemovePrefixUpTo(result, ' ');
Expand Down Expand Up @@ -931,7 +931,7 @@ bool IsCommodore(void* log)
char* textResult = NULL;
bool status = false;

if (0 == ExecuteCommand(NULL, productNameCommand, true, true, 0, 0, &textResult, NULL, log))
if ((0 == ExecuteCommand(NULL, productNameCommand, true, true, 0, 0, &textResult, NULL, log)) && textResult)
{
RemovePrefixBlanks(textResult);
RemoveTrailingBlanks(textResult);
Expand Down

0 comments on commit 1724674

Please sign in to comment.