Skip to content

Commit a470348

Browse files
karkhazdanielsn
andauthored
Temporarily disable the __CPROVER_{r,w}_ok macros (#600)
* Temporarily disable the __CPROVER_{r,w}_ok macros This is while we work to resolve an issue with CBMC, described at diffblue/cbmc#5194 * fix aws_array_list_back * fix aws_array_list_front * fix aws_array_list_get_at * fix aws_byte_cursor_read_u8 proof * fix CBMC proof for aws_array_list_set_at * fix aws_byte_buf_write_from_whole_cursor CBMC proof, and minor issue in aws_byte_buf_write * fix CBMC proof for aws_array_list_push_back * fix byte_cursor read proofs Co-authored-by: Daniel Schwartz-Narbonne <[email protected]>
1 parent a798f57 commit a470348

File tree

24 files changed

+42
-48
lines changed

24 files changed

+42
-48
lines changed

.cbmc-batch/include/proof_helpers/aws_byte_cursor_read_common.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
void aws_byte_cursor_read_common_harness() {
2121
/* parameters */
2222
struct aws_byte_cursor cur;
23-
size_t length;
24-
DEST_TYPE *dest = can_fail_malloc(length);
23+
DEST_TYPE *dest = can_fail_malloc(sizeof(*dest));
2524

2625
/* assumptions */
2726
ensure_byte_cursor_has_allocated_buffer_member(&cur);
2827
__CPROVER_assume(aws_byte_cursor_is_valid(&cur));
28+
__CPROVER_assume(cur.len >= BYTE_WIDTH);
2929
__CPROVER_assume(AWS_MEM_IS_READABLE(cur.ptr, BYTE_WIDTH));
30-
__CPROVER_assume(AWS_OBJECT_PTR_IS_WRITABLE(dest));
30+
__CPROVER_assume(dest != NULL);
3131

3232
/* save current state of the data structure */
3333
struct aws_byte_cursor old_cur = cur;

.cbmc-batch/jobs/aws_array_list_back/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ DEPENDENCIES += $(HELPERDIR)/source/proof_allocators.c
2323
DEPENDENCIES += $(HELPERDIR)/source/make_common_data_structures.c
2424
DEPENDENCIES += $(HELPERDIR)/source/utils.c
2525
DEPENDENCIES += $(HELPERDIR)/stubs/error.c
26-
DEPENDENCIES += $(HELPERDIR)/stubs/memcpy_override.c
2726
DEPENDENCIES += $(SRCDIR)/source/array_list.c
2827
DEPENDENCIES += $(SRCDIR)/source/common.c
2928

.cbmc-batch/jobs/aws_array_list_back/aws_array_list_back_harness.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,12 @@ void aws_array_list_back_harness() {
2323

2424
/* data structure */
2525
struct aws_array_list list;
26+
void *val = can_fail_malloc(list.item_size);
2627

2728
/* assumptions */
2829
__CPROVER_assume(aws_array_list_is_bounded(&list, MAX_INITIAL_ITEM_ALLOCATION, MAX_ITEM_SIZE));
2930
ensure_array_list_has_allocated_data_member(&list);
3031
__CPROVER_assume(aws_array_list_is_valid(&list));
31-
size_t malloc_size;
32-
__CPROVER_assume(malloc_size <= list.item_size);
33-
void *val = can_fail_malloc(malloc_size);
3432

3533
/* save current state of the data structure */
3634
struct aws_array_list old = list;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
jobos: ubuntu16
21
cbmcflags: "--bounds-check;--div-by-zero-check;--float-overflow-check;--nan-check;--pointer-check;--pointer-overflow-check;--signed-overflow-check;--undefined-shift-check;--unsigned-overflow-check;--unwind;1;--unwinding-assertions;--unwindset;memcpy_impl.0:3;--object-bits;8"
3-
goto: aws_array_list_back_harness.goto
42
expected: "SUCCESSFUL"
3+
goto: aws_array_list_back_harness.goto
4+
jobos: ubuntu16

.cbmc-batch/jobs/aws_array_list_front/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ DEPENDENCIES += $(HELPERDIR)/source/proof_allocators.c
2626
DEPENDENCIES += $(HELPERDIR)/source/make_common_data_structures.c
2727
DEPENDENCIES += $(HELPERDIR)/source/utils.c
2828
DEPENDENCIES += $(HELPERDIR)/stubs/error.c
29-
DEPENDENCIES += $(HELPERDIR)/stubs/memcpy_override.c
3029
DEPENDENCIES += $(SRCDIR)/source/array_list.c
3130
DEPENDENCIES += $(SRCDIR)/source/common.c
3231

.cbmc-batch/jobs/aws_array_list_front/aws_array_list_front_harness.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ void aws_array_list_front_harness() {
2727
__CPROVER_assume(aws_array_list_is_bounded(&list, MAX_INITIAL_ITEM_ALLOCATION, MAX_ITEM_SIZE));
2828
ensure_array_list_has_allocated_data_member(&list);
2929
__CPROVER_assume(aws_array_list_is_valid(&list));
30-
size_t malloc_size;
31-
__CPROVER_assume(malloc_size <= list.item_size);
32-
void *val = can_fail_malloc(malloc_size);
30+
void *val = can_fail_malloc(list.item_size);
3331

3432
/* save current state of the data structure */
3533
struct aws_array_list old = list;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
jobos: ubuntu16
21
cbmcflags: "--bounds-check;--div-by-zero-check;--float-overflow-check;--nan-check;--pointer-check;--pointer-overflow-check;--signed-overflow-check;--undefined-shift-check;--unsigned-overflow-check;--unwind;1;--unwinding-assertions;--unwindset;memcpy_impl.0:3;--object-bits;8"
3-
goto: aws_array_list_front_harness.goto
42
expected: "SUCCESSFUL"
3+
goto: aws_array_list_front_harness.goto
4+
jobos: ubuntu16

.cbmc-batch/jobs/aws_array_list_get_at/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ DEPENDENCIES += $(HELPERDIR)/source/proof_allocators.c
2323
DEPENDENCIES += $(HELPERDIR)/source/make_common_data_structures.c
2424
DEPENDENCIES += $(HELPERDIR)/source/utils.c
2525
DEPENDENCIES += $(HELPERDIR)/stubs/error.c
26-
DEPENDENCIES += $(HELPERDIR)/stubs/memcpy_override.c
2726
DEPENDENCIES += $(SRCDIR)/source/array_list.c
2827
DEPENDENCIES += $(SRCDIR)/source/common.c
2928

.cbmc-batch/jobs/aws_array_list_get_at/aws_array_list_get_at_harness.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ void aws_array_list_get_at_harness() {
2727
__CPROVER_assume(aws_array_list_is_bounded(&list, MAX_INITIAL_ITEM_ALLOCATION, MAX_ITEM_SIZE));
2828
ensure_array_list_has_allocated_data_member(&list);
2929
__CPROVER_assume(aws_array_list_is_valid(&list));
30-
size_t malloc_size;
31-
__CPROVER_assume(malloc_size <= list.item_size);
32-
void *val = can_fail_malloc(malloc_size);
30+
void *val = can_fail_malloc(list.item_size);
3331
size_t index;
3432

3533
/* save current state of the data structure */
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
jobos: ubuntu16
21
cbmcflags: "--bounds-check;--div-by-zero-check;--float-overflow-check;--nan-check;--pointer-check;--pointer-overflow-check;--signed-overflow-check;--undefined-shift-check;--unsigned-overflow-check;--unwind;1;--unwinding-assertions;--unwindset;memcpy_impl.0:3;--object-bits;8"
3-
goto: aws_array_list_get_at_harness.goto
42
expected: "SUCCESSFUL"
3+
goto: aws_array_list_get_at_harness.goto
4+
jobos: ubuntu16

.cbmc-batch/jobs/aws_array_list_push_back/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ DEPENDENCIES += $(HELPERDIR)/source/proof_allocators.c
2222
DEPENDENCIES += $(HELPERDIR)/source/make_common_data_structures.c
2323
DEPENDENCIES += $(HELPERDIR)/source/utils.c
2424
DEPENDENCIES += $(HELPERDIR)/stubs/error.c
25-
DEPENDENCIES += $(HELPERDIR)/stubs/memcpy_override_no_op.c
2625
DEPENDENCIES += $(SRCDIR)/source/array_list.c
2726
DEPENDENCIES += $(SRCDIR)/source/common.c
2827

.cbmc-batch/jobs/aws_array_list_push_back/aws_array_list_push_back_harness.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include <proof_helpers/make_common_data_structures.h>
1818

1919
/**
20-
* Runtime: 18s
20+
* Runtime: 4 min
2121
*/
2222
void aws_array_list_push_back_harness() {
2323
/* data structure */
@@ -28,9 +28,7 @@ void aws_array_list_push_back_harness() {
2828
ensure_array_list_has_allocated_data_member(&list);
2929
__CPROVER_assume(aws_array_list_is_valid(&list));
3030
__CPROVER_assume(list.data != NULL);
31-
size_t malloc_size;
32-
__CPROVER_assume(malloc_size <= list.item_size);
33-
void *val = can_fail_malloc(malloc_size);
31+
void *val = can_fail_malloc(list.item_size);
3432

3533
/* save current state of the data structure */
3634
struct aws_array_list old = list;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
jobos: ubuntu16
21
cbmcflags: "--bounds-check;--div-by-zero-check;--float-overflow-check;--nan-check;--pointer-check;--pointer-overflow-check;--signed-overflow-check;--undefined-shift-check;--unsigned-overflow-check;--unwind;1;--unwinding-assertions;--object-bits;8"
3-
goto: aws_array_list_push_back_harness.goto
42
expected: "SUCCESSFUL"
3+
goto: aws_array_list_push_back_harness.goto
4+
jobos: ubuntu16

.cbmc-batch/jobs/aws_array_list_set_at/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ DEPENDENCIES += $(HELPERDIR)/source/proof_allocators.c
2222
DEPENDENCIES += $(HELPERDIR)/source/make_common_data_structures.c
2323
DEPENDENCIES += $(HELPERDIR)/source/utils.c
2424
DEPENDENCIES += $(HELPERDIR)/stubs/error.c
25-
DEPENDENCIES += $(HELPERDIR)/stubs/memcpy_override_no_op.c
2625
DEPENDENCIES += $(SRCDIR)/source/array_list.c
2726
DEPENDENCIES += $(SRCDIR)/source/common.c
2827

.cbmc-batch/jobs/aws_array_list_set_at/aws_array_list_set_at_harness.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include <proof_helpers/make_common_data_structures.h>
1818

1919
/**
20-
* Runtime: 20s
20+
* Runtime: 3m 42s
2121
*/
2222
void aws_array_list_set_at_harness() {
2323
/* data structure */
@@ -29,8 +29,7 @@ void aws_array_list_set_at_harness() {
2929
__CPROVER_assume(aws_array_list_is_valid(&list));
3030
__CPROVER_assume(list.data != NULL);
3131
size_t malloc_size;
32-
__CPROVER_assume(malloc_size <= list.item_size);
33-
void *val = can_fail_malloc(malloc_size);
32+
void *val = can_fail_malloc(list.item_size);
3433
size_t index;
3534

3635
/* save current state of the data structure */
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
jobos: ubuntu16
21
cbmcflags: "--bounds-check;--div-by-zero-check;--float-overflow-check;--nan-check;--pointer-check;--pointer-overflow-check;--signed-overflow-check;--undefined-shift-check;--unsigned-overflow-check;--unwind;1;--unwinding-assertions;--object-bits;8"
3-
goto: aws_array_list_set_at_harness.goto
42
expected: "SUCCESSFUL"
3+
goto: aws_array_list_set_at_harness.goto
4+
jobos: ubuntu16

.cbmc-batch/jobs/aws_byte_buf_write_from_whole_cursor/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ DEPENDENCIES += $(HELPERDIR)/source/make_common_data_structures.c
2222
DEPENDENCIES += $(HELPERDIR)/source/proof_allocators.c
2323
DEPENDENCIES += $(HELPERDIR)/source/utils.c
2424
DEPENDENCIES += $(HELPERDIR)/stubs/error.c
25-
DEPENDENCIES += $(HELPERDIR)/stubs/memcpy_override.c
2625
DEPENDENCIES += $(SRCDIR)/source/byte_buf.c
2726
DEPENDENCIES += $(SRCDIR)/source/common.c
2827

.cbmc-batch/jobs/aws_byte_buf_write_from_whole_cursor/aws_byte_buf_write_from_whole_cursor_harness.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ void aws_byte_buf_write_from_whole_cursor_harness() {
2828
__CPROVER_assume(aws_byte_cursor_is_bounded(&src, MAX_BUFFER_SIZE));
2929
ensure_byte_cursor_has_allocated_buffer_member(&src);
3030
__CPROVER_assume(aws_byte_cursor_is_valid(&src));
31-
__CPROVER_assume(AWS_MEM_IS_WRITABLE(src.ptr, src.len));
3231

3332
/* save current state of the parameters */
3433
struct aws_byte_buf buf_old = buf;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
jobos: ubuntu16
21
cbmcflags: "--bounds-check;--div-by-zero-check;--float-overflow-check;--nan-check;--pointer-check;--pointer-overflow-check;--signed-overflow-check;--undefined-shift-check;--unsigned-overflow-check;--unwind;1;--unwinding-assertions;--unwindset;memcpy_impl.0:11;--object-bits;8"
3-
goto: aws_byte_buf_write_from_whole_cursor_harness.goto
42
expected: "SUCCESSFUL"
3+
goto: aws_byte_buf_write_from_whole_cursor_harness.goto
4+
jobos: ubuntu16
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
jobos: ubuntu16
21
cbmcflags: "--bounds-check;--div-by-zero-check;--float-overflow-check;--nan-check;--pointer-check;--pointer-overflow-check;--signed-overflow-check;--undefined-shift-check;--unsigned-overflow-check;--unwind;1;--unwinding-assertions;--object-bits;8"
3-
goto: aws_byte_cursor_read_be16_harness.goto
42
expected: "SUCCESSFUL"
3+
goto: aws_byte_cursor_read_be16_harness.goto
4+
jobos: ubuntu16

.cbmc-batch/jobs/aws_byte_cursor_read_u8/aws_byte_cursor_read_u8_harness.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ void aws_byte_cursor_read_u8_harness() {
2121
/* parameters */
2222
struct aws_byte_cursor cur;
2323
size_t length;
24+
__CPROVER_assume(length >=1);
2425
uint8_t *dest = bounded_malloc(length);
2526

2627
/* assumptions */
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
jobos: ubuntu16
21
cbmcflags: "--bounds-check;--div-by-zero-check;--float-overflow-check;--nan-check;--pointer-check;--pointer-overflow-check;--signed-overflow-check;--undefined-shift-check;--unsigned-overflow-check;--unwind;1;--unwinding-assertions;--object-bits;8"
3-
goto: aws_byte_cursor_read_u8_harness.goto
42
expected: "SUCCESSFUL"
3+
goto: aws_byte_cursor_read_u8_harness.goto
4+
jobos: ubuntu16

include/aws/common/assert.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ AWS_EXTERN_C_END
9696
# define AWS_POSTCONDITION1(cond) __CPROVER_assert((cond), # cond " check failed")
9797
# define AWS_FATAL_POSTCONDITION2(cond, explanation) __CPROVER_assert((cond), (explanation))
9898
# define AWS_FATAL_POSTCONDITION1(cond) __CPROVER_assert((cond), # cond " check failed")
99-
# define AWS_MEM_IS_READABLE(base, len) __CPROVER_r_ok((base), (len))
100-
# define AWS_MEM_IS_WRITABLE(base, len) __CPROVER_w_ok((base), (len))
10199
#else
102100
# define AWS_PRECONDITION2(cond, expl) AWS_ASSERT(cond)
103101
# define AWS_PRECONDITION1(cond) AWS_ASSERT(cond)
@@ -107,12 +105,17 @@ AWS_EXTERN_C_END
107105
# define AWS_POSTCONDITION1(cond) AWS_ASSERT(cond)
108106
# define AWS_FATAL_POSTCONDITION2(cond, expl) AWS_FATAL_ASSERT(cond)
109107
# define AWS_FATAL_POSTCONDITION1(cond) AWS_FATAL_ASSERT(cond)
108+
#endif /* CBMC */
110109

111110
/* the C runtime does not give a way to check these properties,
112-
* but we can at least check that the pointer is valid */
113-
# define AWS_MEM_IS_READABLE(base, len) (((len) == 0) || (base))
114-
# define AWS_MEM_IS_WRITABLE(base, len) (((len) == 0) || (base))
115-
#endif /* CBMC */
111+
* but we can at least check that the pointer is valid.
112+
* these macros are intended to be used with CBMC proofs, but will not use CBMC
113+
* intrinsics until https://github.com/diffblue/cbmc/issues/5194 is fixed.*/
114+
#define AWS_MEM_IS_READABLE(base, len) (((len) == 0) || (base))
115+
#define AWS_MEM_IS_WRITABLE(base, len) (((len) == 0) || (base))
116+
117+
#define __CPROVER_r_ok(base, len) (AWS_MEM_IS_READABLE(base, len))
118+
#define __CPROVER_w_ok(base, len) (AWS_MEM_IS_WRITEABLE(base, len))
116119

117120
#define AWS_RETURN_ERROR_IF_IMPL(type, cond, err, explanation) \
118121
do { \

source/byte_buf.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,7 @@ bool aws_byte_cursor_read_and_fill_buffer(
10801080
*/
10811081
bool aws_byte_cursor_read_u8(struct aws_byte_cursor *AWS_RESTRICT cur, uint8_t *AWS_RESTRICT var) {
10821082
AWS_PRECONDITION(aws_byte_cursor_is_valid(cur));
1083+
AWS_PRECONDITION(AWS_MEM_IS_WRITABLE(var, 1));
10831084
bool rv = aws_byte_cursor_read(cur, var, 1);
10841085
AWS_POSTCONDITION(aws_byte_cursor_is_valid(cur));
10851086
return rv;
@@ -1262,6 +1263,11 @@ bool aws_byte_buf_write(struct aws_byte_buf *AWS_RESTRICT buf, const uint8_t *AW
12621263
AWS_PRECONDITION(aws_byte_buf_is_valid(buf));
12631264
AWS_PRECONDITION(AWS_MEM_IS_READABLE(src, len), "Input array [src] must be readable up to [len] bytes.");
12641265

1266+
if (len == 0) {
1267+
AWS_POSTCONDITION(aws_byte_buf_is_valid(buf));
1268+
return true;
1269+
}
1270+
12651271
if (buf->len > (SIZE_MAX >> 1) || len > (SIZE_MAX >> 1) || buf->len + len > buf->capacity) {
12661272
AWS_POSTCONDITION(aws_byte_buf_is_valid(buf));
12671273
return false;

0 commit comments

Comments
 (0)