-
Notifications
You must be signed in to change notification settings - Fork 274
Adds an over-approximation model for sysconf #7780
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
Merged
+70
−0
Merged
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include <errno.h> | ||
#include <unistd.h> | ||
|
||
main() | ||
{ | ||
long result; | ||
int name; | ||
|
||
errno = 0; | ||
// Testing sysconf as an over-apporximation. | ||
// We expect to cover all branches, thus, all assertions should fail. | ||
if((result = sysconf(name)) == -1) | ||
{ | ||
if(errno == 0) | ||
{ | ||
__CPROVER_assert(0, "ARG_MAX is not supported"); | ||
} | ||
else | ||
{ | ||
__CPROVER_assert(0, "sysconf() error"); | ||
} | ||
} | ||
else | ||
{ | ||
__CPROVER_assert(0, "ARG_MAX is supported"); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
CORE unix | ||
main.c | ||
|
||
^\[main.assertion.\d+\] line \d+ ARG\_MAX is not supported: FAILURE$ | ||
^\[main.assertion.\d+\] line \d+ sysconf\(\) error: FAILURE$ | ||
^\[main.assertion.\d+\] line \d+ ARG\_MAX is supported: FAILURE$ | ||
^\*\* 3 of 3 failed .*$ | ||
^VERIFICATION FAILED$ | ||
^EXIT=10$ | ||
^SIGNAL=0$ | ||
-- | ||
^WARNING: no body for function sysconf | ||
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 |
---|---|---|
|
@@ -319,3 +319,34 @@ ret_type _read(int fildes, void *buf, size_type nbyte) | |
__CPROVER_HIDE:; | ||
return read(fildes, buf, nbyte); | ||
} | ||
|
||
/* FUNCTION: sysconf */ | ||
|
||
#ifndef __CPROVER_ERRNO_H_INCLUDED | ||
# include <errno.h> | ||
# define __CPROVER_ERRNO_H_INCLUDED | ||
#endif | ||
|
||
long __VERIFIER_nondet_long(void); | ||
unsigned int __VERIFIER_nondet_unsigned_int(void); | ||
|
||
long sysconf(int name); | ||
|
||
// This overapproximation is based on the sysconf specification available at | ||
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/sysconf.html. | ||
long sysconf(int name) | ||
{ | ||
__CPROVER_HIDE:; | ||
(void)name; | ||
long retval = __VERIFIER_nondet_long(); | ||
|
||
// We should keep errno as non-determinist as possible, since this model | ||
// nver takes into account the name input. | ||
errno = __VERIFIER_nondet_unsigned_int(); | ||
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 is prone to arithmetic conversion failures for |
||
|
||
// Spec states "some returned values may be huge; they are not suitable | ||
// for allocating memory". There aren't also guarantees about return | ||
// values being strickly equal or greater to -1. | ||
// Thus, modelling it as non-deterministic. | ||
return retval; | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.