Skip to content

Commit 037ed53

Browse files
Check enable_environment for NULL before copying
The enable_environment was missing NULL pointer checks before trying to copy the string. This issue was found by fuzz testing, so the fuzz test has been included as a reproducible case.
1 parent eab3603 commit 037ed53

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

loader/loader.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2744,7 +2744,8 @@ VkResult loader_read_layer_json(const struct loader_instance *inst, struct loade
27442744
cJSON *enable_environment = loader_cJSON_GetObjectItem(layer_node, "enable_environment");
27452745

27462746
// enable_environment is optional
2747-
if (enable_environment && enable_environment->child && enable_environment->child->type == cJSON_String) {
2747+
if (enable_environment && enable_environment->child && enable_environment->child->type == cJSON_String &&
2748+
enable_environment->child->string && enable_environment->child->valuestring) {
27482749
result = loader_copy_to_new_str(inst, enable_environment->child->string, &(props.enable_env_var.name));
27492750
if (VK_SUCCESS != result) goto out;
27502751
result = loader_copy_to_new_str(inst, enable_environment->child->valuestring, &(props.enable_env_var.value));

tests/loader_fuzz_tests.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ TEST(BadJsonInput, ClusterFuzzTestCase_6308459683315712) {
109109
// combine_settings_layers_with_regular_layers
110110
execute_instance_enumerate_fuzzer("clusterfuzz-testcase-instance_enumerate_fuzzer-6308459683315712");
111111
}
112+
TEST(BadJsonInput, ClusterFuzzTestCase_6583684169269248) {
113+
// Crashes ASAN
114+
// Nullptr dereference in loader_copy_to_new_str
115+
execute_instance_enumerate_fuzzer("clusterfuzz-testcase-minimized-instance_enumerate_fuzzer-6583684169269248");
116+
}
117+
112118
TEST(BadJsonInput, ClusterFuzzTestCase_5258042868105216) {
113119
// Doesn't crash with ASAN or UBSAN
114120
// Doesn't reproducibly crash - json_load_fuzzer: Abrt in loader_cJSON_Delete

0 commit comments

Comments
 (0)