Skip to content

Commit 7cf30e3

Browse files
committed
Adds an over-approximation model for sysconf
Signed-off-by: Felipe R. Monteiro <[email protected]>
1 parent bd87ba9 commit 7cf30e3

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <unistd.h>
2+
#include <errno.h>
3+
4+
int main() {
5+
errno = 0;
6+
long result = sysconf(_SC_ARG_MAX);
7+
__CPROVER_assert(!(errno == EINVAL) || (result == -1), "Non-deterministically set errno to EINVAL");
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.c
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^\[main.assertion.\d+\] .* Non-deterministically set errno to EINVAL: SUCCESS$
7+
^\*\* 0 of 1 failed
8+
--
9+
^WARNING: no body for function sysconf

src/ansi-c/library/unistd.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,3 +319,27 @@ ret_type _read(int fildes, void *buf, size_type nbyte)
319319
__CPROVER_HIDE:;
320320
return read(fildes, buf, nbyte);
321321
}
322+
323+
/* FUNCTION: sysconf */
324+
325+
#ifndef __CPROVER_ERRNO_H_INCLUDED
326+
#include <errno.h>
327+
#define __CPROVER_ERRNO_H_INCLUDED
328+
#endif
329+
330+
long __VERIFIER_nondet_long(void);
331+
__CPROVER_bool __VERIFIER_nondet___CPROVER_bool(void);
332+
333+
long sysconf(int name);
334+
335+
// This overapproximation is based on this specification
336+
// https://man7.org/linux/man-pages/man3/sysconf.3.html.
337+
long sysconf(int name)
338+
{
339+
__CPROVER_HIDE:;
340+
(void)name;
341+
long retval = __VERIFIER_nondet_long();
342+
if(retval == -1 && __VERIFIER_nondet___CPROVER_bool())
343+
errno = EINVAL;
344+
return retval;
345+
}

0 commit comments

Comments
 (0)