Fix: EEVEE: Potential Read From Unallocated Memory

Generated copies of GLSL sources are kept in a std::string and
it was always accessed by a long living StringRefNull which lead
to potential read from unallocated memory as std::strings are
not null terminated.

Pull Request: https://projects.blender.org/blender/blender/pulls/117120
This commit is contained in:
Jeroen Bakker
2024-01-15 08:27:17 +01:00
parent 299e112d1a
commit f4632e1da0
2 changed files with 9 additions and 4 deletions

View File

@@ -1459,11 +1459,11 @@ GLSource::GLSource(const char *other)
{
if (!gpu_shader_dependency_get_filename_from_source_string(other).is_empty()) {
source = "";
source_ref = StringRefNull(other);
source_ref = other;
}
else {
source = other;
source_ref = StringRefNull(source);
source_ref = nullptr;
}
}
@@ -1490,7 +1490,12 @@ Vector<const char *> GLSources::sources_get() const
result.reserve(size());
for (const GLSource &source : *this) {
result.append(source.source_ref.c_str());
if (source.source_ref) {
result.append(source.source_ref);
}
else {
result.append(source.source.c_str());
}
}
return result;
}

View File

@@ -45,7 +45,7 @@ namespace gpu {
*/
struct GLSource {
std::string source;
StringRefNull source_ref;
const char *source_ref;
GLSource() = default;
GLSource(const char *other_source);