Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SARIF test #2

Open
wants to merge 75 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
2acdc29
xenopsd: use uuid instead of deprecated uuidm functions
psafont Aug 17, 2022
e833182
message-switch: conform to new APIs in jst libs
psafont Aug 17, 2022
80ee829
xapi-storage-script: conform to new APIs in jst libs
psafont Aug 18, 2022
2ee0819
xen-api-client: conform to new APIs in jst libs
psafont Oct 6, 2022
0604f31
stream_vdi, import: conform to new APIs in tar
psafont Aug 19, 2022
2ce7645
gencert: conform to new APIs in x509
psafont Aug 19, 2022
8b4d026
xapi-guard, xen-api-client: conform to new APIs in conduit
psafont Aug 19, 2022
bb1e9ec
message-switch, vhd-tool: drop io-page-unix
psafont Sep 16, 2022
661d682
nbd: change ocaml-nbd usage
psafont Oct 6, 2022
efe5654
session_check: add action name in the error returned
psafont Nov 4, 2022
d30d352
xenctrlext_stubs: fix xfm_open parameter mismatch
psafont Jan 10, 2023
c61d2ad
vhd-tool/direct_copy_stubs: fix setting of O_DIRECT flag
edwintorok Dec 7, 2022
e72966b
Makefile: add a rule to write out a compile_flags.txt
edwintorok Dec 7, 2022
b49a2b4
direct_copy_stubs.c: uerror is available in caml/unixsupport.h
edwintorok Dec 7, 2022
4390fab
add .editorconfig: use spaces instead of tabs in C files
edwintorok Dec 7, 2022
d8b7031
tuntap_stubs.c: raise Unix.error instead of failwith
edwintorok Dec 7, 2022
4a7eec6
xenctrlext_stubs.c: xc_get_last_error is not thread safe, use just er…
edwintorok Dec 7, 2022
7987d71
xa_auth_stubs.c: move free inside the blocking section
edwintorok Dec 7, 2022
1e02ea2
xenctrlext_stubs.c: add missing enter/leave blocking section
edwintorok Dec 7, 2022
ed21d97
unixpwd_stubs.c: factor out common code and use enter/leave blocking …
edwintorok Dec 7, 2022
57c6d2b
C stubs: add and use .clang-format
edwintorok Dec 7, 2022
10ff86e
dbgring: switch from Xenmmap to Gnt + Io_page
edwintorok Dec 8, 2022
f6eceeb
xe-toolstack-restart: stop and start all services at once
edwintorok Nov 22, 2022
03788e3
schematest: add better instructions
psafont Sep 20, 2022
a51711a
WIP: PVH
edwintorok Aug 12, 2019
d5794f7
WiP
edwintorok Jan 3, 2023
611956e
wip
edwintorok Jan 3, 2023
764ab12
wip
edwintorok Jan 4, 2023
918ab89
wip
edwintorok Jan 5, 2023
236916f
cstubs
edwintorok Jan 5, 2023
922a994
wip
edwintorok Jan 6, 2023
7d885d3
wip
edwintorok Jan 6, 2023
5a88ba7
tools/ocaml: register exceptions always
edwintorok Jan 6, 2023
70a2c16
wip
edwintorok Jan 6, 2023
a93d74a
wip
edwintorok Jan 6, 2023
9731add
wip
edwintorok Jan 6, 2023
93236bf
genmain fixed, and fix wrong number of arguments bug
edwintorok Jan 9, 2023
c2dae6a
fix a few more _H these are not visible to static analysis by default…
edwintorok Jan 10, 2023
0994d96
wip
edwintorok Jan 10, 2023
56a02a9
wip
edwintorok Jan 10, 2023
e551fe4
wip
edwintorok Jan 10, 2023
cfff1f0
pin my fork of xs-opam DO NOT MERGE
edwintorok Jan 10, 2023
8b85543
DO NOT MERGE: reintroduce one of the race conditions to check .sarif …
edwintorok Jan 10, 2023
6dd0a87
fix SARIF path
edwintorok Jan 10, 2023
10d2492
fix SARIF rule
edwintorok Jan 10, 2023
3b5af13
fix SARIF rule
edwintorok Jan 10, 2023
dc6c1ed
run static analyzer first. TODO move back
edwintorok Jan 10, 2023
5b79c74
iopage
edwintorok Jan 10, 2023
9452c0d
disable opam cache for now, TODO: make it invalidate based on source…
edwintorok Jan 10, 2023
95433a3
unixpwd: fix build needs uerror
edwintorok Jan 10, 2023
74d6f19
add xapi-lintcstubs to CI, needed for static analyzer
edwintorok Jan 10, 2023
a7440f1
fixup! genmain fixed, and fix wrong number of arguments bug
edwintorok Jan 10, 2023
ba3f1dd
fixup! genmain fixed, and fix wrong number of arguments bug
edwintorok Jan 10, 2023
95c70db
revert github workflow changes
edwintorok Jan 10, 2023
93a656d
add new workflow with own caching
edwintorok Jan 10, 2023
baa47c7
run on push
edwintorok Jan 10, 2023
6dfe4da
opam-repositories for action v2
edwintorok Jan 10, 2023
68e3d3c
ocaml-compiler for action v2
edwintorok Jan 10, 2023
dc4299c
log-vars for action v2
edwintorok Jan 10, 2023
4c0720c
opam-repositories for action v2
edwintorok Jan 10, 2023
2247ee7
tag and configure first
edwintorok Jan 10, 2023
86984ae
only have 1 package here, faster pinning
edwintorok Jan 10, 2023
dcb04a9
xapi version
edwintorok Jan 10, 2023
a00afbf
rename workflow
edwintorok Jan 10, 2023
e1e8b6c
try to enable dune caching for opam
edwintorok Jan 10, 2023
3efce4c
update deps
edwintorok Jan 10, 2023
32662d7
update deps
edwintorok Jan 10, 2023
034601b
show error
edwintorok Jan 10, 2023
779da7f
cache one run
edwintorok Jan 10, 2023
c6fcc9f
reenable
edwintorok Jan 10, 2023
251ff0c
depexts
edwintorok Jan 10, 2023
ed0052b
autoload runtime.model.c
edwintorok Jan 12, 2023
d9b6d91
refactor .h generator to be smaller
edwintorok Jan 12, 2023
18ac1ee
reformat
edwintorok Jan 12, 2023
03e808a
reduce tool deps to allow independent install
edwintorok Jan 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
BasedOnStyle: GNU
IndentWidth: 4

# override GNU to match Xen ../../CODING_STYLE more closely
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
SpacesInConditionalStatement: true
SpaceBeforeParens: ControlStatements
BreakBeforeBraces: Allman
20 changes: 20 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# See ./CODING_STYLE
root = true

[*]
end_of_line = lf
indent_style = space
charset = utf-8
max_line_length = 79
trim_trailing_whitespace = true
insert_final_newline = true

# Makefiles must use tabs, otherwise they don't work
[Makefile]
indent_style = tabs

[*.{c,h}]
indent_size = 4

[*.{ml,mli}]
indent_size = 2
73 changes: 73 additions & 0 deletions .github/workflows/staticanalysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Run OCaml C stub static analyzer on XAPI's C stubs

on:
push:
pull_request:
branches:
- master
- 'feature/**'
- '*-lcm'

jobs:
staticanalyzer:
name: Ocaml files
runs-on: ubuntu-22.04
env:
package: "xapi-lintcstubs"
# for building .cmt, TODO: restructure so the C stubs don't need these
xapideps: "xentoollog xapi-stdext-pervasives lwt_ssl xenctrl io-page conf-pam conf-xxhash"
XAPI_VERSION: "v0.0.0-${{ github.sha }}"
# required for dune cache to work inside opam for now, otherwise it
# gets EXDEV and considers it a cache miss
DUNE_CACHE_STORAGE_MODE: copy

steps:
- name: Checkout code
uses: actions/checkout@v3

# we could just use the upstream repo here, but I want to ensure
# that we're able to run the static analyzer locally too
- name: Pull configuration from xs-opam
run: |
curl --fail --silent https://raw.githubusercontent.com/edwintorok/xs-opam/master/tools/xs-opam-ci.env | cut -f2 -d " " > .env

- name: Load environment file
id: dotenv
uses: falti/[email protected]
with:
log-variables: true

- name: Use ocaml
uses: avsm/setup-ocaml@v2
with:
ocaml-compiler: ${{ steps.dotenv.outputs.ocaml_version_full }}
opam-repositories: |
default: ${{ steps.dotenv.outputs.repository }}
dune-cache: true
opam-local-packages: ${{ env.package }}.opam

- name: Install dependencies for static analyzer
run: |
opam update
opam install --deps-only ${{ env.package }}
opam install ${{ env.xapideps }}

# The checkout action performs a shallow, this triggers dune to set the
# version to <hash>-dirty. Work around this dune behaviour and tag the
# commit so a proper version is always picked up
- name: Tag current commit
run: |
git config user.name "Dune workaround"
git config user.email "<>"
git tag -am "workaround for dune" "$XAPI_VERSION"

- name: Configure
run: opam exec -- ./configure --xapi_version="$XAPI_VERSION"

- name: Run static analyzer
run: opam exec -- make analyze

- name: Upload SARIF report
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: _build/default/xapi.sarif
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ check:
clean:
dune clean

analyze:
dune build --profile=$(PROFILE) xapi.sarif

lint:
dune build @python
pylint --disable=line-too-long,too-few-public-methods,unused-argument,no-self-use,invalid-name,broad-except,protected-access,redefined-builtin,too-many-lines,wildcard-import,too-many-branches,too-many-arguments,unused-wildcard-import,raising-format-tuple,too-many-statements,duplicate-code _build/default/xapi-storage/python/xapi/storage/api/v5/*.py
Expand All @@ -31,6 +34,7 @@ lint:
test:
dune runtest --profile=$(PROFILE) --no-buffer -j $(JOBS)
dune build @runtest-python --profile=$(PROFILE)
dune build @analyze --profile=$(PROFILE)

stresstest:
dune build @stresstest --profile=$(PROFILE) --no-buffer -j $(JOBS)
Expand Down Expand Up @@ -82,6 +86,7 @@ doc-json:

format:
dune build @fmt --auto-promote
git ls-files '*.c' '*.h' | xargs clang-format -i

.PHONY: quality-gate
quality-gate:
Expand Down Expand Up @@ -214,3 +219,10 @@ uninstall:
message-switch message-switch-async message-switch-cli message-switch-core message-switch-lwt \
message-switch-unix xapi-idl forkexec xapi-forkexecd xapi-storage xapi-storage-script xapi-log \
xapi-open-uri

compile_flags.txt: Makefile
(ocamlc -config-var ocamlc_cflags;\
ocamlc -config-var ocamlc_cppflags;\
echo -I$(shell ocamlc -where);\
echo -Wall -Wextra -Wstrict-prototypes -D_FORTIFY_SOURCE=2\
) | xargs -n1 echo >$@
90 changes: 90 additions & 0 deletions dune
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,93 @@
(executable
(name configure)
(libraries dune-configurator findlib cmdliner unix))


(rule
(with-stdout-to ctypesdir (run dirname %{lib:ctypes:cstubs_internals.h}))
)

; This is a single invocation but it is very quick (<0.2s),
; although depends on the machine sometimes can be ~1.5s too
; no need to parallelize, also output can be cached.
; Only depend on ML files that contain C stubs though,
; and these .ml also don't require preprocessing for easier use
(rule
(deps
ocaml/staticanalyzer/arity/lintcstubs_arity.exe
(:mlfiles
(glob_files ocaml/auth/*.ml)
(glob_files ocaml/libs/log/*.ml)
(glob_files ocaml/vhd-tool/src/channels.ml)
(glob_files ocaml/xenopsd/c_stubs/*.ml)
(glob_files ocaml/xxhash/lib/*.ml)
(glob_files unixpwd/src/*.ml)
))
(action
(with-stdout-to primitives.h
(run ocaml/staticanalyzer/arity/lintcstubs_arity.exe %{mlfiles})
))
)

(rule
(deps
ocaml/staticanalyzer/genmain/lintcstubs_genmain.exe
(:cmtfiles
(glob_files ocaml/auth/.pam.objs/byte/*.cmt)
(glob_files ocaml/libs/log/.log.objs/byte/*.cmt)
(glob_files ocaml/vhd-tool/src/.channel_stubs.objs/byte/*.cmt)
(glob_files ocaml/xenopsd/c_stubs/.xc_stubs.objs/byte/*.cmt)
(glob_files ocaml/xenopsd/c_stubs/.c_stubs.objs/byte/*.cmt)
(glob_files ocaml/xxhash/stubs/.xxhash_bindings.objs/byte/*.cmt)
(glob_files ocaml/xxhash/lib/.xxhash.objs/byte/*.cmt)
(glob_files unixpwd/src/.unixpwd.objs/byte/*.cmt)
)
)
(action
(with-stdout-to primitives.model.c
(run ocaml/staticanalyzer/genmain/lintcstubs_genmain.exe %{cmtfiles})
)
)
)

; once we upgrade to Dune 3.x we can use glob_files_rec here
(rule
(targets xapi.sarif lintcstubs.stdout)
(deps
(package xapi-lintcstubs)
(:headers (glob_files ocaml/auth/*.h) (glob_files unixpwd/c/*.h) primitives.h)
(:runtime_model ocaml/staticanalyzer/model/ocaml_runtime.model.c)
(:primitives_model primitives.model.c)
(:cstubs
(glob_files ocaml/auth/*.c)
(glob_files ocaml/libs/log/*.c)
(glob_files ocaml/vhd-tool/src/*.c)
(glob_files ocaml/xenopsd/c_stubs/*.c)
(glob_files unixpwd/c/unix*.c)))

; enable only errors from our analyses
; so that the paths in the .sarif will be correct a chdir is needed
; --disable warn.warning
(action
(progn
(run rm -f goblint.sarif)
(run ln -s %{read-lines:ctypesdir} ctypes)
(with-stdout-to lintcstubs.stdout
(run ocaml/staticanalyzer/lintcstubs.exe -o xapi.sarif --disable warn.info
--disable warn.unsound --disable warn.imprecise
--disable warn.deadcode
--disable warn.behavior
--set ana.activated "[\"ocamlcstubs\",\"escape\"]"
--sarif -I %{ocaml_where}
-I ocaml/auth -I ctypes -I unixpwd/c
%{primitives_model}
%{cstubs}
))))
)
; --enable dbg.debug --enable dbg.verbose
; TODO: show stderr too
(rule
(alias analyze)
(deps lintcstubs.stdout)
(action (diff xapi.stdout.reference %{deps}))
)
4 changes: 3 additions & 1 deletion dune-project
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
(lang dune 2.0)
(lang dune 2.8)
(cram enable)
(using dune_site 0.1)

(formatting (enabled_for ocaml))
2 changes: 1 addition & 1 deletion message-switch.opam
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ depends: [
"cmdliner"
"cohttp-async" {with-test}
"cohttp-lwt-unix"
"io-page-unix"
"io-page" {>= "2.4.0"}
"lwt_log"
"message-switch-async" {with-test}
"message-switch-lwt"
Expand Down
20 changes: 20 additions & 0 deletions ocaml/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# See ./CODING_STYLE
root = true

[*]
end_of_line = lf
indent_style = space
charset = utf-8
max_line_length = 79
trim_trailing_whitespace = true
insert_final_newline = true

# Makefiles must use tabs, otherwise they don't work
[{Makefile,*.mk,Makefile.rules}]
indent_style = tabs

[*.{c,h}]
indent_size = 4

[*.{ml,mli}]
indent_size = 2
Loading