From bfdab448cc0ab86e38bfe4dadd653a0a30cb29bc Mon Sep 17 00:00:00 2001 From: YLChen-007 <1561316811@qq.com> Date: Mon, 13 Apr 2026 15:56:13 +0800 Subject: [PATCH] Fix null pointer dereference in DependencyInfoDumpingHandler Add a null check for the return value of GetOutputStream() in dependency_info.cc before dereferencing the stream pointer. When GetOutputStream() fails to open the output file (e.g., due to permission errors, full disk, or non-existent directory), it returns nullptr. The code previously unconditionally dereferenced this pointer, causing a segmentation fault (SIGSEGV). This is the same vulnerability pattern that was fixed in file_compiler.cc (commit 1d97901), but was missed in the dependency_info.cc code path. The fix follows the identical pattern: check the pointer for null before use and return false on failure. Bug: Null pointer dereference when glslc is invoked with -MD flag and the dependency info output file cannot be opened for writing. --- glslc/src/dependency_info.cc | 4 ++++ glslc/test/option_dash_M.py | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/glslc/src/dependency_info.cc b/glslc/src/dependency_info.cc index 2f1ef2f4a..1ba3afb9c 100644 --- a/glslc/src/dependency_info.cc +++ b/glslc/src/dependency_info.cc @@ -50,6 +50,10 @@ bool DependencyInfoDumpingHandler::DumpDependencyInfo( std::ofstream potential_file_stream_for_dep_info_dump; std::ostream* dep_file_stream = shaderc_util::GetOutputStream( dep_file_name, &potential_file_stream_for_dep_info_dump, &std::cerr); + if (!dep_file_stream) { + // An error message has already been emitted to the stderr stream. + return false; + } *dep_file_stream << dep_string_stream.str(); if (dep_file_stream->fail()) { std::cerr << "glslc: error: error writing dependent_files info to output " diff --git a/glslc/test/option_dash_M.py b/glslc/test/option_dash_M.py index e32ff0720..39091c0d4 100644 --- a/glslc/test/option_dash_M.py +++ b/glslc/test/option_dash_M.py @@ -752,3 +752,13 @@ class TestErrorMissingDependencyTargetName(expect.StderrMatch): glslc_args = ['target', 'shader.vert', '-c', '-MT'] expected_stderr = ['glslc: error: ' 'missing dependency info target after \'-MT\'\n'] + + +@inside_glslc_testsuite('OptionsCapM') +class TestErrorDashMFUnwritableFile(expect.ErrorMessageSubstr): + """Tests that when we fail to make an output dependency file, glslc + fails gracefully and emits an error message instead of crashing.""" + environment = EMPTY_SHADER_IN_CURDIR + bad_file = '/file/should/not/exist/today.d' + glslc_args = ['-MD', '-MF', bad_file, 'shader.vert'] + expected_error_substr = ['cannot open output file']