Skip to content

Commit 662c214

Browse files
committed
test: Add goblint static analyser.
1 parent 8f07755 commit 662c214

File tree

6 files changed

+195
-1
lines changed

6 files changed

+195
-1
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
analysis:
1717
strategy:
1818
matrix:
19-
tool: [autotools, clang-tidy, compcert, cppcheck, doxygen, infer, misra, tcc, tokstyle]
19+
tool: [autotools, clang-tidy, compcert, cppcheck, doxygen, goblint, infer, misra, tcc, tokstyle]
2020
runs-on: ubuntu-latest
2121
steps:
2222
- name: Set up Docker Buildx

other/docker/goblint/BUILD.bazel

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
load("@rules_cc//cc:defs.bzl", "cc_library")
2+
3+
cc_library(
4+
name = "sodium",
5+
testonly = True,
6+
srcs = ["sodium.c"],
7+
deps = ["@libsodium"],
8+
)

other/docker/goblint/Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
FROM ghcr.io/goblint/analyzer:latest
2+
3+
RUN apt-get update && \
4+
DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
5+
libsodium-dev \
6+
tcc \
7+
&& apt-get clean \
8+
&& rm -rf /var/lib/apt/lists/*
9+
10+
WORKDIR /work
11+
COPY auto_tests/ /work/auto_tests/
12+
COPY testing/ /work/testing/
13+
COPY toxav/ /work/toxav/
14+
COPY toxcore/ /work/toxcore/
15+
COPY toxencryptsave/ /work/toxencryptsave/
16+
COPY third_party/ /work/third_party/
17+
18+
COPY other/make_single_file /work/other/
19+
COPY other/docker/goblint/sodium.c /work/other/docker/goblint/
20+
21+
RUN other/make_single_file -core auto_tests/tox_new_test.c other/docker/goblint/sodium.c > analysis.c
22+
# Try compiling+linking just to make sure we have all the fake functions.
23+
RUN tcc analysis.c
24+
25+
COPY other/docker/goblint/analysis.json /work/other/docker/goblint/
26+
RUN /opt/goblint/analyzer/bin/goblint --conf /work/other/docker/goblint/analysis.json analysis.c

other/docker/goblint/analysis.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"ana": {
3+
"activated": [
4+
"base","mallocWrapper","escape","mutex","mutexEvents","access","assert","expRelation"
5+
],
6+
"arrayoob": true,
7+
"wp": true,
8+
"apron": {
9+
"strengthening": true
10+
},
11+
"base": {
12+
"structs" : {
13+
"domain" : "combined-sk"
14+
},
15+
"arrays": {
16+
"domain": "partitioned"
17+
}
18+
},
19+
"malloc": {
20+
"wrappers": [
21+
"mem_balloc",
22+
"mem_alloc",
23+
"mem_valloc",
24+
"mem_vrealloc"
25+
]
26+
}
27+
},
28+
"warn": {
29+
"behavior": false,
30+
"call": false,
31+
"integer": true,
32+
"float": false,
33+
"race": false,
34+
"deadcode": false,
35+
"unsound": false,
36+
"imprecise": false,
37+
"success": false,
38+
"unknown": false
39+
},
40+
"exp": {
41+
"earlyglobs": true
42+
}
43+
}

other/docker/goblint/run

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
3+
set -eux
4+
BUILD=goblint
5+
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" .

other/docker/goblint/sodium.c

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#include <sodium.h>
2+
3+
#include <string.h>
4+
5+
int crypto_sign_keypair(unsigned char *pk, unsigned char *sk)
6+
{
7+
memset(pk, 0, 32);
8+
memset(sk, 0, 32);
9+
return 0;
10+
}
11+
int crypto_sign_ed25519_pk_to_curve25519(unsigned char *curve25519_pk,
12+
const unsigned char *ed25519_pk)
13+
{
14+
memset(curve25519_pk, 0, 32);
15+
return 0;
16+
}
17+
int crypto_sign_ed25519_sk_to_curve25519(unsigned char *curve25519_sk,
18+
const unsigned char *ed25519_sk)
19+
{
20+
memset(curve25519_sk, 0, 32);
21+
return 0;
22+
}
23+
void sodium_memzero(void * const pnt, const size_t len)
24+
{
25+
memset(pnt, 0, len);
26+
}
27+
int sodium_mlock(void * const addr, const size_t len)
28+
{
29+
return 0;
30+
}
31+
int sodium_munlock(void * const addr, const size_t len)
32+
{
33+
return 0;
34+
}
35+
int crypto_verify_32(const unsigned char *x, const unsigned char *y)
36+
{
37+
return memcmp(x, y, 32);
38+
}
39+
int crypto_verify_64(const unsigned char *x, const unsigned char *y)
40+
{
41+
return memcmp(x, y, 64);
42+
}
43+
int crypto_sign_detached(unsigned char *sig, unsigned long long *siglen_p,
44+
const unsigned char *m, unsigned long long mlen,
45+
const unsigned char *sk)
46+
{
47+
return 0;
48+
}
49+
int crypto_sign_verify_detached(const unsigned char *sig,
50+
const unsigned char *m,
51+
unsigned long long mlen,
52+
const unsigned char *pk)
53+
{
54+
return 0;
55+
}
56+
int crypto_box_beforenm(unsigned char *k, const unsigned char *pk,
57+
const unsigned char *sk)
58+
{
59+
memset(k, 0, 32);
60+
return 0;
61+
}
62+
int crypto_box_afternm(unsigned char *c, const unsigned char *m,
63+
unsigned long long mlen, const unsigned char *n,
64+
const unsigned char *k)
65+
{
66+
memset(c, 0, 32);
67+
return 0;
68+
}
69+
int crypto_box_open_afternm(unsigned char *m, const unsigned char *c,
70+
unsigned long long clen, const unsigned char *n,
71+
const unsigned char *k)
72+
{
73+
return 0;
74+
}
75+
int crypto_scalarmult_curve25519_base(unsigned char *q,
76+
const unsigned char *n)
77+
{
78+
memset(q, 0, 32);
79+
return 0;
80+
}
81+
int crypto_auth(unsigned char *out, const unsigned char *in,
82+
unsigned long long inlen, const unsigned char *k)
83+
{
84+
return 0;
85+
}
86+
int crypto_auth_verify(const unsigned char *h, const unsigned char *in,
87+
unsigned long long inlen, const unsigned char *k)
88+
{
89+
return 0;
90+
}
91+
int crypto_hash_sha256(unsigned char *out, const unsigned char *in,
92+
unsigned long long inlen)
93+
{
94+
return 0;
95+
}
96+
int crypto_hash_sha512(unsigned char *out, const unsigned char *in,
97+
unsigned long long inlen)
98+
{
99+
return 0;
100+
}
101+
void randombytes(unsigned char * const buf, const unsigned long long buf_len)
102+
{
103+
memset(buf, 0, buf_len);
104+
}
105+
uint32_t randombytes_uniform(const uint32_t upper_bound)
106+
{
107+
return upper_bound;
108+
}
109+
int sodium_init(void)
110+
{
111+
return 0;
112+
}

0 commit comments

Comments
 (0)