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 / qualification / security673 / resources / negative.om
| 1 | note Exact-once source mutator. stdin original module; stdout mutated module. |
| 2 | note argv1=1..4 mutates ep_event for that event only;5 mutates rv_reserve rollback. |
| 3 | note Compile emitted module with UNCHANGED checks.om and demo.om. Expected exits7/4. |
| 4 | note Reject missing/duplicate pattern, oversized source and I/O errors normally. |
| 5 | global source uchar 16384 |
| 6 | global needle uchar 256 |
| 7 | global params ulong 2 |
| 8 | global arg uchar 8 |
| 9 | text epfind "if or lt event 1 gt event 4\nret 1\nend\nret 0\nend\n" |
| 10 | text rvfind "for d ulong 8\nif gt get q d rv_room s d\nret 3\nend\nend\n" |
| 11 | text eppre "if or lt event 1 gt event 4\nret 1\nend\nif eq event " |
| 12 | text eppost "\nput e 4 0\nend\nret 0\nend\n" |
| 13 | text rvbad "for d ulong 8\nif gt get q d rv_room s d\nret 3\nend\nput s add rv_charge j d get q d\nend\n" |
| 14 | fn choose mode ulong to void |
| 15 | if eq mode 5 |
| 16 | put params 1 len rvfind |
| 17 | for i ulong len rvfind |
| 18 | put needle i get rvfind i |
| 19 | end |
| 20 | else |
| 21 | put params 1 len epfind |
| 22 | for i ulong len epfind |
| 23 | put needle i get epfind i |
| 24 | end |
| 25 | end |
| 26 | end |
| 27 | fn matches at ulong to bool |
| 28 | for i ulong get params 1 |
| 29 | if ne get source add at i get needle i |
| 30 | ret false |
| 31 | end |
| 32 | end |
| 33 | ret true |
| 34 | end |
| 35 | fn input to bool |
| 36 | size = ulong 0 |
| 37 | while lt size len source bound 16384 |
| 38 | n = read 0 source size sub len source size |
| 39 | if lt n 0 |
| 40 | ret false |
| 41 | end |
| 42 | if eq n 0 |
| 43 | put params 0 size |
| 44 | ret true |
| 45 | end |
| 46 | size = add size ulong n |
| 47 | end |
| 48 | ret false |
| 49 | end |
| 50 | fn replacement mode ulong to bool |
| 51 | if eq mode 5 |
| 52 | ret eq write 1 rvbad 0 len rvbad long len rvbad |
| 53 | end |
| 54 | if ne write 1 eppre 0 len eppre long len eppre |
| 55 | ret false |
| 56 | end |
| 57 | if ne write 1 arg 0 1 1 |
| 58 | ret false |
| 59 | end |
| 60 | ret eq write 1 eppost 0 len eppost long len eppost |
| 61 | end |
| 62 | fn main to int |
| 63 | if ne argcnt 2 |
| 64 | ret 2 |
| 65 | end |
| 66 | if ne argread 1 arg 0 8 1 |
| 67 | ret 2 |
| 68 | end |
| 69 | mode = ulong get arg 0 |
| 70 | if or lt mode 49 gt mode 53 |
| 71 | ret 2 |
| 72 | end |
| 73 | mode = sub mode 48 |
| 74 | choose mode |
| 75 | if not input |
| 76 | ret 3 |
| 77 | end |
| 78 | if lt get params 0 get params 1 |
| 79 | ret 4 |
| 80 | end |
| 81 | count = ulong 0 |
| 82 | found = ulong 0 |
| 83 | for at ulong add sub get params 0 get params 1 1 |
| 84 | if matches at |
| 85 | count = add count 1 |
| 86 | found = at |
| 87 | end |
| 88 | end |
| 89 | if ne count 1 |
| 90 | ret 4 |
| 91 | end |
| 92 | if ne write 1 source 0 found long found |
| 93 | ret 5 |
| 94 | end |
| 95 | if not replacement mode |
| 96 | ret 5 |
| 97 | end |
| 98 | start = add found get params 1 |
| 99 | size = sub get params 0 start |
| 100 | if ne write 1 source start size long size |
| 101 | ret 5 |
| 102 | end |
| 103 | ret 0 |
| 104 | end |