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 / pkt-consumer.om
| 1 | note Synthetic issue #671 packed-list consumer. Hostile stdin bytes reach execprog unchanged. |
| 2 | note With one decimal argument K, only the first K bytes are passed (truncation at each boundary). |
| 3 | note A malformed packet traps 3 (exit 103) inside execprog; a valid one replaces this process. |
| 4 | note Own exits: 90 usage or bad K, 91 read failure or input over 131071 bytes, 95 exec failed. |
| 5 | global pkt uchar 131072 |
| 6 | global arg uchar 8 |
| 7 | fn rdall to long |
| 8 | note Every pass but the last adds at least one byte to the 131072-byte buffer: 131073 passes bound it. |
| 9 | n = ulong 0 |
| 10 | k = long 1 |
| 11 | while gt k 0 bound 131073 |
| 12 | if eq n len pkt |
| 13 | ret -1 |
| 14 | end |
| 15 | k = read 0 pkt n sub len pkt n |
| 16 | if gt k 0 |
| 17 | n = add n ulong k |
| 18 | end |
| 19 | end |
| 20 | if lt k 0 |
| 21 | ret k |
| 22 | end |
| 23 | ret long n |
| 24 | end |
| 25 | fn argk to long |
| 26 | r = argread 1 arg 0 len arg |
| 27 | if lt r 1 |
| 28 | ret -1 |
| 29 | end |
| 30 | if gt r 5 |
| 31 | ret -1 |
| 32 | end |
| 33 | v = ulong 0 |
| 34 | for i ulong ulong r |
| 35 | c = get arg i |
| 36 | if lt c 48 |
| 37 | ret -1 |
| 38 | end |
| 39 | if gt c 57 |
| 40 | ret -1 |
| 41 | end |
| 42 | v = add mul v 10 ulong sub c 48 |
| 43 | end |
| 44 | ret long v |
| 45 | end |
| 46 | fn main to int |
| 47 | if gt argcnt 2 |
| 48 | ret 90 |
| 49 | end |
| 50 | t = rdall |
| 51 | if lt t 0 |
| 52 | ret 91 |
| 53 | end |
| 54 | k = ulong t |
| 55 | if eq argcnt 2 |
| 56 | a = argk |
| 57 | if lt a 0 |
| 58 | ret 90 |
| 59 | end |
| 60 | if gt a t |
| 61 | ret 90 |
| 62 | end |
| 63 | k = ulong a |
| 64 | end |
| 65 | r = execprog pkt 0 k |
| 66 | if ge r 0 |
| 67 | ret 96 |
| 68 | end |
| 69 | ret 95 |
| 70 | end |