-
Notifications
You must be signed in to change notification settings - Fork 74
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
Added CBMC proof of stringBuilder function #255
Changes from 33 commits
0bbf408
95529f8
21ee448
4b189aa
ae17c09
4a2ed43
6c5d6f5
b4a774c
db409b7
402e6b8
92b5b00
62ddec4
67ad6b0
1f5668f
3bda16a
2c7f2ee
e88c8c0
d274f81
a085b6a
fcb1efe
76eebdd
4620878
69d28c6
4013be0
e684033
08fa29e
5a72e20
d470ee5
3902fbd
a44ccc8
089cee5
27b1a18
1762c85
6d32385
6c8a0e3
278419c
7b794e3
e1fd68b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
HARNESS_ENTRY = stringBuilder_harness | ||
HARNESS_FILE = $(HARNESS_ENTRY) | ||
|
||
# This should be a unique identifier for this proof, and will appear on the | ||
# Litani dashboard. It can be human-readable and contain spaces if you wish. | ||
PROOF_UID = stringBuilder | ||
|
||
DEFINES += | ||
INCLUDES += | ||
|
||
REMOVE_FUNCTION_BODY += | ||
UNWINDSET += | ||
|
||
CBMC_FLAG_UNWINDING_ASSERTIONS = | ||
|
||
PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c | ||
PROJECT_SOURCES += $(SRCDIR)/source/ota_mqtt.c | ||
|
||
# If this proof is found to consume huge amounts of RAM, you can set the | ||
# EXPENSIVE variable. With new enough versions of the proof tools, this will | ||
# restrict the number of EXPENSIVE CBMC jobs running at once. See the | ||
# documentation in Makefile.common under the "Job Pools" heading for details. | ||
# EXPENSIVE = true | ||
|
||
include ../Makefile.common |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
stringBuilder proof | ||
============== | ||
|
||
This directory contains a memory safety proof for stringBuilder. | ||
|
||
To run the proof. | ||
------------- | ||
|
||
* Add `cbmc`, `goto-cc`, `goto-instrument`, `goto-analyzer`, and `cbmc-viewer` | ||
to your path. | ||
* Run `make`. | ||
* Open html/index.html in a web browser. | ||
|
||
To use [`arpa`](https://github.com/awslabs/aws-proof-build-assistant) to simplify writing Makefiles. | ||
------------- | ||
|
||
* Run `make arpa` to generate a Makefile.arpa that contains relevant build information for the proof. | ||
* Use Makefile.arpa as the starting point for your proof Makefile by: | ||
1. Modifying Makefile.arpa (if required). | ||
2. Including Makefile.arpa into the existing proof Makefile (add `sinclude Makefile.arpa` at the bottom of the Makefile, right before `include ../Makefile.common`). |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# This file marks this directory as containing a CBMC proof. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ "expected-missing-functions": | ||
[ | ||
], | ||
"proof-name": "<__FUNCTION_NAME__>", | ||
"proof-root": "<__PATH_TO_PROOF_ROOT__>" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. */ | ||
/* SPDX-License-Identifier: Apache-2.0 */ | ||
|
||
/** | ||
* @file stringBuilder_harness.c | ||
* @brief Implements the proof harness for stringBuilder function. | ||
*/ | ||
#include "ota_mqtt_private.h" | ||
|
||
/* Declaration of the mangled name function generated by CBMC for static functions. */ | ||
size_t __CPROVER_file_local_ota_mqtt_c_stringBuilder( char * pBuffer, | ||
size_t bufferSizeBytes, | ||
const char * strings[] ); | ||
|
||
void stringBuilder_harness() | ||
{ | ||
char * pBuffer; | ||
size_t bufferSizeBytes; | ||
char ** strings; | ||
|
||
size_t numStrings; | ||
size_t stringSize; | ||
size_t i; | ||
size_t stringLength; | ||
|
||
/* The pBuffer is statically allocated with a non-zero size before passing it to the stringBuilder function.*/ | ||
__CPROVER_assume( bufferSizeBytes > 0 ); | ||
pBuffer = ( char * ) malloc( bufferSizeBytes ); | ||
|
||
/* pBuffer can never be NULL since it it always initialized before passing it to the stringBuilder function. */ | ||
__CPROVER_assume( pBuffer != NULL ); | ||
|
||
/* The minimum and the maximum number of strings inside the numStrings is 11. */ | ||
__CPROVER_assume( numStrings > 0 && numStrings < UINT32_MAX ); | ||
|
||
/* Initializing an array of strings with size numStrings. */ | ||
strings = ( char ** ) malloc( numStrings * sizeof( char * ) ); | ||
|
||
/* The strings array cannot be NULL as it is always initialized before | ||
* passing to the function. */ | ||
__CPROVER_assume( strings != NULL ); | ||
|
||
for( i = 0; i < numStrings - 1; ++i ) | ||
{ | ||
strings[ i ] = ( char * ) malloc( stringSize ); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This condition: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. I have changed the free statement accordingly. In this proof I only to allocate memory for the first |
||
|
||
/* Strings array is always passed with a NULL string at the end. */ | ||
__CPROVER_assume( strings[ numStrings - 1 ] == NULL ); | ||
yanjos-dev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
__CPROVER_file_local_ota_mqtt_c_stringBuilder( pBuffer, bufferSizeBytes, strings ); | ||
|
||
/* Free the allocated memory. */ | ||
free( pBuffer ); | ||
|
||
for( i = 0; i < numStrings; ++i ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should match your previous memory allocation. I think this is correct though and that the malloc code needs to change, as commented above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated it in 6d32385 |
||
{ | ||
free( strings[ i ] ); | ||
} | ||
|
||
free( strings ); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This wording sounds like you are saying both the min and the max are 11. I think you mean to say that the min is 0 and the max is 11.
Also, if the max is 11, then why have the assumption go to UINT32_MAX?
size_t
is also a signed data type, so it doesn't make sense to compare it to UINT32_MAX.