Skip to content

Commit

Permalink
fix: Resolve nullptr access issues (#61)
Browse files Browse the repository at this point in the history
* Add nullptr check to avoid nullptr access.
* passing C style char array for putenv function instead of string constant to avoid
  compilation warning.

Related-To: VLCLJ-2228

Signed-off-by: Vishnu Khanth <vishnu.khanth.b@intel.com>
  • Loading branch information
vishnu-khanth authored Aug 1, 2024
1 parent 0d90d15 commit a96c15c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,14 @@ TEST_F(
GivenHierarchyModeCombindedAndSysmanEnableEnvDisabledThenUUIDFromCoreAndSysmanMatches) {
auto is_sysman_enabled = getenv("ZES_ENABLE_SYSMAN");
// Disabling enable_sysman env if it's defaultly enabled
if (strcmp(is_sysman_enabled, "1") == 0) {
putenv("ZES_ENABLE_SYSMAN=0");
if (is_sysman_enabled != nullptr && strcmp(is_sysman_enabled, "1") == 0) {
char disable_sysman_env[] = "ZES_ENABLE_SYSMAN=0";
putenv(disable_sysman_env);
}
run_child_process("COMBINED");
if (strcmp(is_sysman_enabled, "1") == 0) {
putenv("ZES_ENABLE_SYSMAN=1");
if (is_sysman_enabled != nullptr && strcmp(is_sysman_enabled, "1") == 0) {
char enable_sysman_env[] = "ZES_ENABLE_SYSMAN=1";
putenv(enable_sysman_env);
}
}

Expand All @@ -127,12 +129,14 @@ TEST_F(
GivenHierarchyModeCompositeAndSysmanEnableEnvDisabledThenUUIDFromCoreAndSysmanMatches) {
auto is_sysman_enabled = getenv("ZES_ENABLE_SYSMAN");
// Disabling enable_sysman env if it's defaultly enabled
if (strcmp(is_sysman_enabled, "1") == 0) {
putenv("ZES_ENABLE_SYSMAN=0");
if (is_sysman_enabled != nullptr && strcmp(is_sysman_enabled, "1") == 0) {
char disable_sysman_env[] = "ZES_ENABLE_SYSMAN=0";
putenv(disable_sysman_env);
}
run_child_process("COMPOSITE");
if (strcmp(is_sysman_enabled, "1") == 0) {
putenv("ZES_ENABLE_SYSMAN=1");
if (is_sysman_enabled != nullptr && strcmp(is_sysman_enabled, "1") == 0) {
char enable_sysman_env[] = "ZES_ENABLE_SYSMAN=1";
putenv(enable_sysman_env);
}
}
#endif // USE_ZESINIT
Expand Down
10 changes: 6 additions & 4 deletions conformance_tests/sysman/test_sysman_init/src/test_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ TEST(
GivenSysmanEnableEnvDisabledAndCoreInitializedFirstWhenSysmanInitializedThenzesDriverGetWorks) {
auto is_sysman_enabled = getenv("ZES_ENABLE_SYSMAN");
// Disabling enable_sysman env if it's defaultly enabled
if (strcmp(is_sysman_enabled, "1") == 0) {
putenv("ZES_ENABLE_SYSMAN=0");
if (is_sysman_enabled != nullptr && strcmp(is_sysman_enabled, "1") == 0) {
char disable_sysman_env[] = "ZES_ENABLE_SYSMAN=0";
putenv(disable_sysman_env);
}
ASSERT_EQ(ZE_RESULT_SUCCESS, zeInit(0));
uint32_t zeInitCount = 0;
Expand All @@ -34,8 +35,9 @@ TEST(
uint32_t zesInitCount = 0;
ASSERT_EQ(ZE_RESULT_SUCCESS, zesDriverGet(&zesInitCount, nullptr));
ASSERT_GT(zesInitCount, 0);
if (strcmp(is_sysman_enabled, "1") == 0) {
putenv("ZES_ENABLE_SYSMAN=1");
if (is_sysman_enabled != nullptr && strcmp(is_sysman_enabled, "1") == 0) {
char enable_sysman_env[] = "ZES_ENABLE_SYSMAN=1";
putenv(enable_sysman_env);
}
}

Expand Down

0 comments on commit a96c15c

Please sign in to comment.