Skip to content

Commit

Permalink
Adds an over-approximation model for sysconf
Browse files Browse the repository at this point in the history
Signed-off-by: Felipe R. Monteiro <felisous@amazon.com>
  • Loading branch information
feliperodri committed Jun 22, 2023
1 parent bd87ba9 commit 1eac41d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
11 changes: 11 additions & 0 deletions regression/cbmc-library/sysconf-01/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <errno.h>
#include <unistd.h>

int main()
{
errno = 0;
long result = sysconf(_SC_ARG_MAX);
__CPROVER_assert(
!(errno == EINVAL) || (result == -1),
"Non-deterministically set errno to EINVAL");
}
9 changes: 9 additions & 0 deletions regression/cbmc-library/sysconf-01/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE
main.c

^EXIT=0$
^SIGNAL=0$
^\[main.assertion.\d+\] .* Non-deterministically set errno to EINVAL: SUCCESS$
^\*\* 0 of 1 failed
--
^WARNING: no body for function sysconf
24 changes: 24 additions & 0 deletions src/ansi-c/library/unistd.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,3 +319,27 @@ 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);
__CPROVER_bool __VERIFIER_nondet___CPROVER_bool(void);

long sysconf(int name);

// This overapproximation is based on this specification
// https://man7.org/linux/man-pages/man3/sysconf.3.html.
long sysconf(int name)
{
__CPROVER_HIDE:;
(void)name;
long retval = __VERIFIER_nondet_long();
if(retval == -1 && __VERIFIER_nondet___CPROVER_bool())
errno = EINVAL;
return retval;
}

0 comments on commit 1eac41d

Please sign in to comment.