Skip to content

Commit d9b3078

Browse files
committed
Prevent labels with an empty name from being accepted, and some tests associated with that change.
1 parent 816d0ad commit d9b3078

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

redox-parser/src/asm_parser.rs

+10
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ impl<'a> AsmParser<'a> {
128128
// Are we dealing with a label marker?
129129
// These are found at the start of a line and act as a target for branching instructions.
130130
if raw_args[0].starts_with(':') {
131+
if raw_args[0].len() == 1 {
132+
panic!("invalid syntax - a label designator without a name!");
133+
}
134+
131135
let ins = Instruction::Label(raw_args[0].to_string());
132136
instructions.push(ins);
133137
continue;
@@ -263,6 +267,10 @@ impl<'a> AsmParser<'a> {
263267
// address at compile time. For now we'll use dummy values and keep track of the
264268
// used labels for reference later.
265269
if substring.starts_with(':') {
270+
if substring.len() == 1 {
271+
panic!("invalid syntax - a label designator without a name!");
272+
}
273+
266274
self.labeled_instructions.insert(i, substring.to_string());
267275

268276
// We want to insert a dummy 32-bit address argument for now.
@@ -1029,6 +1037,8 @@ mod tests_asm_parsing {
10291037
false,
10301038
"failed to correctly parse label instruction.",
10311039
),
1040+
ParserTest::new(":", &[], true, "succeeded in parsing an empty label."),
1041+
ParserTest::new("call :", &[], true, "succeeded in parsing an empty label."),
10321042
];
10331043

10341044
ParserTests::new(&tests).run_all();

0 commit comments

Comments
 (0)