omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / seed / tilelab / parser_mutant.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note Host-only negative control: remove exactly one parser guard from source on stdin. |
| 3 | note Mode 1 removes overflow refusal; mode 2 removes malformed-REGS propagation. |
| 4 | om2 |
| 5 | text over "if gt v div sub ulong 0xffffffffffffffff digit 10" |
| 6 | text status "if ne get argbad 0 0" |
| 7 | text repl "if false" |
| 8 | global source uchar 65536 |
| 9 | global arg uchar 1 |
| 10 | fn matches pos ulong mode uchar to bool |
| 11 | if eq mode 49 |
| 12 | if gt add pos len over len source |
| 13 | ret false |
| 14 | end |
| 15 | for j ulong len over |
| 16 | if ne get source add pos j get over j |
| 17 | ret false |
| 18 | end |
| 19 | end |
| 20 | ret true |
| 21 | end |
| 22 | if gt add pos len status len source |
| 23 | ret false |
| 24 | end |
| 25 | for j ulong len status |
| 26 | if ne get source add pos j get status j |
| 27 | ret false |
| 28 | end |
| 29 | end |
| 30 | ret true |
| 31 | end |
| 32 | fn emit off ulong n ulong to void |
| 33 | pos = ulong 0 |
| 34 | while lt pos n bound 65536 |
| 35 | r = write 1 source add off pos sub n pos |
| 36 | if le r 0 |
| 37 | exit 4 |
| 38 | end |
| 39 | pos = add pos ulong r |
| 40 | end |
| 41 | end |
| 42 | fn main to int |
| 43 | if ne argcnt 2 |
| 44 | ret 2 |
| 45 | end |
| 46 | r = argread 1 arg 0 1 |
| 47 | if ne r 1 |
| 48 | ret 2 |
| 49 | end |
| 50 | mode = get arg 0 |
| 51 | if and ne mode 49 ne mode 50 |
| 52 | ret 2 |
| 53 | end |
| 54 | n = ulong 0 |
| 55 | while lt n len source bound 65536 |
| 56 | r = read 0 source n sub len source n |
| 57 | if lt r 0 |
| 58 | ret 3 |
| 59 | end |
| 60 | if eq r 0 |
| 61 | break |
| 62 | end |
| 63 | n = add n ulong r |
| 64 | end |
| 65 | if eq n len source |
| 66 | ret 3 |
| 67 | end |
| 68 | found = ulong 0 |
| 69 | where = ulong 0 |
| 70 | for i ulong n |
| 71 | if matches i mode |
| 72 | found = add found 1 |
| 73 | where = i |
| 74 | end |
| 75 | end |
| 76 | if ne found 1 |
| 77 | ret 5 |
| 78 | end |
| 79 | size = len status |
| 80 | if eq mode 49 |
| 81 | size = len over |
| 82 | end |
| 83 | emit 0 where |
| 84 | r = write 1 repl 0 len repl |
| 85 | if ne r long len repl |
| 86 | ret 4 |
| 87 | end |
| 88 | emit add where size sub n add where size |
| 89 | ret 0 |
| 90 | end |