Disallow NUL characters in section names and assertion messages

Allowing these in object files would lose anything after the '\0'
when RGBLINK reads the object.
This commit is contained in:
Rangi
2026-08-22 19:51:03 -04:00
parent 21a4b85a4f
commit a2c52caca2
7 changed files with 16 additions and 1 deletions
+4
View File
@@ -162,6 +162,10 @@ void out_CreatePatch(uint32_t type, Expression const &expr, uint32_t ofs, uint32
void out_CreateAssert(
AssertionType type, Expression const &expr, std::string const &message, uint32_t ofs
) {
if (message.find('\0') != std::string::npos) {
fatal("Assertion messages cannot contain '\\0' characters");
}
Assertion &assertion = assertions.emplace_front();
initPatch(assertion.patch, type, expr, ofs);
+4
View File
@@ -544,6 +544,10 @@ void sect_NewSection(
SectionSpec const &attrs,
SectionModifier mod
) {
if (name.find('\0') != std::string::npos) {
fatal("Section names cannot contain '\\0' characters");
}
for (SectionStackEntry &entry : sectionStack) {
if (entry.section && entry.section->name == name) {
fatal("Section \"%s\" is already on the stack", name.c_str());
+1
View File
@@ -0,0 +1 @@
assert x, "oops \0 null"
+2
View File
@@ -0,0 +1,2 @@
FATAL: Assertion messages cannot contain '\0' characters
at assert-nul.asm(1)
+2
View File
@@ -0,0 +1,2 @@
SECTION "test\0 foo", ROM0
SECTION "test\0 bar", ROM0
+2
View File
@@ -0,0 +1,2 @@
FATAL: Section names cannot contain '\0' characters
at section-name-nul.asm(1)
+1 -1
View File
@@ -7,4 +7,4 @@ SECTION "ROM2 1K", ROMX,BANK[2]
ds $1000
SECTION "ROM2 1", ROMX,BANK[2]
ds 1
SECTION "\\\"\'\n\r\t\0", ROM0
SECTION "\\\"\'\n\r\t", ROM0