From bcb0e1989421eed85fdabed91fac8b39840b1a94 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Mon, 26 Oct 2026 15:42:06 -0500 Subject: [PATCH] seed/omc: refuse an empty text (error 8) An empty `text X ""` got nm_len 0, which is also the unsized-view marker, so passing it as a view argument read its count from a register never set (exit 28 on 2c824805) and `get` was bounds-checked against garbage (exit 103). Refuse it with error 8, as an array of length 0. Source only; reseed in batch 3. Reported by BabelCLI. Signed-off-by: Drake Stapleton --- docs/one_layer/OMEGESE.md | 3 ++- seed/omc/om2/s1/bad-text-empty-get.om | 5 +++++ seed/omc/om2/s1/bad-text-empty.om | 8 ++++++++ seed/omc/om2/s1/s1.cases | 5 +++++ seed/omc/om2/s1/text-one-view.om | 8 ++++++++ seed/omc/omc.om | 7 ++++++- 6 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 seed/omc/om2/s1/bad-text-empty-get.om create mode 100644 seed/omc/om2/s1/bad-text-empty.om create mode 100644 seed/omc/om2/s1/text-one-view.om diff --git a/docs/one_layer/OMEGESE.md b/docs/one_layer/OMEGESE.md index 119c55955..d04b98519 100644 --- a/docs/one_layer/OMEGESE.md +++ b/docs/one_layer/OMEGESE.md @@ -456,7 +456,8 @@ gate that tests it (`seed/rung4/gate4.sh`, section numbers of that script). Deci Program mode only (error 9). (s.6 echo, bytecopy, s.7) - `text NAME "bytes"`: a read-only array of uchar holding the bytes between the quotes, with its length; `\n` is 10, `\t` is 9, `\\` is 92, `\"` is 34; any other escape, or a quote missing its end, - is error 22. Program mode only. (s.7) + is error 22. At least one byte: an empty text `""` is error 8, like an array of length 0. Program mode + only. (s.7) - `NAME = new T N v`: a local array of N elements, each v, on the stack, given back when the function returns. Only in a function's outermost block (error 9); at most 4 MiB of local arrays (error 23). There is no `free`: nothing is given back by hand (decision 24), and the word is refused (error 9). diff --git a/seed/omc/om2/s1/bad-text-empty-get.om b/seed/omc/om2/s1/bad-text-empty-get.om new file mode 100644 index 000000000..8e7cff7c4 --- /dev/null +++ b/seed/omc/om2/s1/bad-text-empty-get.om @@ -0,0 +1,5 @@ +om2 +text Em "" +fn main to int +ret int get Em 5 +end diff --git a/seed/omc/om2/s1/bad-text-empty.om b/seed/omc/om2/s1/bad-text-empty.om new file mode 100644 index 000000000..288260561 --- /dev/null +++ b/seed/omc/om2/s1/bad-text-empty.om @@ -0,0 +1,8 @@ +om2 +text Em "" +fn f s view uchar * to ulong +ret len s +end +fn main to int +ret int f Em +end diff --git a/seed/omc/om2/s1/s1.cases b/seed/omc/om2/s1/s1.cases index c0dd85b7e..0b430e9fc 100644 --- a/seed/omc/om2/s1/s1.cases +++ b/seed/omc/om2/s1/s1.cases @@ -54,3 +54,8 @@ s1-bad-fmt-compile emit seed/omc/om2/s1/bad-fmt-compile.om - err:3:5 5 s1-diag-newpt emit seed/omc/om2/s1/diag-newpt.om - file:seed/omc/om2/s1/diag-newpt.err 16 s1-diag-viewpt emit seed/omc/om2/s1/diag-viewpt.om - file:seed/omc/om2/s1/diag-viewpt.err 16 s1-bad-fmt-crtext emit seed/omc/om2/s1/bad-fmt-crtext.om - err:4:6 6 +# regression (BabelCLI 2026-10-26): an empty text has nm_len 0, the unsized-view marker, so a view argument +# got a stray count and `get` was checked against a register never set. Now error 8, as a zero-length array. +s1-bad-text-empty refuse seed/omc/om2/s1/bad-text-empty.om 8 +s1-bad-text-empty-get refuse seed/omc/om2/s1/bad-text-empty-get.om 8 +s1-text-one-view run seed/omc/om2/s1/text-one-view.om - - - 1 diff --git a/seed/omc/om2/s1/text-one-view.om b/seed/omc/om2/s1/text-one-view.om new file mode 100644 index 000000000..bfcdf3cbd --- /dev/null +++ b/seed/omc/om2/s1/text-one-view.om @@ -0,0 +1,8 @@ +om2 +text One "a" +fn f s view uchar * to ulong +ret len s +end +fn main to int +ret int f One +end diff --git a/seed/omc/omc.om b/seed/omc/omc.om index eed86971c..421731c3f 100644 --- a/seed/omc/omc.om +++ b/seed/omc/omc.om @@ -6987,7 +6987,9 @@ eol end note s_text: text NAME "...": read-only bytes in the program image (escapes \n \t \\ \", any other is error -note 22), padded to a word, with their length; address 0x400000 + its place. om4 S_TEXT. +note 22), padded to a word, with their length; address 0x400000 + its place. om4 S_TEXT. An empty text is +note error 8, like a zero-length array: nm_len 0 marks an unsized view, so its count would be read from a +note register it never set (a view argument got a stray length, indexing checked against garbage). fn s_text to void w = topname tok @@ -7028,6 +7030,9 @@ end m = add m 1 end end +if eq n 0 +fail 8 +end while ne and get oc 0 3 0 emitb 0 end