interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / seed / qualification / security673 / packet-corpus.om

166 lines · 2748 bytes Raw Blame History
1note Synthetic issue #671 packed-list corpus. Reads one mode byte and writes one packet to stdout.
2note Format (OMEGESE, exec packed list): u16le count 1..1024, then count records of u16le length and
3note bytes; whole packet at most 65536 bytes; first record nonempty; no zero byte; no trailing bytes.
4note Accepted modes 0 8 11 12. Every other mode breaks exactly the rule named beside it and must
5note be refused with trap 3 before any kernel exec. Unknown modes exit 92; I/O failures 90 and 91.
6global pkt uchar 131072
7global n ulong 1
8text path "/bin/true"
9text echo "/bin/echo"
10text word1 "packed"
11text word2 "list"
12fn emitb v uchar to void
13put pkt get n 0 v
14put n 0 add get n 0 1
15end
16fn put16 v ulong to void
17emitb uchar and v 255
18emitb uchar shr v 8
19end
20fn pfill v uchar k ulong to void
21for i ulong k
22emitb v
23end
24end
25fn rawtrue to void
26for i ulong len path
27emitb get path i
28end
29end
30fn rectrue to void
31put16 len path
32rawtrue
33end
34fn rececho to void
35put16 len echo
36for i ulong len echo
37emitb get echo i
38end
39put16 len word1
40for i ulong len word1
41emitb get word1 i
42end
43put16 len word2
44for i ulong len word2
45emitb get word2 i
46end
47end
48fn modea m ulong to void
49note 0 valid single record; 1 count 0; 2 count 1025 without records; 3 record declares 5, has 3.
50if eq m 0
51put16 1
52rectrue
53end
54if eq m 1
55put16 0
56end
57if eq m 2
58put16 1025
59end
60if eq m 3
61put16 1
62put16 5
63emitb 97
64emitb 98
65emitb 99
66end
67note 4 trailing byte; 5 empty first record; 6 zero byte inside the path.
68if eq m 4
69put16 1
70rectrue
71emitb 0
72end
73if eq m 5
74put16 1
75put16 0
76end
77if eq m 6
78put16 1
79put16 len path
80for i ulong len path
81if eq i 7
82emitb 0
83else
84emitb get path i
85end
86end
87end
88note 7 record declares 4093 bytes and the 4096-byte packet holds 4092.
89if eq m 7
90put16 1
91put16 4093
92pfill 97 4092
93end
94end
95fn modeb m ulong to void
96note 8 valid 1024 records (path plus 1023 empty arguments); 9 count 1025 with 1025 well-formed records.
97if eq m 8
98put16 1024
99rectrue
100for i ulong 1023
101put16 0
102end
103end
104if eq m 9
105put16 1025
106rectrue
107for i ulong 1024
108put16 0
109end
110end
111note 10 well-formed 65537-byte packet (one byte over); 11 well-formed 65536-byte packet.
112if eq m 10
113put16 2
114rectrue
115put16 65522
116pfill 97 65522
117end
118if eq m 11
119put16 2
120rectrue
121put16 65521
122pfill 97 65521
123end
124note 12 valid echo packet; 13 zero byte after a valid path; 14 count 65535; 15 length 65535.
125if eq m 12
126put16 3
127rececho
128end
129if eq m 13
130put16 1
131put16 11
132rawtrue
133emitb 0
134emitb 120
135end
136if eq m 14
137put16 65535
138end
139if eq m 15
140put16 1
141put16 65535
142emitb 97
143emitb 98
144end
145end
146fn main to int
147if ne read 0 pkt 0 1 1
148ret 90
149end
150m = ulong get pkt 0
151if gt m 15
152ret 92
153end
154put n 0 0
155modea m
156modeb m
157done = ulong 0
158while lt done get n 0 bound 131073
159r = write 1 pkt done sub get n 0 done
160if le r 0
161ret 91
162end
163done = add done ulong r
164end
165ret 0
166end