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 / si / inquisitor / lib.om

2361 lines · 46370 bytes Raw Blame History
1note si/inquisitor/lib.om: pure-Omega automated code gatekeeper and diff/audit scanner
2note Faithful port of spark-inquisitor (DiffAuditor + ConstitutionalChecker) plus
3note omega-mv governance rules (protected paths, dirty-tree, NOT_RUN-as-PASS, stubs).
4note Composed after si/directives/om2.om; no om2 header and no fn main in this unit.
5
6const SEV_PASS ulong 0
7const SEV_WARN ulong 1
8const SEV_BLOCK ulong 2
9
10const RULE_SECRET ulong 0
11const RULE_ENV_FILE ulong 1
12const RULE_PROTECTED_PATH ulong 2
13const RULE_DIRTY_TREE ulong 3
14const RULE_FALSE_PASS ulong 4
15const RULE_TELEMETRY ulong 5
16const RULE_STUB_HARD ulong 6
17const RULE_TODO_WARN ulong 7
18const RULE_UNSLOP_WARN ulong 8
19
20const SUB_AWS_KEY ulong 1
21const SUB_GH_PAT ulong 2
22const SUB_PRIV_KEY ulong 3
23const SUB_SECRET_ASSIGN ulong 4
24const SUB_ENV_FILE ulong 5
25const SUB_PATH_EVIDENCE ulong 6
26const SUB_PATH_AIEN ulong 7
27const SUB_PATH_GATES ulong 8
28const SUB_PATH_CI ulong 9
29const SUB_DIRTY_TREE ulong 10
30const SUB_FALSE_PASS_INLINE ulong 11
31const SUB_FALSE_PASS_RECORD ulong 12
32const SUB_TELEM_VENDOR ulong 13
33const SUB_TELEM_RAW ulong 14
34const SUB_STUB_HARD ulong 15
35const SUB_TODO_WARN ulong 16
36const SUB_UNSLOP_DASH ulong 17
37const SUB_UNSLOP_BUZZ ulong 18
38const SUB_PATH_AIEN_TEST ulong 19
39
40const INQ_MAX_IN ulong 131072
41const INQ_MAX_OUT ulong 32768
42const INQ_MAX_FIND ulong 128
43
44global inq_in uchar 131072
45global inq_in_len ulong 1
46global inq_out uchar 32768
47global inq_out_len ulong 1
48global inq_pbuf uchar 131072
49global inq_pbuf_off ulong 1
50global inq_pbuf_len ulong 1
51global inq_a_buf uchar 131072
52global inq_a_len ulong 1
53global inq_b_buf uchar 131072
54global inq_b_len ulong 1
55global inq_is_md ulong 1
56global inq_tmp_off ulong 1
57global inq_tmp_len ulong 1
58global inq_num_val ulong 1
59global inq_num_pos ulong 1
60global inq_num_ok ulong 1
61
62global inq_verdict ulong 1
63global inq_blocks ulong 1
64global inq_warns ulong 1
65global inq_files ulong 1
66global inq_lines ulong 1
67global inq_added ulong 1
68global inq_rcnt ulong 16
69
70global inq_find_cnt ulong 1
71global inq_find_rule ulong 128
72global inq_find_sev ulong 128
73global inq_find_line ulong 128
74global inq_find_sub ulong 128
75
76global inq_in_bin ulong 1
77global inq_in_hunk ulong 1
78global inq_hunk_has_cnt ulong 1
79global inq_hunk_old ulong 1
80global inq_hunk_new ulong 1
81global inq_expect_plus ulong 1
82global inq_has_git_hdr ulong 1
83global inq_in_git_body ulong 1
84global inq_skip_file ulong 1
85global inq_diff_checked ulong 1
86global inq_seen_notrun ulong 1
87global inq_seen_pass ulong 1
88global inq_rec_flagged ulong 1
89global inq_hash ulong 1
90
91text inq_hex "0123456789abcdef"
92
93note Diff header prefixes
94text p_diff_git "diff --git "
95text p_plus3 "+++ "
96text p_minus3 "--- "
97text p_hunk "@@ "
98text p_hunk3 "@@@ "
99text p_bin_files "Binary files "
100text p_git_bin "GIT binary patch"
101text p_file_rec "FILE: "
102text p_dev_null "/dev/null"
103text p_b_slash "b/"
104text p_a_slash "a/"
105text p_sp_b_slash " b/"
106text p_sp_qb_slash " \"b/"
107text p_sp_and_sp " and "
108text p_sp_and_b " and b/"
109text p_sp_and_qb " and \"b/"
110text p_sp_and_dev " and /dev/null"
111text p_sp_differ " differ"
112text p_colon_sp ": "
113text p_ren_from "rename from "
114text p_ren_to "rename to "
115text p_cpy_from "copy from "
116text p_cpy_to "copy to "
117text p_hdr_idx "index "
118text p_hdr_omode "old mode "
119text p_hdr_nmode "new mode "
120text p_hdr_nfmode "new file mode "
121text p_hdr_dfmode "deleted file mode "
122text p_hdr_sim "similarity index "
123text p_hdr_dis "dissimilarity index "
124
125note Self-exclusion paths for non-secret rule literals (DRA-440: never exempt from secrets scanning)
126text p_self_inq "spark-inquisitor"
127text p_self_con "constitution.rs"
128
129note Protected path patterns
130text p_env ".env"
131text p_env_dot ".env."
132text p_evid_pre "evidence/"
133text p_evid_mid "/evidence/"
134text p_aien_pre ".aien/"
135text p_aien_mid "/.aien/"
136text p_gates_pre "tests/gates/"
137text p_gates_mid "/tests/gates/"
138text p_ghwf_pre ".github/workflows/"
139text p_ghwf_mid "/.github/workflows/"
140text p_fgjo_pre ".forgejo/"
141text p_fgjo_mid "/.forgejo/"
142text p_aient_pre "tools/aien-test/"
143text p_aient_mid "/tools/aien-test/"
144text p_ext_md ".md"
145
146note Secret patterns
147text p_akia "AKIA"
148text p_ghp "ghp_"
149text p_gh_fine "github_pat_"
150text p_pem_beg "-----BEGIN "
151text p_pem_end "PRIVATE KEY-----"
152text p_pem_rsa "BEGIN RSA PRIVATE KEY"
153text p_sec_k1 "SECRET_KEY="
154text p_sec_k2 "API_KEY="
155text p_sec_k3 "PRIVATE_KEY="
156text p_sec_k4 "ACCESS_TOKEN="
157text p_redacted "redacted"
158text p_vault "vault"
159
160note Dirty-tree patterns
161text p_dt1 "dirty_tree: true"
162text p_dt2 "dirty_tree=true"
163text p_dt3 "dirty_tree=1"
164text p_dt4 "dirty_tree: 1"
165text p_dt5 "git_status: dirty"
166text p_dt6 "worktree: dirty"
167text p_dt7 "tree_state: dirty"
168text p_dt8 "dirty-tree: true"
169text p_dt9 "status: m "
170text p_dt10 "status: ?? "
171
172note False-PASS (NOT_RUN / SKIPPED labelled PASS) patterns
173text p_pass_w "pass"
174text p_not_run "not_run"
175text p_skipped "skipped"
176text p_blk_hw "blocked_hardware"
177text p_blk_op "blocked_operator"
178text p_miss_impl "missing_implementation"
179text p_zero_tests "0 tests run"
180text p_gs_notrun "gate_state: not_run"
181text p_tr_zero "tests_run: 0"
182text p_ex_zero "executed: 0"
183text p_ts_skip "test_status: skipped"
184text p_ts_notrun "test_status: not_run"
185text p_st_notrun "state: not_run"
186text p_v_pass "verdict: pass"
187text p_c_pass "claim: pass"
188text p_s_pass "status: pass"
189text p_r_pass "reported: pass"
190text p_rec_sep "---"
191
192note Telemetry patterns (upstream audit.rs)
193text p_tel1 "google-analytics"
194text p_tel2 "segment.io"
195text p_tel3 "mixpanel"
196text p_tel4 "sentry.io"
197text p_tel5 "datadog"
198text p_tel6 "tracking_id"
199text p_tel7 "analytics.js"
200text p_tel8 "amplitude.com"
201text p_tel9 "hotjar"
202text p_tel10 "clarity.ms"
203text p_tel11 "send_telemetry"
204text p_tel12 "report_telemetry"
205text p_tel13 "collect_telemetry"
206text p_tel_raw "telemetry"
207text p_tel_ok1 "gpu-telemetry"
208text p_tel_ok2 "zero telemetry"
209text p_tel_ok3 "zero-telemetry"
210text p_tel_ok4 "no telemetry"
211text p_tel_ok5 "no-telemetry"
212text p_tel_ok6 "anti-telemetry"
213text p_tel_ok7 "block telemetry"
214text p_tel_ok8 "telemetryforbidden"
215text p_tel_ok9 "forbid"
216text p_tel_ok10 "reject"
217
218note Stub and TODO markers
219text p_stub1 "unimplemented!("
220text p_stub2 "todo!("
221text p_stub3 "stub_only"
222text p_stub4 "not_implemented"
223text p_stub5 "panic!(\"not implemented"
224text p_todo1 "todo:"
225text p_todo2 "todo("
226text p_todo3 "fixme:"
227text p_todo4 "fixme "
228text p_todo5 "placeholder"
229
230note Unslop buzzword patterns (upstream constitution.rs)
231text p_bz1 "delve"
232text p_bz2 "tapestry"
233text p_bz3 "testament"
234text p_bz4 "crucial"
235text p_bz5 "pivotal"
236text p_bz6 "game-changer"
237text p_bz7 "game changer"
238text p_bz8 "elevate"
239text p_bz8_ok1 "--elevate"
240text p_bz8_ok2 "elevate_"
241text p_bz9 "unleash"
242text p_bz9_ok1 "--unleash"
243text p_bz9_ok2 "unleash_"
244
245note Receipt JSON strings
246text j_head "{\"verdict\":\""
247text j_pass "PASS"
248text j_warn "WARN"
249text j_block "BLOCK"
250text j_sev "\",\"severity\":"
251text j_blk ",\"blocks\":"
252text j_wrn ",\"warns\":"
253text j_fil ",\"files\":"
254text j_lin ",\"lines\":"
255text j_add ",\"added\":"
256text j_r_sec ",\"rules\":{\"secret\":"
257text j_r_env ",\"env_file\":"
258text j_r_pth ",\"protected_path\":"
259text j_r_dty ",\"dirty_tree\":"
260text j_r_fps ",\"false_pass\":"
261text j_r_tel ",\"telemetry\":"
262text j_r_stb ",\"stub\":"
263text j_r_tdo ",\"todo\":"
264text j_r_uns ",\"unslop\":"
265text j_fp "},\"fingerprint\":\""
266text j_fnd "\",\"findings\":["
267text j_f_open "{\"rule\":\""
268text j_f_sev "\",\"severity\":\""
269text j_f_line "\",\"line\":"
270text j_f_det ",\"detail\":\""
271text j_f_close "\"}"
272text j_comma ","
273text j_tail "]}\n"
274
275note Rule name strings
276text rn_secret "secret"
277text rn_env "env_file"
278text rn_path "protected_path"
279text rn_dirty "dirty_tree"
280text rn_fpass "false_pass"
281text rn_telem "telemetry"
282text rn_stub "stub"
283text rn_todo "todo"
284text rn_unslop "unslop"
285text rn_unk "unknown"
286
287note Sub-reason detail strings
288text sd_aws "aws_access_key"
289text sd_gh "github_pat"
290text sd_pem "private_key_pem"
291text sd_assign "plaintext_secret_assign"
292text sd_env "plaintext_env_file"
293text sd_evid "protected_evidence_path"
294text sd_aien "protected_aien_path"
295text sd_gates "protected_gates_path"
296text sd_ci "protected_ci_workflow_path"
297text sd_aient "protected_aien_test_path"
298text sd_dirty "dirty_worktree_flag"
299text sd_fpi "not_run_or_skipped_labelled_pass"
300text sd_fpr "audit_record_pass_with_zero_or_not_run"
301text sd_tv "telemetry_tracker_hook"
302text sd_tr "telemetry_source_indicator"
303text sd_stub "unimplemented_or_stub_marker"
304text sd_todo "todo_or_fixme_marker"
305text sd_dash "unicode_em_or_en_dash"
306text sd_buzz "ai_slop_buzzword"
307text sd_other "policy_violation"
308
309fn inq_to_lower c uchar to uchar
310if and ge c 65 le c 90
311ret add c 32
312end
313ret c
314end
315
316fn inq_is_alnum c uchar to bool
317if and ge c 48 le c 57
318ret true
319end
320if and ge c 65 le c 90
321ret true
322end
323if and ge c 97 le c 122
324ret true
325end
326ret false
327end
328
329fn inq_is_upper_alnum c uchar to bool
330if and ge c 48 le c 57
331ret true
332end
333if and ge c 65 le c 90
334ret true
335end
336ret false
337end
338
339fn inq_is_word c uchar to bool
340if eq c 95
341ret true
342end
343ret inq_is_alnum c
344end
345
346fn inq_fnv_step h ulong b uchar to ulong
347x = xor h ulong b
348ret mul x ulong 0x100000001b3
349end
350
351fn inq_reset to void
352put inq_pbuf_off 0 0
353put inq_pbuf_len 0 0
354put inq_a_len 0 0
355put inq_b_len 0 0
356put inq_is_md 0 0
357put inq_tmp_off 0 0
358put inq_tmp_len 0 0
359put inq_out_len 0 0
360put inq_verdict 0 SEV_PASS
361put inq_blocks 0 0
362put inq_warns 0 0
363put inq_files 0 0
364put inq_lines 0 0
365put inq_added 0 0
366put inq_find_cnt 0 0
367put inq_in_bin 0 0
368put inq_in_hunk 0 0
369put inq_hunk_has_cnt 0 0
370put inq_hunk_old 0 0
371put inq_hunk_new 0 0
372put inq_expect_plus 0 0
373put inq_has_git_hdr 0 0
374put inq_in_git_body 0 0
375put inq_skip_file 0 0
376put inq_diff_checked 0 0
377put inq_seen_notrun 0 0
378put inq_seen_pass 0 0
379put inq_rec_flagged 0 0
380put inq_hash 0 ulong 0xcbf29ce484222325
381for i ulong 16
382put inq_rcnt i 0
383end
384end
385
386fn inq_load_text s view uchar * to ulong
387n = len s
388if gt n INQ_MAX_IN
389n = INQ_MAX_IN
390end
391for i ulong n bound 131072
392put inq_in i get s i
393end
394put inq_in_len 0 n
395ret n
396end
397
398fn inq_record rule ulong sev ulong line_no ulong sub_id ulong to void
399cur_v = get inq_verdict 0
400if gt sev cur_v
401put inq_verdict 0 sev
402end
403if eq sev SEV_BLOCK
404put inq_blocks 0 add get inq_blocks 0 1
405else
406if eq sev SEV_WARN
407put inq_warns 0 add get inq_warns 0 1
408end
409end
410if lt rule 16
411put inq_rcnt rule add get inq_rcnt rule 1
412end
413fc = get inq_find_cnt 0
414if lt fc INQ_MAX_FIND
415put inq_find_rule fc rule
416put inq_find_sev fc sev
417put inq_find_line fc line_no
418put inq_find_sub fc sub_id
419put inq_find_cnt 0 add fc 1
420end
421end
422
423fn inq_starts_cs off ulong nlen ulong pat view uchar * to bool
424pl = len pat
425if lt nlen pl
426ret false
427end
428for i ulong pl bound 128
429if ne get inq_in add off i get pat i
430ret false
431end
432end
433ret true
434end
435
436fn inq_match_cs pos ulong pat view uchar * to bool
437pl = len pat
438for j ulong pl bound 128
439if ne get inq_in add pos j get pat j
440ret false
441end
442end
443ret true
444end
445
446fn inq_match_ci pos ulong pat view uchar * to bool
447pl = len pat
448for j ulong pl bound 128
449c1 = inq_to_lower get inq_in add pos j
450c2 = inq_to_lower get pat j
451if ne c1 c2
452ret false
453end
454end
455ret true
456end
457
458fn inq_contains_cs off ulong nlen ulong pat view uchar * to bool
459pl = len pat
460if or eq pl 0 lt nlen pl
461ret false
462end
463lim = add sub nlen pl 1
464for i ulong lim bound 131072
465if inq_match_cs add off i pat
466ret true
467end
468end
469ret false
470end
471
472fn inq_contains_ci off ulong nlen ulong pat view uchar * to bool
473pl = len pat
474if or eq pl 0 lt nlen pl
475ret false
476end
477lim = add sub nlen pl 1
478for i ulong lim bound 131072
479if inq_match_ci add off i pat
480ret true
481end
482end
483ret false
484end
485
486fn inq_word_ok off ulong nlen ulong i ulong pl ulong to bool
487if gt i 0
488if inq_is_word get inq_in sub add off i 1
489ret false
490end
491end
492end_idx = add i pl
493if lt end_idx nlen
494if inq_is_word get inq_in add off end_idx
495ret false
496end
497end
498ret true
499end
500
501fn inq_contains_word_ci off ulong nlen ulong pat view uchar * to bool
502pl = len pat
503if or eq pl 0 lt nlen pl
504ret false
505end
506lim = add sub nlen pl 1
507for i ulong lim bound 131072
508if inq_word_ok off nlen i pl
509if inq_match_ci add off i pat
510ret true
511end
512end
513end
514ret false
515end
516
517fn inq_find_substr_cs off ulong nlen ulong pat view uchar * to ulong
518pl = len pat
519if or eq pl 0 lt nlen pl
520ret nlen
521end
522lim = add sub nlen pl 1
523for i ulong lim bound 131072
524if inq_match_cs add off i pat
525ret i
526end
527end
528ret nlen
529end
530
531fn inq_find_substr_last_cs off ulong nlen ulong pat view uchar * to ulong
532pl = len pat
533if or eq pl 0 lt nlen pl
534ret nlen
535end
536found = nlen
537lim = add sub nlen pl 1
538for i ulong lim bound 131072
539if inq_match_cs add off i pat
540found = i
541end
542end
543ret found
544end
545
546fn inq_find_quote_end pos ulong end_p ulong to ulong
547p = add pos 1
548while lt p end_p bound 131072
549c = get inq_in p
550if eq c 92
551if lt add p 1 end_p
552p = add p 2
553else
554p = end_p
555end
556else
557if eq c 34
558ret add p 1
559end
560p = add p 1
561end
562end
563ret end_p
564end
565
566fn inq_slice_eq_pat off ulong nlen ulong pat view uchar * to bool
567if ne nlen len pat
568ret false
569end
570for i ulong nlen bound 128
571if ne get inq_in add off i get pat i
572ret false
573end
574end
575ret true
576end
577
578fn inq_slice_eq_in off1 ulong len1 ulong off2 ulong len2 ulong to bool
579if ne len1 len2
580ret false
581end
582for i ulong len1 bound 131072
583if ne get inq_in add off1 i get inq_in add off2 i
584ret false
585end
586end
587ret true
588end
589
590fn inq_pb_eq_pat off ulong nlen ulong pat view uchar * to bool
591if ne nlen len pat
592ret false
593end
594for i ulong nlen bound 128
595if ne get inq_pbuf add off i get pat i
596ret false
597end
598end
599ret true
600end
601
602fn inq_pb_match_ci pos ulong pat view uchar * to bool
603pl = len pat
604for j ulong pl bound 128
605c1 = inq_to_lower get inq_pbuf add pos j
606c2 = inq_to_lower get pat j
607if ne c1 c2
608ret false
609end
610end
611ret true
612end
613
614fn inq_pb_starts_ci off ulong nlen ulong pat view uchar * to bool
615pl = len pat
616if lt nlen pl
617ret false
618end
619for i ulong pl bound 128
620if ne inq_to_lower get inq_pbuf add off i inq_to_lower get pat i
621ret false
622end
623end
624ret true
625end
626
627fn inq_pb_ends_ci off ulong nlen ulong pat view uchar * to bool
628pl = len pat
629if lt nlen pl
630ret false
631end
632base = add off sub nlen pl
633for i ulong pl bound 128
634if ne inq_to_lower get inq_pbuf add base i inq_to_lower get pat i
635ret false
636end
637end
638ret true
639end
640
641fn inq_pb_contains_ci off ulong nlen ulong pat view uchar * to bool
642pl = len pat
643if or eq pl 0 lt nlen pl
644ret false
645end
646lim = add sub nlen pl 1
647for i ulong lim bound 131072
648if inq_pb_match_ci add off i pat
649ret true
650end
651end
652ret false
653end
654
655fn inq_pb_is_env off ulong nlen ulong to bool
656if lt nlen 4
657ret false
658end
659base = ulong 0
660for i ulong nlen bound 131072
661if eq get inq_pbuf add off i 47
662base = add i 1
663end
664end
665blen = sub nlen base
666if lt blen 4
667ret false
668end
669p0 = add off base
670if ne get inq_pbuf p0 46
671ret false
672end
673if ne inq_to_lower get inq_pbuf add p0 1 101
674ret false
675end
676if ne inq_to_lower get inq_pbuf add p0 2 110
677ret false
678end
679if ne inq_to_lower get inq_pbuf add p0 3 118
680ret false
681end
682if eq blen 4
683ret true
684end
685if eq get inq_pbuf add p0 4 46
686ret true
687end
688ret false
689end
690
691fn inq_pb_eq_a to bool
692off = get inq_pbuf_off 0
693nlen = get inq_pbuf_len 0
694if ne nlen get inq_a_len 0
695ret false
696end
697for i ulong nlen bound 131072
698if ne get inq_pbuf add off i get inq_a_buf i
699ret false
700end
701end
702ret true
703end
704
705fn inq_pb_eq_b to bool
706off = get inq_pbuf_off 0
707nlen = get inq_pbuf_len 0
708if ne nlen get inq_b_len 0
709ret false
710end
711for i ulong nlen bound 131072
712if ne get inq_pbuf add off i get inq_b_buf i
713ret false
714end
715end
716ret true
717end
718
719fn inq_pb_save_a to void
720off = get inq_pbuf_off 0
721nlen = get inq_pbuf_len 0
722for i ulong nlen bound 131072
723put inq_a_buf i get inq_pbuf add off i
724end
725put inq_a_len 0 nlen
726end
727
728fn inq_clear_active_path to void
729put inq_b_len 0 0
730put inq_skip_file 0 0
731put inq_is_md 0 0
732end
733
734fn inq_pb_set_active to void
735off = get inq_pbuf_off 0
736nlen = get inq_pbuf_len 0
737for i ulong nlen bound 131072
738put inq_b_buf i get inq_pbuf add off i
739end
740put inq_b_len 0 nlen
741if or inq_pb_contains_ci off nlen p_self_inq inq_pb_contains_ci off nlen p_self_con
742put inq_skip_file 0 1
743else
744put inq_skip_file 0 0
745end
746if inq_pb_ends_ci off nlen p_ext_md
747put inq_is_md 0 1
748else
749put inq_is_md 0 0
750end
751end
752
753fn inq_is_ws_char c uchar to bool
754if or eq c 32 or eq c 9 eq c 13
755ret true
756end
757ret false
758end
759
760fn inq_trim_ws off ulong nlen ulong to void
761s = off
762e = add off nlen
763while lt s e bound 131072
764if inq_is_ws_char get inq_in s
765s = add s 1
766else
767break
768end
769end
770while gt e s bound 131072
771if inq_is_ws_char get inq_in sub e 1
772e = sub e 1
773else
774break
775end
776end
777put inq_tmp_off 0 s
778put inq_tmp_len 0 sub e s
779end
780
781fn inq_is_octal c uchar to bool
782ret and ge c 48 le c 55
783end
784
785fn inq_decode_cesc c uchar to uchar
786if eq c 116
787ret 9
788end
789if eq c 110
790ret 10
791end
792if eq c 114
793ret 13
794end
795if eq c 98
796ret 8
797end
798if eq c 102
799ret 12
800end
801if eq c 97
802ret 7
803end
804if eq c 118
805ret 11
806end
807ret c
808end
809
810fn inq_oct3 a uchar b uchar c uchar to uchar
811v1 = mul sub ulong a 48 64
812v2 = mul sub ulong b 48 8
813v3 = sub ulong c 48
814ret uchar and add v1 add v2 v3 255
815end
816
817fn inq_unesc_to_pbuf s ulong e ulong to ulong
818p = s
819w = ulong 0
820while lt p e bound 131072
821c = get inq_in p
822if eq c 92
823if lt add p 1 e
824n1 = get inq_in add p 1
825oct_done = false
826if inq_is_octal n1
827if le add p 4 e
828n2 = get inq_in add p 2
829n3 = get inq_in add p 3
830if and inq_is_octal n2 inq_is_octal n3
831put inq_pbuf w inq_oct3 n1 n2 n3
832w = add w 1
833p = add p 4
834oct_done = true
835end
836end
837end
838if not oct_done
839put inq_pbuf w inq_decode_cesc n1
840w = add w 1
841p = add p 2
842end
843else
844put inq_pbuf w c
845w = add w 1
846p = add p 1
847end
848else
849put inq_pbuf w c
850w = add w 1
851p = add p 1
852end
853end
854ret w
855end
856
857fn inq_norm_to_pbuf off ulong nlen ulong to void
858inq_trim_ws off nlen
859s = get inq_tmp_off 0
860e = add s get inq_tmp_len 0
861w = ulong 0
862quoted = false
863if ge sub e s 2
864if and eq get inq_in s 34 eq get inq_in sub e 1 34
865w = inq_unesc_to_pbuf add s 1 sub e 1
866quoted = true
867else
868if and eq get inq_in s 39 eq get inq_in sub e 1 39
869s = add s 1
870e = sub e 1
871end
872end
873end
874if not quoted
875w = sub e s
876for i ulong w bound 131072
877put inq_pbuf i get inq_in add s i
878end
879end
880ns = ulong 0
881if ge sub w ns 2
882c0 = get inq_pbuf ns
883c1 = get inq_pbuf add ns 1
884if and eq c1 47 or eq c0 97 eq c0 98
885ns = add ns 2
886end
887end
888while ge sub w ns 2 bound 65536
889c0 = get inq_pbuf ns
890c1 = get inq_pbuf add ns 1
891if and eq c0 46 eq c1 47
892ns = add ns 2
893else
894break
895end
896end
897put inq_pbuf_off 0 ns
898put inq_pbuf_len 0 sub w ns
899end
900
901fn inq_pb_check_path line_no ulong to void
902off = get inq_pbuf_off 0
903nlen = get inq_pbuf_len 0
904if eq nlen 0
905ret
906end
907if inq_pb_eq_pat off nlen p_dev_null
908ret
909end
910if inq_pb_is_env off nlen
911inq_record RULE_ENV_FILE SEV_BLOCK line_no SUB_ENV_FILE
912end
913if or inq_pb_starts_ci off nlen p_evid_pre inq_pb_contains_ci off nlen p_evid_mid
914inq_record RULE_PROTECTED_PATH SEV_BLOCK line_no SUB_PATH_EVIDENCE
915end
916if or inq_pb_starts_ci off nlen p_aien_pre inq_pb_contains_ci off nlen p_aien_mid
917inq_record RULE_PROTECTED_PATH SEV_BLOCK line_no SUB_PATH_AIEN
918end
919if or inq_pb_starts_ci off nlen p_gates_pre inq_pb_contains_ci off nlen p_gates_mid
920inq_record RULE_PROTECTED_PATH SEV_BLOCK line_no SUB_PATH_GATES
921end
922if or inq_pb_starts_ci off nlen p_ghwf_pre inq_pb_contains_ci off nlen p_ghwf_mid
923inq_record RULE_PROTECTED_PATH SEV_BLOCK line_no SUB_PATH_CI
924else
925if or inq_pb_starts_ci off nlen p_fgjo_pre inq_pb_contains_ci off nlen p_fgjo_mid
926inq_record RULE_PROTECTED_PATH SEV_BLOCK line_no SUB_PATH_CI
927end
928end
929if or inq_pb_starts_ci off nlen p_aient_pre inq_pb_contains_ci off nlen p_aient_mid
930inq_record RULE_PROTECTED_PATH SEV_BLOCK line_no SUB_PATH_AIEN_TEST
931end
932end
933
934fn inq_diff_git_exact_mid pos ulong end_p ulong to ulong
935rem_l = sub end_p pos
936if lt rem_l 5
937ret end_p
938end
939if ne rem rem_l 2 1
940ret end_p
941end
942k = div sub rem_l 5 2
943if or ne get inq_in pos 97 ne get inq_in add pos 1 47
944ret end_p
945end
946m = add pos add 2 k
947if not inq_match_cs m p_sp_b_slash
948ret end_p
949end
950if inq_slice_eq_in add pos 2 k add m 3 k
951ret add m 1
952end
953ret end_p
954end
955
956fn inq_diff_git_find_t2 pos ulong end_p ulong to ulong
957if eq get inq_in pos 34
958qe = inq_find_quote_end pos end_p
959while lt qe end_p bound 131072
960if eq get inq_in qe 32
961qe = add qe 1
962else
963break
964end
965end
966ret qe
967end
968mid = inq_diff_git_exact_mid pos end_p
969if lt mid end_p
970ret mid
971end
972rem_l = sub end_p pos
973idx = inq_find_substr_cs pos rem_l p_sp_qb_slash
974if lt idx rem_l
975ret add pos add idx 1
976end
977idx = inq_find_substr_last_cs pos rem_l p_sp_b_slash
978if lt idx rem_l
979ret add pos add idx 1
980end
981p = pos
982while lt p end_p bound 131072
983if ne get inq_in p 32
984p = add p 1
985else
986break
987end
988end
989while lt p end_p bound 131072
990if eq get inq_in p 32
991p = add p 1
992else
993break
994end
995end
996ret p
997end
998
999fn inq_diff_git_check_alt pos ulong end_p ulong t2_s ulong line_no ulong to void
1000if eq get inq_in pos 34
1001ret
1002end
1003rem_l = sub end_p pos
1004idx1 = inq_find_substr_cs pos rem_l p_sp_b_slash
1005if ge idx1 rem_l
1006ret
1007end
1008alt_t2 = add pos add idx1 1
1009if eq alt_t2 t2_s
1010ret
1011end
1012inq_norm_to_pbuf pos idx1
1013inq_pb_check_path line_no
1014inq_norm_to_pbuf alt_t2 sub end_p alt_t2
1015inq_pb_check_path line_no
1016end
1017
1018fn inq_parse_diff_git off ulong nlen ulong line_no ulong to void
1019put inq_in_bin 0 0
1020put inq_in_hunk 0 0
1021put inq_hunk_has_cnt 0 0
1022put inq_hunk_old 0 0
1023put inq_hunk_new 0 0
1024put inq_expect_plus 0 1
1025put inq_has_git_hdr 0 1
1026put inq_in_git_body 0 0
1027put inq_diff_checked 0 0
1028put inq_a_len 0 0
1029inq_clear_active_path
1030put inq_files 0 add get inq_files 0 1
1031pos = add off 11
1032end_p = add off nlen
1033while lt pos end_p bound 131072
1034if eq get inq_in pos 32
1035pos = add pos 1
1036else
1037break
1038end
1039end
1040if ge pos end_p
1041ret
1042end
1043t2_s = inq_diff_git_find_t2 pos end_p
1044if lt t2_s end_p
1045t1_e = t2_s
1046while gt t1_e pos bound 131072
1047if eq get inq_in sub t1_e 1 32
1048t1_e = sub t1_e 1
1049else
1050break
1051end
1052end
1053inq_norm_to_pbuf pos sub t1_e pos
1054inq_pb_save_a
1055inq_norm_to_pbuf t2_s sub end_p t2_s
1056same_ab = inq_pb_eq_a
1057inq_pb_set_active
1058inq_pb_check_path line_no
1059if not same_ab
1060inq_norm_to_pbuf pos sub t1_e pos
1061inq_pb_check_path line_no
1062inq_diff_git_check_alt pos end_p t2_s line_no
1063end
1064put inq_diff_checked 0 1
1065else
1066inq_norm_to_pbuf pos sub end_p pos
1067inq_pb_save_a
1068inq_pb_set_active
1069inq_pb_check_path line_no
1070end
1071end
1072
1073fn inq_strip_tab_len pos ulong rem_l ulong to ulong
1074tab_i = ulong 0
1075while lt tab_i rem_l bound 131072
1076if eq get inq_in add pos tab_i 9
1077ret tab_i
1078end
1079tab_i = add tab_i 1
1080end
1081ret rem_l
1082end
1083
1084fn inq_is_quoted_in s ulong tl ulong to bool
1085if lt tl 2
1086ret false
1087end
1088if ne get inq_in s 34
1089ret false
1090end
1091last = sub add s tl 1
1092ret eq get inq_in last 34
1093end
1094
1095fn inq_is_plain_path_in s ulong tl ulong to bool
1096has_sep = false
1097for i ulong tl bound 131072
1098c = get inq_in add s i
1099if or eq c 32 or eq c 58 eq c 61
1100ret false
1101end
1102if or eq c 40 or eq c 41 eq c 33
1103ret false
1104end
1105if or eq c 47 eq c 46
1106has_sep = true
1107end
1108end
1109ret has_sep
1110end
1111
1112fn inq_is_hdr_path off ulong nlen ulong allow_a bool to bool
1113rem_l = inq_strip_tab_len off nlen
1114has_tab = lt rem_l nlen
1115inq_trim_ws off rem_l
1116s = get inq_tmp_off 0
1117tl = get inq_tmp_len 0
1118if eq tl 0
1119ret false
1120end
1121if inq_slice_eq_pat s tl p_dev_null
1122ret true
1123end
1124if inq_is_quoted_in s tl
1125ret true
1126end
1127if ge tl 2
1128if eq get inq_in add s 1 47
1129c0 = get inq_in s
1130if eq c0 98
1131ret true
1132end
1133if and allow_a eq c0 97
1134ret true
1135end
1136end
1137end
1138if has_tab
1139if inq_contains_cs s tl p_colon_sp
1140ret false
1141end
1142ret true
1143end
1144ret inq_is_plain_path_in s tl
1145end
1146
1147fn inq_has_ab_prefix s ulong tl ulong allow_a bool to bool
1148if ge tl 2
1149if eq get inq_in add s 1 47
1150c0 = get inq_in s
1151if eq c0 98
1152ret true
1153end
1154if and allow_a eq c0 97
1155ret true
1156end
1157end
1158end
1159if ge tl 4
1160if inq_is_quoted_in s tl
1161if eq get inq_in add s 2 47
1162c1 = get inq_in add s 1
1163if eq c1 98
1164ret true
1165end
1166if and allow_a eq c1 97
1167ret true
1168end
1169end
1170end
1171end
1172ret false
1173end
1174
1175fn inq_is_git_path off ulong nlen ulong allow_a bool to bool
1176rem_l = inq_strip_tab_len off nlen
1177has_tab = lt rem_l nlen
1178inq_trim_ws off rem_l
1179s = get inq_tmp_off 0
1180tl = get inq_tmp_len 0
1181if eq tl 0
1182ret false
1183end
1184if inq_slice_eq_pat s tl p_dev_null
1185ret true
1186end
1187if inq_has_ab_prefix s tl allow_a
1188ret true
1189end
1190if has_tab
1191if not inq_contains_cs s tl p_colon_sp
1192ret true
1193end
1194end
1195ret false
1196end
1197
1198fn inq_plus_header_allowed off ulong nlen ulong to bool
1199ep = get inq_expect_plus 0
1200if eq ep 0
1201ret false
1202end
1203pos = add off 4
1204rem_l = sub nlen 4
1205if eq ep 2
1206ret inq_is_hdr_path pos rem_l false
1207end
1208ret inq_is_git_path pos rem_l false
1209end
1210
1211fn inq_minus_is_git_path off ulong nlen ulong to bool
1212ret inq_is_git_path add off 4 sub nlen 4 true
1213end
1214
1215fn inq_parse_minus_header off ulong nlen ulong line_no ulong exp_mode ulong to void
1216put inq_in_bin 0 0
1217put inq_expect_plus 0 exp_mode
1218pos = add off 4
1219rem_l = inq_strip_tab_len pos sub nlen 4
1220inq_norm_to_pbuf pos rem_l
1221npl = get inq_pbuf_len 0
1222if or eq npl 0 inq_pb_eq_pat get inq_pbuf_off 0 npl p_dev_null
1223ret
1224end
1225already = false
1226if eq get inq_diff_checked 0 1
1227if inq_pb_eq_a
1228already = true
1229end
1230end
1231if not already
1232inq_clear_active_path
1233inq_pb_check_path line_no
1234end
1235end
1236
1237fn inq_parse_plus_header off ulong nlen ulong line_no ulong to void
1238put inq_in_bin 0 0
1239put inq_expect_plus 0 0
1240if eq get inq_has_git_hdr 0 1
1241put inq_in_git_body 0 1
1242end
1243pos = add off 4
1244rem_l = inq_strip_tab_len pos sub nlen 4
1245inq_norm_to_pbuf pos rem_l
1246npl = get inq_pbuf_len 0
1247if or eq npl 0 inq_pb_eq_pat get inq_pbuf_off 0 npl p_dev_null
1248inq_clear_active_path
1249put inq_diff_checked 0 0
1250ret
1251end
1252already = false
1253if eq get inq_diff_checked 0 1
1254if inq_pb_eq_b
1255already = true
1256end
1257end
1258inq_pb_set_active
1259put inq_diff_checked 0 0
1260if not already
1261put inq_files 0 add get inq_files 0 1
1262inq_pb_check_path line_no
1263end
1264end
1265
1266fn inq_bin_check_split s ulong sp ulong e ulong line_no ulong primary bool to void
1267inq_norm_to_pbuf s sp
1268a_ok = and gt get inq_pbuf_len 0 0 not inq_pb_eq_pat get inq_pbuf_off 0 get inq_pbuf_len 0 p_dev_null
1269inq_pb_save_a
1270dst_s = add s add sp 5
1271inq_norm_to_pbuf dst_s sub e dst_s
1272b_ok = and gt get inq_pbuf_len 0 0 not inq_pb_eq_pat get inq_pbuf_off 0 get inq_pbuf_len 0 p_dev_null
1273same_ab = and a_ok and b_ok inq_pb_eq_a
1274if primary
1275if or a_ok b_ok
1276put inq_files 0 add get inq_files 0 1
1277end
1278if b_ok
1279inq_pb_set_active
1280else
1281if a_ok
1282inq_norm_to_pbuf s sp
1283inq_pb_set_active
1284inq_norm_to_pbuf dst_s sub e dst_s
1285end
1286end
1287end
1288if b_ok
1289inq_pb_check_path line_no
1290end
1291if and a_ok not same_ab
1292inq_norm_to_pbuf s sp
1293inq_pb_check_path line_no
1294end
1295end
1296
1297fn inq_bin_exact_mid s ulong e ulong to ulong
1298rem_l = sub e s
1299if lt rem_l 9
1300ret rem_l
1301end
1302if ne rem rem_l 2 1
1303ret rem_l
1304end
1305k = div sub rem_l 9 2
1306if or ne get inq_in s 97 ne get inq_in add s 1 47
1307ret rem_l
1308end
1309m = add s add 2 k
1310if not inq_match_cs m p_sp_and_b
1311ret rem_l
1312end
1313if inq_slice_eq_in add s 2 k add m 7 k
1314ret add 2 k
1315end
1316ret rem_l
1317end
1318
1319fn inq_parse_bin_files off ulong nlen ulong line_no ulong to void
1320note Format: "Binary files <src> and <dst> differ"
1321put inq_in_bin 0 0
1322put inq_in_hunk 0 0
1323put inq_hunk_has_cnt 0 0
1324put inq_hunk_old 0 0
1325put inq_hunk_new 0 0
1326put inq_expect_plus 0 0
1327put inq_has_git_hdr 0 0
1328put inq_in_git_body 0 0
1329put inq_diff_checked 0 0
1330inq_clear_active_path
1331s = add off 13
1332e = add off nlen
1333while lt s e bound 131072
1334if eq get inq_in s 32
1335s = add s 1
1336else
1337break
1338end
1339end
1340while gt e s bound 131072
1341c = get inq_in sub e 1
1342if or eq c 32 eq c 13
1343e = sub e 1
1344else
1345break
1346end
1347end
1348if ge sub e s 7
1349if inq_match_cs sub e 7 p_sp_differ
1350e = sub e 7
1351end
1352end
1353rem_l = sub e s
1354if eq rem_l 0
1355ret
1356end
1357if eq get inq_in s 34
1358qe = inq_find_quote_end s e
1359if le add qe 5 e
1360if inq_match_cs qe p_sp_and_sp
1361inq_bin_check_split s sub qe s e line_no true
1362ret
1363end
1364end
1365end
1366mid = inq_bin_exact_mid s e
1367if lt mid rem_l
1368inq_bin_check_split s mid e line_no true
1369ret
1370end
1371if ge rem_l 14
1372if inq_match_cs sub e 14 p_sp_and_dev
1373inq_bin_check_split s sub rem_l 14 e line_no true
1374ret
1375end
1376end
1377sp_qb = inq_find_substr_cs s rem_l p_sp_and_qb
1378if lt sp_qb rem_l
1379inq_bin_check_split s sp_qb e line_no true
1380ret
1381end
1382sp_b1 = inq_find_substr_cs s rem_l p_sp_and_b
1383if lt sp_b1 rem_l
1384sp_b2 = inq_find_substr_last_cs s rem_l p_sp_and_b
1385inq_bin_check_split s sp_b2 e line_no true
1386if ne sp_b1 sp_b2
1387inq_bin_check_split s sp_b1 e line_no false
1388end
1389ret
1390end
1391sp1 = inq_find_substr_cs s rem_l p_sp_and_sp
1392if lt sp1 rem_l
1393sp2 = inq_find_substr_last_cs s rem_l p_sp_and_sp
1394inq_bin_check_split s sp2 e line_no true
1395if ne sp1 sp2
1396inq_bin_check_split s sp1 e line_no false
1397end
1398end
1399end
1400
1401fn inq_read_u64_at pos ulong end_p ulong to void
1402digits = ulong 0
1403val = ulong 0
1404p = pos
1405while lt p end_p bound 131072
1406c = get inq_in p
1407if and ge c 48 le c 57
1408digits = add digits 1
1409if le digits 9
1410val = add mul val 10 ulong sub c 48
1411end
1412p = add p 1
1413else
1414break
1415end
1416end
1417put inq_num_pos 0 p
1418put inq_num_val 0 val
1419if and gt digits 0 le digits 9
1420put inq_num_ok 0 1
1421else
1422put inq_num_ok 0 0
1423end
1424end
1425
1426fn inq_parse_hunk_hdr off ulong nlen ulong to void
1427put inq_in_bin 0 0
1428put inq_expect_plus 0 0
1429if eq get inq_has_git_hdr 0 1
1430put inq_in_git_body 0 1
1431end
1432put inq_in_hunk 0 1
1433put inq_hunk_has_cnt 0 0
1434put inq_hunk_old 0 0
1435put inq_hunk_new 0 0
1436p = add off 3
1437end_p = add off nlen
1438while lt p end_p bound 131072
1439if eq get inq_in p 32
1440p = add p 1
1441else
1442break
1443end
1444end
1445if ge p end_p
1446ret
1447end
1448if ne get inq_in p 45
1449ret
1450end
1451p = add p 1
1452inq_read_u64_at p end_p
1453if eq get inq_num_ok 0 0
1454ret
1455end
1456p = get inq_num_pos 0
1457old_c = ulong 1
1458if lt p end_p
1459if eq get inq_in p 44
1460p = add p 1
1461inq_read_u64_at p end_p
1462if eq get inq_num_ok 0 0
1463ret
1464end
1465old_c = get inq_num_val 0
1466p = get inq_num_pos 0
1467end
1468end
1469if ge p end_p
1470ret
1471end
1472if ne get inq_in p 32
1473ret
1474end
1475while lt p end_p bound 131072
1476if eq get inq_in p 32
1477p = add p 1
1478else
1479break
1480end
1481end
1482if ge p end_p
1483ret
1484end
1485if ne get inq_in p 43
1486ret
1487end
1488p = add p 1
1489inq_read_u64_at p end_p
1490if eq get inq_num_ok 0 0
1491ret
1492end
1493p = get inq_num_pos 0
1494new_c = ulong 1
1495if lt p end_p
1496if eq get inq_in p 44
1497p = add p 1
1498inq_read_u64_at p end_p
1499if eq get inq_num_ok 0 0
1500ret
1501end
1502new_c = get inq_num_val 0
1503p = get inq_num_pos 0
1504end
1505end
1506if ge p end_p
1507ret
1508end
1509if ne get inq_in p 32
1510ret
1511end
1512while lt p end_p bound 131072
1513if eq get inq_in p 32
1514p = add p 1
1515else
1516break
1517end
1518end
1519if lt sub end_p p 2
1520ret
1521end
1522if or ne get inq_in p 64 ne get inq_in add p 1 64
1523ret
1524end
1525if and eq old_c 0 eq new_c 0
1526ret
1527end
1528put inq_hunk_old 0 old_c
1529put inq_hunk_new 0 new_c
1530put inq_hunk_has_cnt 0 1
1531end
1532
1533fn inq_hunk_step kind ulong to void
1534if eq get inq_in_hunk 0 0
1535ret
1536end
1537if eq get inq_hunk_has_cnt 0 0
1538ret
1539end
1540old_r = get inq_hunk_old 0
1541new_r = get inq_hunk_new 0
1542if or eq kind 0 eq kind 45
1543if gt old_r 0
1544old_r = sub old_r 1
1545put inq_hunk_old 0 old_r
1546end
1547end
1548if or eq kind 0 eq kind 43
1549if gt new_r 0
1550new_r = sub new_r 1
1551put inq_hunk_new 0 new_r
1552end
1553end
1554if and eq old_r 0 eq new_r 0
1555put inq_in_hunk 0 0
1556put inq_hunk_has_cnt 0 0
1557end
1558end
1559
1560fn inq_try_git_path_hdr off ulong nlen ulong line_no ulong to bool
1561if inq_starts_cs off nlen p_ren_from
1562inq_norm_to_pbuf add off 12 sub nlen 12
1563inq_pb_check_path line_no
1564ret true
1565end
1566if inq_starts_cs off nlen p_ren_to
1567inq_norm_to_pbuf add off 10 sub nlen 10
1568inq_pb_set_active
1569inq_pb_check_path line_no
1570ret true
1571end
1572if inq_starts_cs off nlen p_cpy_from
1573inq_norm_to_pbuf add off 10 sub nlen 10
1574inq_pb_check_path line_no
1575ret true
1576end
1577if inq_starts_cs off nlen p_cpy_to
1578inq_norm_to_pbuf add off 8 sub nlen 8
1579inq_pb_set_active
1580inq_pb_check_path line_no
1581ret true
1582end
1583ret false
1584end
1585
1586fn inq_try_git_meta_hdr off ulong nlen ulong to bool
1587if or inq_starts_cs off nlen p_hdr_idx inq_starts_cs off nlen p_hdr_omode
1588ret true
1589end
1590if or inq_starts_cs off nlen p_hdr_nmode inq_starts_cs off nlen p_hdr_nfmode
1591ret true
1592end
1593if or inq_starts_cs off nlen p_hdr_dfmode inq_starts_cs off nlen p_hdr_sim
1594ret true
1595end
1596if inq_starts_cs off nlen p_hdr_dis
1597ret true
1598end
1599ret false
1600end
1601
1602fn inq_has_aws_key off ulong nlen ulong to bool
1603if lt nlen 20
1604ret false
1605end
1606lim = add sub nlen 20 1
1607for i ulong lim bound 131072
1608if inq_starts_cs add off i sub nlen i p_akia
1609ok = true
1610if gt i 0
1611if inq_is_word get inq_in sub add off i 1
1612ok = false
1613end
1614end
1615if ok
1616end_i = add i 20
1617if lt end_i nlen
1618if inq_is_word get inq_in add off end_i
1619ok = false
1620end
1621end
1622end
1623if ok
1624base = add off add i 4
1625for k ulong 16
1626if not inq_is_upper_alnum get inq_in add base k
1627ok = false
1628break
1629end
1630end
1631if ok
1632ret true
1633end
1634end
1635end
1636end
1637ret false
1638end
1639
1640fn inq_has_ghp_token off ulong nlen ulong to bool
1641if lt nlen 40
1642ret false
1643end
1644lim = add sub nlen 40 1
1645for i ulong lim bound 131072
1646if inq_starts_cs add off i sub nlen i p_ghp
1647ok = true
1648if gt i 0
1649if inq_is_word get inq_in sub add off i 1
1650ok = false
1651end
1652end
1653if ok
1654run_n = ulong 0
1655idx = add i 4
1656while and lt idx nlen lt run_n 36 bound 36
1657if inq_is_alnum get inq_in add off idx
1658run_n = add run_n 1
1659idx = add idx 1
1660else
1661break
1662end
1663end
1664if ge run_n 36
1665ret true
1666end
1667end
1668end
1669end
1670ret false
1671end
1672
1673fn inq_has_gh_fine_pat off ulong nlen ulong to bool
1674if lt nlen 61
1675ret false
1676end
1677if not inq_contains_cs off nlen p_gh_fine
1678ret false
1679end
1680lim = add sub nlen 61 1
1681for i ulong lim bound 131072
1682if inq_starts_cs add off i sub nlen i p_gh_fine
1683ok = true
1684if gt i 0
1685if inq_is_word get inq_in sub add off i 1
1686ok = false
1687end
1688end
1689if ok
1690run_n = ulong 0
1691idx = add i 11
1692while and lt idx nlen lt run_n 50 bound 50
1693if inq_is_word get inq_in add off idx
1694run_n = add run_n 1
1695idx = add idx 1
1696else
1697break
1698end
1699end
1700if ge run_n 50
1701ret true
1702end
1703end
1704end
1705end
1706ret false
1707end
1708
1709fn inq_check_secrets off ulong nlen ulong line_no ulong to void
1710if inq_has_aws_key off nlen
1711inq_record RULE_SECRET SEV_BLOCK line_no SUB_AWS_KEY
1712end
1713if or inq_has_ghp_token off nlen inq_has_gh_fine_pat off nlen
1714inq_record RULE_SECRET SEV_BLOCK line_no SUB_GH_PAT
1715end
1716if inq_contains_cs off nlen p_pem_rsa
1717inq_record RULE_SECRET SEV_BLOCK line_no SUB_PRIV_KEY
1718else
1719if and inq_contains_cs off nlen p_pem_beg inq_contains_cs off nlen p_pem_end
1720inq_record RULE_SECRET SEV_BLOCK line_no SUB_PRIV_KEY
1721end
1722end
1723if not or inq_contains_ci off nlen p_redacted inq_contains_ci off nlen p_vault
1724has_asgn = or inq_contains_cs off nlen p_sec_k1 inq_contains_cs off nlen p_sec_k2
1725has_asgn = or has_asgn or inq_contains_cs off nlen p_sec_k3 inq_contains_cs off nlen p_sec_k4
1726if has_asgn
1727inq_record RULE_SECRET SEV_BLOCK line_no SUB_SECRET_ASSIGN
1728end
1729end
1730end
1731
1732fn inq_has_tel_vendor off ulong nlen ulong to bool
1733if inq_contains_ci off nlen p_tel1
1734ret true
1735end
1736if inq_contains_ci off nlen p_tel2
1737ret true
1738end
1739if inq_contains_ci off nlen p_tel3
1740ret true
1741end
1742if inq_contains_ci off nlen p_tel4
1743ret true
1744end
1745if inq_contains_ci off nlen p_tel5
1746ret true
1747end
1748if inq_contains_ci off nlen p_tel6
1749ret true
1750end
1751if inq_contains_ci off nlen p_tel7
1752ret true
1753end
1754if inq_contains_ci off nlen p_tel8
1755ret true
1756end
1757if inq_contains_ci off nlen p_tel9
1758ret true
1759end
1760if inq_contains_ci off nlen p_tel10
1761ret true
1762end
1763if inq_contains_ci off nlen p_tel11
1764ret true
1765end
1766if inq_contains_ci off nlen p_tel12
1767ret true
1768end
1769if inq_contains_ci off nlen p_tel13
1770ret true
1771end
1772ret false
1773end
1774
1775fn inq_tel_is_negated off ulong nlen ulong to bool
1776if inq_contains_ci off nlen p_tel_ok1
1777ret true
1778end
1779if inq_contains_ci off nlen p_tel_ok2
1780ret true
1781end
1782if inq_contains_ci off nlen p_tel_ok3
1783ret true
1784end
1785if inq_contains_ci off nlen p_tel_ok4
1786ret true
1787end
1788if inq_contains_ci off nlen p_tel_ok5
1789ret true
1790end
1791if inq_contains_ci off nlen p_tel_ok6
1792ret true
1793end
1794if inq_contains_ci off nlen p_tel_ok7
1795ret true
1796end
1797if inq_contains_ci off nlen p_tel_ok8
1798ret true
1799end
1800if inq_contains_ci off nlen p_tel_ok9
1801ret true
1802end
1803if inq_contains_ci off nlen p_tel_ok10
1804ret true
1805end
1806ret false
1807end
1808
1809fn inq_check_telemetry off ulong nlen ulong line_no ulong to void
1810if inq_has_tel_vendor off nlen
1811inq_record RULE_TELEMETRY SEV_BLOCK line_no SUB_TELEM_VENDOR
1812ret
1813end
1814if eq get inq_is_md 0 0
1815if inq_contains_ci off nlen p_tel_raw
1816if not inq_tel_is_negated off nlen
1817inq_record RULE_TELEMETRY SEV_BLOCK line_no SUB_TELEM_RAW
1818end
1819end
1820end
1821end
1822
1823fn inq_check_stubs off ulong nlen ulong line_no ulong to void
1824hard = or inq_contains_ci off nlen p_stub1 inq_contains_ci off nlen p_stub2
1825hard = or hard or inq_contains_ci off nlen p_stub3 inq_contains_ci off nlen p_stub4
1826hard = or hard inq_contains_ci off nlen p_stub5
1827if hard
1828inq_record RULE_STUB_HARD SEV_BLOCK line_no SUB_STUB_HARD
1829ret
1830end
1831soft = or inq_contains_ci off nlen p_todo1 inq_contains_ci off nlen p_todo2
1832soft = or soft or inq_contains_ci off nlen p_todo3 inq_contains_ci off nlen p_todo4
1833soft = or soft inq_contains_word_ci off nlen p_todo5
1834if soft
1835inq_record RULE_TODO_WARN SEV_WARN line_no SUB_TODO_WARN
1836end
1837end
1838
1839fn inq_has_utf8_dash off ulong nlen ulong to bool
1840if lt nlen 3
1841ret false
1842end
1843lim = sub nlen 2
1844for i ulong lim bound 131072
1845b0 = get inq_in add off i
1846if eq b0 226
1847b1 = get inq_in add off add i 1
1848if eq b1 128
1849b2 = get inq_in add off add i 2
1850if or eq b2 148 eq b2 147
1851ret true
1852end
1853end
1854end
1855end
1856ret false
1857end
1858
1859fn inq_check_unslop off ulong nlen ulong line_no ulong to void
1860if inq_has_utf8_dash off nlen
1861inq_record RULE_UNSLOP_WARN SEV_WARN line_no SUB_UNSLOP_DASH
1862end
1863bz = or inq_contains_word_ci off nlen p_bz1 inq_contains_word_ci off nlen p_bz2
1864bz = or bz or inq_contains_word_ci off nlen p_bz3 inq_contains_word_ci off nlen p_bz4
1865bz = or bz or inq_contains_word_ci off nlen p_bz5 inq_contains_ci off nlen p_bz6
1866bz = or bz inq_contains_ci off nlen p_bz7
1867if not bz
1868if inq_contains_word_ci off nlen p_bz8
1869if not or inq_contains_ci off nlen p_bz8_ok1 inq_contains_ci off nlen p_bz8_ok2
1870bz = true
1871end
1872end
1873end
1874if not bz
1875if inq_contains_word_ci off nlen p_bz9
1876if not or inq_contains_ci off nlen p_bz9_ok1 inq_contains_ci off nlen p_bz9_ok2
1877bz = true
1878end
1879end
1880end
1881if bz
1882inq_record RULE_UNSLOP_WARN SEV_WARN line_no SUB_UNSLOP_BUZZ
1883end
1884end
1885
1886fn inq_check_dirty_line off ulong nlen ulong line_no ulong to void
1887hit = or inq_contains_ci off nlen p_dt1 inq_contains_ci off nlen p_dt2
1888hit = or hit or inq_contains_ci off nlen p_dt3 inq_contains_ci off nlen p_dt4
1889hit = or hit or inq_contains_ci off nlen p_dt5 inq_contains_ci off nlen p_dt6
1890hit = or hit or inq_contains_ci off nlen p_dt7 inq_contains_ci off nlen p_dt8
1891hit = or hit or inq_contains_ci off nlen p_dt9 inq_contains_ci off nlen p_dt10
1892if hit
1893inq_record RULE_DIRTY_TREE SEV_BLOCK line_no SUB_DIRTY_TREE
1894end
1895end
1896
1897fn inq_check_false_pass off ulong nlen ulong line_no ulong to void
1898has_nr = or inq_contains_ci off nlen p_not_run inq_contains_ci off nlen p_skipped
1899has_nr = or has_nr or inq_contains_ci off nlen p_blk_hw inq_contains_ci off nlen p_blk_op
1900has_nr = or has_nr or inq_contains_ci off nlen p_miss_impl inq_contains_ci off nlen p_zero_tests
1901if and has_nr inq_contains_word_ci off nlen p_pass_w
1902inq_record RULE_FALSE_PASS SEV_BLOCK line_no SUB_FALSE_PASS_INLINE
1903put inq_rec_flagged 0 1
1904ret
1905end
1906rec_nr = or inq_contains_ci off nlen p_gs_notrun inq_contains_ci off nlen p_tr_zero
1907rec_nr = or rec_nr or inq_contains_ci off nlen p_ex_zero inq_contains_ci off nlen p_ts_skip
1908rec_nr = or rec_nr or inq_contains_ci off nlen p_ts_notrun inq_contains_ci off nlen p_st_notrun
1909if rec_nr
1910put inq_seen_notrun 0 1
1911end
1912rec_p = or inq_contains_ci off nlen p_v_pass inq_contains_ci off nlen p_c_pass
1913rec_p = or rec_p or inq_contains_ci off nlen p_s_pass inq_contains_ci off nlen p_r_pass
1914if rec_p
1915put inq_seen_pass 0 1
1916end
1917if eq get inq_seen_notrun 0 1
1918if eq get inq_seen_pass 0 1
1919if eq get inq_rec_flagged 0 0
1920inq_record RULE_FALSE_PASS SEV_BLOCK line_no SUB_FALSE_PASS_RECORD
1921put inq_rec_flagged 0 1
1922end
1923end
1924end
1925end
1926
1927fn inq_scan_line off ulong nlen ulong line_no ulong to void
1928if eq nlen 0
1929put inq_seen_notrun 0 0
1930put inq_seen_pass 0 0
1931put inq_rec_flagged 0 0
1932put inq_expect_plus 0 0
1933if eq get inq_in_hunk 0 1
1934inq_hunk_step 0
1935end
1936ret
1937end
1938if and eq nlen 3 inq_starts_cs off nlen p_rec_sep
1939put inq_seen_notrun 0 0
1940put inq_seen_pass 0 0
1941put inq_rec_flagged 0 0
1942put inq_expect_plus 0 0
1943if eq get inq_in_hunk 0 1
1944inq_hunk_step 45
1945end
1946ret
1947end
1948if inq_starts_cs off nlen p_diff_git
1949put inq_seen_notrun 0 0
1950put inq_seen_pass 0 0
1951put inq_rec_flagged 0 0
1952inq_parse_diff_git off nlen line_no
1953ret
1954end
1955if inq_starts_cs off nlen p_file_rec
1956put inq_in_bin 0 0
1957put inq_in_hunk 0 0
1958put inq_hunk_has_cnt 0 0
1959put inq_expect_plus 0 0
1960put inq_has_git_hdr 0 0
1961put inq_in_git_body 0 0
1962put inq_diff_checked 0 0
1963put inq_files 0 add get inq_files 0 1
1964inq_norm_to_pbuf add off 6 sub nlen 6
1965inq_pb_set_active
1966inq_pb_check_path line_no
1967ret
1968end
1969if inq_starts_cs off nlen p_bin_files
1970inq_parse_bin_files off nlen line_no
1971ret
1972end
1973if inq_starts_cs off nlen p_git_bin
1974put inq_in_bin 0 1
1975put inq_in_hunk 0 0
1976put inq_hunk_has_cnt 0 0
1977put inq_expect_plus 0 0
1978put inq_has_git_hdr 0 0
1979put inq_in_git_body 0 0
1980put inq_diff_checked 0 0
1981ret
1982end
1983if eq get inq_in_hunk 0 0
1984if inq_starts_cs off nlen p_plus3
1985if inq_plus_header_allowed off nlen
1986inq_check_secrets off nlen line_no
1987inq_parse_plus_header off nlen line_no
1988ret
1989end
1990end
1991if or eq get inq_expect_plus 0 2 eq get inq_expect_plus 0 3
1992put inq_expect_plus 0 0
1993end
1994if eq get inq_in_git_body 0 0
1995if inq_starts_cs off nlen p_minus3
1996if inq_is_hdr_path add off 4 sub nlen 4 true
1997inq_parse_minus_header off nlen line_no 2
1998ret
1999end
2000end
2001else
2002if inq_starts_cs off nlen p_minus3
2003if inq_minus_is_git_path off nlen
2004put inq_diff_checked 0 0
2005inq_parse_minus_header off nlen line_no 3
2006ret
2007end
2008end
2009end
2010if eq get inq_in_bin 0 0
2011if inq_try_git_path_hdr off nlen line_no
2012ret
2013end
2014if eq get inq_in_git_body 0 0
2015if inq_try_git_meta_hdr off nlen
2016ret
2017end
2018end
2019end
2020end
2021if inq_starts_cs off nlen p_hunk
2022inq_parse_hunk_hdr off nlen
2023ret
2024end
2025if inq_starts_cs off nlen p_hunk3
2026put inq_in_bin 0 0
2027put inq_expect_plus 0 0
2028if eq get inq_has_git_hdr 0 1
2029put inq_in_git_body 0 1
2030end
2031put inq_in_hunk 0 1
2032put inq_hunk_has_cnt 0 0
2033ret
2034end
2035if eq get inq_in_bin 0 1
2036ret
2037end
2038put inq_expect_plus 0 0
2039if eq get inq_has_git_hdr 0 1
2040put inq_in_git_body 0 1
2041end
2042first_c = get inq_in off
2043if eq get inq_in_hunk 0 1
2044if eq first_c 43
2045inq_hunk_step 43
2046else
2047if eq first_c 45
2048inq_hunk_step 45
2049else
2050if eq first_c 32
2051inq_hunk_step 0
2052end
2053end
2054end
2055end
2056if eq get inq_skip_file 0 1
2057note DRA-440: secrets scanning must never self-exempt spark-inquisitor or constitution.rs
2058if eq first_c 43
2059put inq_added 0 add get inq_added 0 1
2060inq_check_secrets off nlen line_no
2061end
2062ret
2063end
2064
2065note Check dirty-tree and false-PASS metadata on both audit lines and added diff lines
2066if ne first_c 45
2067inq_check_dirty_line off nlen line_no
2068inq_check_false_pass off nlen line_no
2069end
2070
2071note Added diff lines (+) run full content policy checks
2072if eq first_c 43
2073put inq_added 0 add get inq_added 0 1
2074inq_check_secrets off nlen line_no
2075inq_check_telemetry off nlen line_no
2076inq_check_stubs off nlen line_no
2077inq_check_unslop off nlen line_no
2078end
2079end
2080
2081fn inq_scan_input to ulong
2082inq_reset
2083total = get inq_in_len 0
2084h = get inq_hash 0
2085for k ulong total bound 131072
2086h = inq_fnv_step h get inq_in k
2087end
2088put inq_hash 0 h
2089pos = ulong 0
2090line_no = ulong 0
2091while lt pos total bound 131072
2092ls = pos
2093while lt pos total bound 131072
2094if eq get inq_in pos 10
2095break
2096end
2097pos = add pos 1
2098end
2099le_pos = pos
2100if gt le_pos ls
2101if eq get inq_in sub le_pos 1 13
2102le_pos = sub le_pos 1
2103end
2104end
2105line_no = add line_no 1
2106inq_scan_line ls sub le_pos ls line_no
2107if lt pos total
2108pos = add pos 1
2109end
2110end
2111put inq_lines 0 line_no
2112note Mix verdict and counts into deterministic receipt fingerprint
2113h = inq_fnv_step get inq_hash 0 uchar and get inq_verdict 0 255
2114h = inq_fnv_step h uchar and get inq_blocks 0 255
2115h = inq_fnv_step h uchar and get inq_warns 0 255
2116put inq_hash 0 h
2117ret get inq_verdict 0
2118end
2119
2120fn inq_out_byte b uchar to void
2121p = get inq_out_len 0
2122if lt p INQ_MAX_OUT
2123put inq_out p b
2124put inq_out_len 0 add p 1
2125end
2126end
2127
2128fn inq_out_str s view uchar * to void
2129n = len s
2130for i ulong n bound 4096
2131inq_out_byte get s i
2132end
2133end
2134
2135fn inq_out_u64 v ulong to void
2136if eq v 0
2137inq_out_byte 48
2138ret
2139end
2140buf = new uchar 24 0
2141k = ulong 0
2142x = v
2143while gt x 0 bound 24
2144d = rem x 10
2145put buf k uchar add 48 d
2146x = div x 10
2147k = add k 1
2148end
2149while gt k 0 bound 24
2150k = sub k 1
2151inq_out_byte get buf k
2152end
2153end
2154
2155fn inq_out_hex64 v ulong to void
2156for i ulong 16
2157sh = mul sub 15 i 4
2158nib = and shr v sh 15
2159inq_out_byte get inq_hex nib
2160end
2161end
2162
2163fn inq_out_sev sev ulong to void
2164if eq sev SEV_PASS
2165inq_out_str j_pass
2166ret
2167end
2168if eq sev SEV_WARN
2169inq_out_str j_warn
2170ret
2171end
2172inq_out_str j_block
2173end
2174
2175fn inq_out_rule_name r ulong to void
2176if eq r RULE_SECRET
2177inq_out_str rn_secret
2178ret
2179end
2180if eq r RULE_ENV_FILE
2181inq_out_str rn_env
2182ret
2183end
2184if eq r RULE_PROTECTED_PATH
2185inq_out_str rn_path
2186ret
2187end
2188if eq r RULE_DIRTY_TREE
2189inq_out_str rn_dirty
2190ret
2191end
2192if eq r RULE_FALSE_PASS
2193inq_out_str rn_fpass
2194ret
2195end
2196if eq r RULE_TELEMETRY
2197inq_out_str rn_telem
2198ret
2199end
2200if eq r RULE_STUB_HARD
2201inq_out_str rn_stub
2202ret
2203end
2204if eq r RULE_TODO_WARN
2205inq_out_str rn_todo
2206ret
2207end
2208if eq r RULE_UNSLOP_WARN
2209inq_out_str rn_unslop
2210ret
2211end
2212inq_out_str rn_unk
2213end
2214
2215fn inq_out_sub_detail s ulong to void
2216if eq s SUB_AWS_KEY
2217inq_out_str sd_aws
2218ret
2219end
2220if eq s SUB_GH_PAT
2221inq_out_str sd_gh
2222ret
2223end
2224if eq s SUB_PRIV_KEY
2225inq_out_str sd_pem
2226ret
2227end
2228if eq s SUB_SECRET_ASSIGN
2229inq_out_str sd_assign
2230ret
2231end
2232if eq s SUB_ENV_FILE
2233inq_out_str sd_env
2234ret
2235end
2236if eq s SUB_PATH_EVIDENCE
2237inq_out_str sd_evid
2238ret
2239end
2240if eq s SUB_PATH_AIEN
2241inq_out_str sd_aien
2242ret
2243end
2244if eq s SUB_PATH_GATES
2245inq_out_str sd_gates
2246ret
2247end
2248if eq s SUB_PATH_CI
2249inq_out_str sd_ci
2250ret
2251end
2252if eq s SUB_PATH_AIEN_TEST
2253inq_out_str sd_aient
2254ret
2255end
2256if eq s SUB_DIRTY_TREE
2257inq_out_str sd_dirty
2258ret
2259end
2260if eq s SUB_FALSE_PASS_INLINE
2261inq_out_str sd_fpi
2262ret
2263end
2264if eq s SUB_FALSE_PASS_RECORD
2265inq_out_str sd_fpr
2266ret
2267end
2268if eq s SUB_TELEM_VENDOR
2269inq_out_str sd_tv
2270ret
2271end
2272if eq s SUB_TELEM_RAW
2273inq_out_str sd_tr
2274ret
2275end
2276if eq s SUB_STUB_HARD
2277inq_out_str sd_stub
2278ret
2279end
2280if eq s SUB_TODO_WARN
2281inq_out_str sd_todo
2282ret
2283end
2284if eq s SUB_UNSLOP_DASH
2285inq_out_str sd_dash
2286ret
2287end
2288if eq s SUB_UNSLOP_BUZZ
2289inq_out_str sd_buzz
2290ret
2291end
2292inq_out_str sd_other
2293end
2294
2295fn inq_format_receipt to ulong
2296put inq_out_len 0 0
2297inq_out_str j_head
2298inq_out_sev get inq_verdict 0
2299inq_out_str j_sev
2300inq_out_u64 get inq_verdict 0
2301inq_out_str j_blk
2302inq_out_u64 get inq_blocks 0
2303inq_out_str j_wrn
2304inq_out_u64 get inq_warns 0
2305inq_out_str j_fil
2306inq_out_u64 get inq_files 0
2307inq_out_str j_lin
2308inq_out_u64 get inq_lines 0
2309inq_out_str j_add
2310inq_out_u64 get inq_added 0
2311inq_out_str j_r_sec
2312inq_out_u64 get inq_rcnt RULE_SECRET
2313inq_out_str j_r_env
2314inq_out_u64 get inq_rcnt RULE_ENV_FILE
2315inq_out_str j_r_pth
2316inq_out_u64 get inq_rcnt RULE_PROTECTED_PATH
2317inq_out_str j_r_dty
2318inq_out_u64 get inq_rcnt RULE_DIRTY_TREE
2319inq_out_str j_r_fps
2320inq_out_u64 get inq_rcnt RULE_FALSE_PASS
2321inq_out_str j_r_tel
2322inq_out_u64 get inq_rcnt RULE_TELEMETRY
2323inq_out_str j_r_stb
2324inq_out_u64 get inq_rcnt RULE_STUB_HARD
2325inq_out_str j_r_tdo
2326inq_out_u64 get inq_rcnt RULE_TODO_WARN
2327inq_out_str j_r_uns
2328inq_out_u64 get inq_rcnt RULE_UNSLOP_WARN
2329inq_out_str j_fp
2330inq_out_hex64 get inq_hash 0
2331inq_out_str j_fnd
2332fc = get inq_find_cnt 0
2333for i ulong fc bound 128
2334if gt i 0
2335inq_out_str j_comma
2336end
2337inq_out_str j_f_open
2338inq_out_rule_name get inq_find_rule i
2339inq_out_str j_f_sev
2340inq_out_sev get inq_find_sev i
2341inq_out_str j_f_line
2342inq_out_u64 get inq_find_line i
2343inq_out_str j_f_det
2344inq_out_sub_detail get inq_find_sub i
2345inq_out_str j_f_close
2346end
2347inq_out_str j_tail
2348ret get inq_out_len 0
2349end
2350
2351fn inq_write_all fd int total ulong to bool
2352sent = ulong 0
2353while lt sent total bound 32768
2354k = write fd inq_out sent sub total sent
2355if le k 0
2356ret false
2357end
2358sent = add sent ulong k
2359end
2360ret true
2361end