Skip to content

Commit 0c5b4fb

Browse files
fix: add null pointer checks for fopen calls in vulkan-shaders-gen.cpp
- Add null checks for fopen calls in write_output_files function - Prevents null pointer dereference vulnerabilities Addresses 2 null pointer dereference vulnerabilities (CWE-476) Co-Authored-By: Jake Cosme <[email protected]>
1 parent 680d493 commit 0c5b4fb

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

ggml/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,16 @@ void process_shaders() {
752752

753753
void write_output_files() {
754754
FILE* hdr = fopen(target_hpp.c_str(), "w");
755+
if (hdr == nullptr) {
756+
std::cerr << "Error opening header file: " << target_hpp << " (" << strerror(errno) << ")\n";
757+
return;
758+
}
755759
FILE* src = fopen(target_cpp.c_str(), "w");
760+
if (src == nullptr) {
761+
std::cerr << "Error opening source file: " << target_cpp << " (" << strerror(errno) << ")\n";
762+
fclose(hdr);
763+
return;
764+
}
756765

757766
fprintf(hdr, "#include <cstdint>\n\n");
758767
fprintf(src, "#include \"%s\"\n\n", basename(target_hpp).c_str());

0 commit comments

Comments
 (0)