Skip to content

Commit cdffe9a

Browse files
authored
Merge pull request #6076 from TGWDB/inlining-bug-6065
Ensure locations are updated during instrumenting preconditions
2 parents 0ea7f13 + c065f64 commit cdffe9a

File tree

7 files changed

+117
-4
lines changed

7 files changed

+117
-4
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
This subdirectory is for tests where goto-cc is used to produce
2+
a goto binary that is then passed to goto-analyzer. There is also
3+
the option to have a custom script to produce the goto binary
4+
should this require special handling or multiple steps. This
5+
script is run if the root name of the test file has a script with
6+
the same filename. For example, if the desc file specifies
7+
test.c as the test file then the chain.sh script will check for
8+
the existence of test.sh and if test.sh exists then it will be used
9+
to build the goto binary (assumed to be test.gb).

regression/goto-cc-goto-analyzer/chain.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@ is_windows=$3
99
options=${*:4:$#-4}
1010
name=${*:$#}
1111
name=${name%.c}
12+
buildgoto=${name}.sh
1213

13-
if [[ "${is_windows}" == "true" ]]; then
14-
"${goto_cc}" "${name}.c"
15-
mv "${name}.exe" "${name}.gb"
14+
if test -f ${buildgoto}; then
15+
./${buildgoto} ${goto_cc} ${is_windows}
1616
else
17-
"${goto_cc}" "${name}.c" -o "${name}.gb"
17+
if [[ "${is_windows}" == "true" ]]; then
18+
"${goto_cc}" "${name}.c"
19+
mv "${name}.exe" "${name}.gb"
20+
else
21+
"${goto_cc}" "${name}.c" -o "${name}.gb"
22+
fi
1823
fi
1924

2025
"${goto_analyzer}" "${name}.gb" ${options}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// This file is highly reduced from some open source projects.
2+
// The following four lines are adapted from the openssl library
3+
// Full repository here:
4+
// Exact file adapted from here: https://github.com/openssl/openssl/tree/master
5+
// https://github.com/openssl/openssl/blob/master/crypto/evp/evp_local.h
6+
struct evp_md_ctx_st
7+
{
8+
const void *digest;
9+
};
10+
// The rest of this file is adapted from, various files in the
11+
// AWS s2n library. Full repository and licence information is
12+
// available here: https://github.com/aws/s2n-tls
13+
// Note that this is a highly cut down synthesis of many files
14+
// with most of their content and structure reduced.
15+
struct s2n_evp_digest
16+
{
17+
const void *ctx;
18+
};
19+
union s2n_hash_low_level_digest {
20+
};
21+
struct s2n_hash_evp_digest
22+
{
23+
struct s2n_evp_digest evp_md5_secondary;
24+
};
25+
struct s2n_hash_state
26+
{
27+
const struct s2n_hash *hash_impl;
28+
union {
29+
union s2n_hash_low_level_digest low_level;
30+
struct s2n_hash_evp_digest high_level;
31+
} digest;
32+
};
33+
struct s2n_hash
34+
{
35+
int (*free)(struct s2n_hash_state *state);
36+
};
37+
void EVP_MD_CTX_free(struct evp_md_ctx_st *ctx)
38+
{
39+
free(ctx->digest);
40+
free(ctx);
41+
}
42+
static int s2n_evp_hash_free(struct s2n_hash_state *state)
43+
{
44+
(EVP_MD_CTX_free((state->digest.high_level.evp_md5_secondary.ctx)));
45+
return 0;
46+
}
47+
static const struct s2n_hash s2n_evp_hash = {
48+
.free = &s2n_evp_hash_free,
49+
};
50+
static int s2n_hash_set_impl(struct s2n_hash_state *state)
51+
{
52+
state->hash_impl = &s2n_evp_hash;
53+
return 0;
54+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// This is highly adapted from the AWS s2n library.
2+
// Full repository and information here: https://github.com/aws/s2n-tls
3+
void s2n_hash_free_harness()
4+
{
5+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CORE
2+
test.c
3+
--verify
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
Checking assertions
7+
^\[EVP_MD_CTX_free.precondition_instance.1\] line \d+ free argument must be NULL or valid pointer: SUCCESS
8+
--
9+
Invariant check failed
10+
--
11+
This test checks that after building the goto binary (see test.sh)
12+
that there is no errors that lead to invariant violations.
13+
This was created after a bug was found due to the
14+
instrument_preconditions code not correctly fixing locations and
15+
the invariant check of partial inlining detecting this location
16+
inconsistency.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
goto_cc=$1
5+
is_windows=$2
6+
7+
if [[ "${is_windows}" == "true" ]]; then
8+
${goto_cc} --export-file-local-symbols simple.c
9+
mv simple.exe simple.gb
10+
${goto_cc} --export-file-local-symbols s2n_hash_inlined.c
11+
mv s2n_hash_inlined.exe s2n_hash_inlined.gb
12+
${goto_cc} --function s2n_hash_free_harness simple.gb s2n_hash_inlined.gb
13+
mv simple.exe test.gb
14+
else
15+
${goto_cc} --export-file-local-symbols simple.c -o simple.gb
16+
${goto_cc} --export-file-local-symbols s2n_hash_inlined.c -o s2n_hash_inlined.gb
17+
${goto_cc} --function s2n_hash_free_harness simple.gb s2n_hash_inlined.gb -o test.gb
18+
fi

src/goto-programs/instrument_preconditions.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ void instrument_preconditions(goto_modelt &goto_model)
141141
// now remove the preconditions
142142
for(auto &f_it : goto_model.goto_functions.function_map)
143143
remove_preconditions(f_it.second.body);
144+
// The above may leave some locations uninitialized, this update is a
145+
// sanity to check to ensure the goto model and functions are correct
146+
// for later passes.
147+
// Note that only the first loop is the one known to leave locations
148+
// uninitialized.
149+
goto_model.goto_functions.update();
144150
}
145151

146152
void remove_preconditions(goto_functiont &goto_function)

0 commit comments

Comments
 (0)