Skip to content

Commit

Permalink
Prevent CheckFileContents cause an invalid reason to fail json_value_…
Browse files Browse the repository at this point in the history
…init_string and cascade into a false passing audit
  • Loading branch information
MariusNi committed Sep 9, 2024
1 parent de8c82d commit 19ecb09
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
11 changes: 5 additions & 6 deletions src/common/asb/Asb.c
Original file line number Diff line number Diff line change
Expand Up @@ -4420,12 +4420,11 @@ int AsbMmiGet(const char* componentName, const char* objectName, char** payload,

if (0 == status)
{
if (NULL == result)
if ((NULL == result) || (NULL == (jsonValue = json_value_init_string(result))))
{
OsConfigLogError(log, "AsbMmiGet(%s, %s): audit failure without a reason", componentName, objectName);
result = DuplicateString(g_fail);

if (NULL == result)
OsConfigLogError(log, "AsbMmiGet(%s, %s): audit failure without a valid reason", componentName, objectName);
FREE_MEMORY(result);
if (NULL == (result = DuplicateString(g_fail)))
{
OsConfigLogError(log, "AsbMmiGet: DuplicateString failed");
status = ENOMEM;
Expand All @@ -4434,7 +4433,7 @@ int AsbMmiGet(const char* componentName, const char* objectName, char** payload,

if (NULL != result)
{
if (NULL == (jsonValue = json_value_init_string(result)))
if ((NULL == jsonValue) && (NULL == (jsonValue = json_value_init_string(result))))
{
OsConfigLogError(log, "AsbMmiGet(%s, %s): json_value_init_string(%s) failed", componentName, objectName, result);
status = ENOMEM;
Expand Down
4 changes: 2 additions & 2 deletions src/common/commonutils/FileUtils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1288,8 +1288,8 @@ int CheckFileContents(const char* fileName, const char* text, char** reason, voi
}
else
{
OsConfigLogInfo(log, "CheckFileContents: '%s' does not match contents of '%s' ('%s')", text, fileName, contents);
OsConfigCaptureReason(reason, "'%s' does not match contents of '%s' ('%s')", text, fileName, contents);
OsConfigLogInfo(log, "CheckFileContents: '%s' does not match contents of '%s'", text, fileName);
OsConfigCaptureReason(reason, "'%s' does not match contents of '%s'", text, fileName);
status = ENOENT;
}
}
Expand Down

0 comments on commit 19ecb09

Please sign in to comment.