diff --git a/core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp b/core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp index 3ce5e70cb700..0868716b3515 100644 --- a/core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp +++ b/core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp @@ -308,6 +308,9 @@ RelinkResult RelinkerPipeline::Relink() { if (symOff < dynSymTabOffset || symOff > raw.size() || raw.size() - symOff < symEntSize || (dynSymTabSize && (off > *dynSymTabSize || symEntSize > *dynSymTabSize - off))) throw RelinkerException("Symbol table entry out of bounds", symOff); + if (symIdx == 0 && std::any_of(raw.begin() + static_cast(symOff), raw.begin() + static_cast(symOff + symEntSize), + [](const std::uint8_t byte) { return byte != 0; })) + throw RelinkerException("Dynamic symbol table entry 0 is not a null symbol entry", symOff); return symOff; }; diff --git a/core/relinker/relinker/tests/test_null_symbol_relocations.py b/core/relinker/relinker/tests/test_null_symbol_relocations.py index 99f436b7b726..6e9f22b35207 100644 --- a/core/relinker/relinker/tests/test_null_symbol_relocations.py +++ b/core/relinker/relinker/tests/test_null_symbol_relocations.py @@ -82,6 +82,21 @@ def main(): capture_output=True, text=True, timeout=20) assert result.returncode == 2 and "Unnamed import symbol is not a null symbol entry" in result.stderr, (target, result.stderr) assert not output.exists() + named_null = image_with(index=0) + names = b"\0foo\0libfoo.prx\0" + named_null[0x600:0x600 + len(names)] = names + struct.pack_into("