Skip to content

Commit

Permalink
cleanup TCB/forbid_xxx.jsonnet, factorize in common.libsonnet (semgre…
Browse files Browse the repository at this point in the history
…p#9882)

test plan:
make check
  • Loading branch information
Yoann Padioleau authored Mar 5, 2024
1 parent dde6675 commit 018f7e7
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 29 deletions.
16 changes: 16 additions & 0 deletions TCB/common.libsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
exclude_paths: [
'TCB/*',
'tools/*',
'scripts/*',
'stats/*',
'*_main.ml',
'Main.ml',
'Test*.ml',
'Unit_*.ml',
],

exclude: {
exclude: self.exclude_paths,
},
}
22 changes: 22 additions & 0 deletions TCB/forbid_chdir.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
local common = import 'common.libsonnet';

{
rules: [
{
id: 'forbid-chdir',
match: { any: [
#TODO
# 'Unix.chdir','UUnix.chdir',
# 'Sys.chdir', 'USys.chdir',
'TODO.chdir',
] },
languages: ['ocaml'],
paths: common.exclude,
severity: 'ERROR',
message: |||
Do not use directly chdir. Use the safer CapSys.chdir().
|||,
},
],

}
2 changes: 2 additions & 0 deletions TCB/forbid_everything.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
local forbid_exit = import 'forbid_exit.jsonnet';
local forbid_network = import 'forbid_network.jsonnet';
local forbid_exec = import 'forbid_exec.jsonnet';
local forbid_chdir = import 'forbid_chdir.jsonnet';
//TODO: forbid_fs, forbid_process, etc.
local forbid_tmp = import "forbid_tmp.jsonnet";
local forbid_misc = import 'forbid_misc.jsonnet';
Expand All @@ -15,6 +16,7 @@ local forbid_misc = import 'forbid_misc.jsonnet';
forbid_exit.rules +
forbid_network.rules +
forbid_exec.rules +
forbid_chdir.rules +
forbid_tmp.rules +
forbid_misc.rules
}
10 changes: 3 additions & 7 deletions TCB/forbid_exec.jsonnet
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local common = import 'common.libsonnet';

// helpers
local unix_funcs = [
'system',
Expand Down Expand Up @@ -38,13 +40,7 @@ local unix_funcs = [
[],
},
languages: ['ocaml'],
paths: {
exclude: [
'TCB/*',
'tools/*', 'scripts/*', 'stats/*',
'Test*.ml', 'Unit_*.ml',
],
},
paths: common.exclude,
severity: 'ERROR',
message: |||
Do not invoke directly external commands. Use the safer CapExec.ml module.
Expand Down
11 changes: 3 additions & 8 deletions TCB/forbid_exit.jsonnet
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local common = import 'common.libsonnet';

{
rules: [
{
Expand All @@ -10,14 +12,7 @@
'UUnix._exit'
] },
languages: ['ocaml'],
paths: {
exclude: [
'TCB/*',
'tools/*', 'scripts/*',
'*_main.ml', 'Main.ml',
'Test*.ml',
],
},
paths: common.exclude,
severity: 'ERROR',
message: |||
Do not use directly exit(). Either raise Common.UnixExit or use the
Expand Down
11 changes: 3 additions & 8 deletions TCB/forbid_misc.jsonnet
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local common = import 'common.libsonnet';

{
rules: [
{
Expand All @@ -6,14 +8,7 @@
'Random.$F',
] },
languages: ['ocaml'],
paths: {
exclude: [
'TCB/*',
'tools/*', 'scripts/*',
'*_main.ml', 'Main.ml',
'Test*.ml', 'Unit*.ml',
],
},
paths: common.exclude,
severity: 'ERROR',
message: |||
Do not use directly Random; use the safer CapRandom module.
Expand Down
9 changes: 3 additions & 6 deletions TCB/forbid_tmp.jsonnet
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local common = import 'common.libsonnet';

// helpers
local funcs = [
"temp_file",
Expand All @@ -21,12 +23,7 @@ local funcs = [
},
languages: ['ocaml'],
paths: {
exclude: [
"UTmp.ml", "CapTmp.ml",
'TCB/*',
'tools/*', 'scripts/*', 'stats/*',
'Test*.ml', 'Unit_*.ml',
],
exclude: common.exclude_paths + ["UTmp.ml", "CapTmp.ml"],
},
severity: 'ERROR',
message: |||
Expand Down

0 comments on commit 018f7e7

Please sign in to comment.