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

Added CBMC proof of stringBuilder function #255

Merged
merged 38 commits into from
Sep 9, 2021
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
0bbf408
Add CBMC-proofs infrastructure
Bujain Aug 4, 2021
95529f8
Add CBMC-proofs infrastructure (#242)
Bujain Aug 5, 2021
21ee448
Added value to not update the submodule
Bujain Aug 5, 2021
4b189aa
Added Include paths and preprocessor defines
Bujain Aug 5, 2021
ae17c09
Added template define file
Bujain Aug 5, 2021
4a2ed43
Updated to ignore the output files on git push
Bujain Aug 5, 2021
6c5d6f5
Added words
Bujain Aug 5, 2021
b4a774c
Updated Project Name
Bujain Aug 5, 2021
db409b7
Updated source directory path
Bujain Aug 5, 2021
402e6b8
Merge branch 'cbmc-proof' into cbmc_infra
AniruddhaKanhere Aug 5, 2021
92b5b00
Update ci.yml
AniruddhaKanhere Aug 5, 2021
62ddec4
Add checks on the branch
AniruddhaKanhere Aug 5, 2021
67ad6b0
Updated Submodule update value
Bujain Aug 5, 2021
1f5668f
Merge branch 'cbmc_infra' of https://github.com/Bujain/ota-for-aws-io…
Bujain Aug 5, 2021
3bda16a
Added litani submodule update
Bujain Aug 5, 2021
2c7f2ee
Update Project name
Bujain Aug 5, 2021
e88c8c0
Added new line in the end of the file
Bujain Aug 5, 2021
d274f81
Remove whitespace
AniruddhaKanhere Aug 5, 2021
a085b6a
Addition to CBMC infrastructure (#243)
Bujain Aug 5, 2021
fcb1efe
Added CBMC proof of setDataInterface function (#245)
Bujain Aug 6, 2021
76eebdd
Added CBMC-proof files of stringBuilder function
Bujain Aug 9, 2021
4620878
Updated assumptions
Bujain Aug 11, 2021
69d28c6
Updated assumptions'
Bujain Aug 12, 2021
4013be0
Removed copyright notice
Bujain Aug 12, 2021
e684033
Added CBMC proof of OTA_HTTP_strerror function (#252)
Bujain Aug 12, 2021
08fa29e
Add CBMC proofs for RequestdataBlock_Http function (#248)
Bujain Aug 12, 2021
5a72e20
Added CBMC proofs for OTA_MQTT_strerror function (#247)
Bujain Aug 12, 2021
d470ee5
Added CBMC proofs for setControlInterface function (#246)
Bujain Aug 12, 2021
3902fbd
Merge branch 'cbmc-proof' into stringBuilder
Bujain Aug 17, 2021
a44ccc8
Updated comments
Bujain Aug 17, 2021
089cee5
Merge branch 'stringBuilder' of https://github.com/Bujain/ota-for-aws…
Bujain Aug 17, 2021
27b1a18
Fix spell check and formatting errors
Bujain Aug 17, 2021
1762c85
Merge branch 'main' into stringBuilder
Bujain Aug 31, 2021
6d32385
Added null terminator to every string
Bujain Sep 2, 2021
6c8a0e3
Merge branch 'main' into stringBuilder
Bujain Sep 9, 2021
278419c
Merge branch 'main' into stringBuilder
Bujain Sep 9, 2021
7b794e3
Merge branch 'main' into stringBuilder
Bujain Sep 9, 2021
e1fd68b
Merge branch 'main' into stringBuilder
Bujain Sep 9, 2021
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
28 changes: 28 additions & 0 deletions test/cbmc/proofs/stringBuilder/Makefile
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
20 changes: 20 additions & 0 deletions test/cbmc/proofs/stringBuilder/README.md
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`).
1 change: 1 addition & 0 deletions test/cbmc/proofs/stringBuilder/cbmc-proof.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# This file marks this directory as containing a CBMC proof.
6 changes: 6 additions & 0 deletions test/cbmc/proofs/stringBuilder/cbmc-viewer.json
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__>"
}
62 changes: 62 additions & 0 deletions test/cbmc/proofs/stringBuilder/stringBuilder_harness.c
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 );
Copy link
Contributor

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.


/* 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 );
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition: i < numStrings - 1 is allocating only four strings, even if numStrings is 5. I think you want i < numStrings instead. This would match the previous malloc you did, where you allocated space for numStrings (in this ex. 5). This will also match the free statement that you have down below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 numStrings-1 pointers.The previous malloc is allocate memory to store the pointers, In strings array the last pointer should always be a NULL pointer and that is why I have assumed the last pointer to be NULL.


/* Strings array is always passed with a NULL string at the end. */
__CPROVER_assume( strings[ numStrings - 1 ] == NULL );

__CPROVER_file_local_ota_mqtt_c_stringBuilder( pBuffer, bufferSizeBytes, strings );

/* Free the allocated memory. */
free( pBuffer );

for( i = 0; i < numStrings; ++i )
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated it in 6d32385

{
free( strings[ i ] );
}

free( strings );
}