Skip to content

Commit bfdab44

Browse files
committed
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.
1 parent 42c364e commit bfdab44

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

glslc/src/dependency_info.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ bool DependencyInfoDumpingHandler::DumpDependencyInfo(
5050
std::ofstream potential_file_stream_for_dep_info_dump;
5151
std::ostream* dep_file_stream = shaderc_util::GetOutputStream(
5252
dep_file_name, &potential_file_stream_for_dep_info_dump, &std::cerr);
53+
if (!dep_file_stream) {
54+
// An error message has already been emitted to the stderr stream.
55+
return false;
56+
}
5357
*dep_file_stream << dep_string_stream.str();
5458
if (dep_file_stream->fail()) {
5559
std::cerr << "glslc: error: error writing dependent_files info to output "

glslc/test/option_dash_M.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,3 +752,13 @@ class TestErrorMissingDependencyTargetName(expect.StderrMatch):
752752
glslc_args = ['target', 'shader.vert', '-c', '-MT']
753753
expected_stderr = ['glslc: error: '
754754
'missing dependency info target after \'-MT\'\n']
755+
756+
757+
@inside_glslc_testsuite('OptionsCapM')
758+
class TestErrorDashMFUnwritableFile(expect.ErrorMessageSubstr):
759+
"""Tests that when we fail to make an output dependency file, glslc
760+
fails gracefully and emits an error message instead of crashing."""
761+
environment = EMPTY_SHADER_IN_CURDIR
762+
bad_file = '/file/should/not/exist/today.d'
763+
glslc_args = ['-MD', '-MF', bad_file, 'shader.vert']
764+
expected_error_substr = ['cannot open output file']

0 commit comments

Comments
 (0)