-
Notifications
You must be signed in to change notification settings - Fork 281
[SV-COMP'18 13/19] Memcpy assertions #2002
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
Closed
Closed
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
555451c
More precise assertion in memcpy about overlap of src/dst memory.
marek-trtik b228fe4
SV-COMP Hotfix: memcpy - turning assert to assume to prever 3 RED re…
marek-trtik ec25788
use __CPROVER_size_t and __CPROVER_ssize_t for __CPROVER_POINTER_OBJE…
kroening 8b65d37
use __CPROVER_size_t and __CPROVER_ssize_t for __CPROVER_POINTER_OBJE…
kroening File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,9 +14,11 @@ inline char *__builtin___strcpy_chk(char *dst, const char *src, __CPROVER_size_t | |
__CPROVER_is_zero_string(dst)=1; | ||
__CPROVER_zero_string_length(dst)=__CPROVER_zero_string_length(src); | ||
#else | ||
__CPROVER_precondition(__CPROVER_POINTER_OBJECT(dst)!= | ||
__CPROVER_POINTER_OBJECT(src), | ||
"strcpy src/dst overlap"); | ||
__CPROVER_precondition( | ||
__CPROVER_POINTER_OBJECT(dst) != __CPROVER_POINTER_OBJECT(src) || | ||
__CPROVER_POINTER_OFFSET(src) + s <= __CPROVER_POINTER_OFFSET(dst) || | ||
__CPROVER_POINTER_OFFSET(dst) + s <= __CPROVER_POINTER_OFFSET(src), | ||
"strcpy src/dst overlap"); | ||
__CPROVER_size_t i=0; | ||
char ch; | ||
do | ||
|
@@ -140,9 +142,16 @@ inline char *strcpy(char *dst, const char *src) | |
__CPROVER_is_zero_string(dst)=1; | ||
__CPROVER_zero_string_length(dst)=__CPROVER_zero_string_length(src); | ||
#else | ||
__CPROVER_precondition(__CPROVER_POINTER_OBJECT(dst)!= | ||
__CPROVER_POINTER_OBJECT(src), | ||
"strcpy src/dst overlap"); | ||
{ | ||
unsigned long n; | ||
for(n = 0U; *(src + n) != 0; ++n) | ||
; | ||
__CPROVER_precondition( | ||
__CPROVER_POINTER_OBJECT(dst) != __CPROVER_POINTER_OBJECT(src) || | ||
__CPROVER_POINTER_OFFSET(src) + n < __CPROVER_POINTER_OFFSET(dst) || | ||
__CPROVER_POINTER_OFFSET(dst) + n < __CPROVER_POINTER_OFFSET(src), | ||
"strcpy src/dst overlap"); | ||
} | ||
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. The precondition needs to be at the head of the function! |
||
__CPROVER_size_t i=0; | ||
char ch; | ||
do | ||
|
@@ -578,6 +587,8 @@ inline char *strdup(const char *str) | |
void *memcpy(void *dst, const void *src, size_t n) | ||
{ | ||
__CPROVER_HIDE: | ||
if(n==0U) | ||
return dst; | ||
#ifdef __CPROVER_STRING_ABSTRACTION | ||
__CPROVER_precondition(__CPROVER_buffer_size(src)>=n, | ||
"memcpy buffer overflow"); | ||
|
@@ -594,9 +605,16 @@ void *memcpy(void *dst, const void *src, size_t n) | |
n <= __CPROVER_zero_string_length(dst))) | ||
__CPROVER_is_zero_string(dst)=0; | ||
#else | ||
__CPROVER_precondition(__CPROVER_POINTER_OBJECT(dst)!= | ||
__CPROVER_POINTER_OBJECT(src), | ||
"memcpy src/dst overlap"); | ||
// TODO: This should be assert rather that assume. However, due to uninitialised | ||
// variables in SV-COMP benchmarks | ||
// linux-4.2-rc1.tar.xz-32_7a-drivers--media--usb--dvb-usb--dvb-usb-opera.ko-entry_point_true-unreach-call.cil.out.c | ||
// linux-4.2-rc1.tar.xz-43_2a-drivers--media--usb--s2255--s2255drv.ko-entry_point_true-unreach-call.cil.out.c | ||
// linux-4.2-rc1.tar.xz-43_2a-drivers--usb--serial--digi_acceleport.ko-entry_point_true-unreach-call.cil.out.c | ||
// the memcpy_guard function does not work. | ||
__CPROVER_assume( | ||
__CPROVER_POINTER_OBJECT(dst) != __CPROVER_POINTER_OBJECT(src) || | ||
__CPROVER_POINTER_OFFSET(src) + n <= __CPROVER_POINTER_OFFSET(dst) || | ||
__CPROVER_POINTER_OFFSET(dst) + n <= __CPROVER_POINTER_OFFSET(src)); | ||
(void)*(char *)dst; // check that the memory is accessible | ||
(void)*(const char *)src; // check that the memory is accessible | ||
|
||
|
@@ -618,6 +636,8 @@ void *memcpy(void *dst, const void *src, size_t n) | |
void *__builtin___memcpy_chk(void *dst, const void *src, __CPROVER_size_t n, __CPROVER_size_t size) | ||
{ | ||
__CPROVER_HIDE: | ||
if(size==0U) | ||
return dst; | ||
#ifdef __CPROVER_STRING_ABSTRACTION | ||
__CPROVER_precondition(__CPROVER_buffer_size(src)>=n, | ||
"memcpy buffer overflow"); | ||
|
@@ -636,9 +656,11 @@ void *__builtin___memcpy_chk(void *dst, const void *src, __CPROVER_size_t n, __C | |
n <= __CPROVER_zero_string_length(dst))) | ||
__CPROVER_is_zero_string(dst)=0; | ||
#else | ||
__CPROVER_precondition(__CPROVER_POINTER_OBJECT(dst)!= | ||
__CPROVER_POINTER_OBJECT(src), | ||
"memcpy src/dst overlap"); | ||
__CPROVER_precondition( | ||
__CPROVER_POINTER_OBJECT(dst) != __CPROVER_POINTER_OBJECT(src) || | ||
__CPROVER_POINTER_OFFSET(src) + n <= __CPROVER_POINTER_OFFSET(dst) || | ||
__CPROVER_POINTER_OFFSET(dst) + n <= __CPROVER_POINTER_OFFSET(src), | ||
"__builtin___memcpy_chk src/dst overlap"); | ||
(void)*(char *)dst; // check that the memory is accessible | ||
(void)*(const char *)src; // check that the memory is accessible | ||
(void)size; | ||
|
@@ -668,6 +690,8 @@ void *__builtin___memcpy_chk(void *dst, const void *src, __CPROVER_size_t n, __C | |
void *memset(void *s, int c, size_t n) | ||
{ | ||
__CPROVER_HIDE:; | ||
if(n==0U) | ||
return s; | ||
#ifdef __CPROVER_STRING_ABSTRACTION | ||
__CPROVER_precondition(__CPROVER_buffer_size(s)>=n, | ||
"memset buffer overflow"); | ||
|
@@ -705,6 +729,8 @@ void *memset(void *s, int c, size_t n) | |
void *__builtin_memset(void *s, int c, __CPROVER_size_t n) | ||
{ | ||
__CPROVER_HIDE:; | ||
if(n==0U) | ||
return s; | ||
#ifdef __CPROVER_STRING_ABSTRACTION | ||
__CPROVER_precondition(__CPROVER_buffer_size(s)>=n, | ||
"memset buffer overflow"); | ||
|
@@ -744,6 +770,8 @@ void *__builtin_memset(void *s, int c, __CPROVER_size_t n) | |
void *__builtin___memset_chk(void *s, int c, __CPROVER_size_t n, __CPROVER_size_t size) | ||
{ | ||
__CPROVER_HIDE:; | ||
if(n==0U) | ||
return s; | ||
#ifdef __CPROVER_STRING_ABSTRACTION | ||
__CPROVER_precondition(__CPROVER_buffer_size(s)>=n, | ||
"memset buffer overflow"); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Convention: I think these are usually
__CPROVER_lowercase_name
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.
The above seems to have been re-introduced after it got moved out into cprover_builtin_headers.h