Skip to content

Commit 58d2ab6

Browse files
authored
Merge pull request #4623 from mauguignard/fix-4621
bugfix: pointer check failure in fgets
2 parents 81c3e02 + 6886712 commit 58d2ab6

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

regression/cbmc-library/fgets-01/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ main.c
55
^SIGNAL=0$
66
^VERIFICATION FAILED$
77
\[main.assertion.3\] line 16 assertion p\[1\] == 'b': FAILURE
8-
\*\* 2 of \d+ failed
8+
\*\* 1 of \d+ failed
99
--
1010
^warning: ignoring

src/ansi-c/library/stdio.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,8 @@ char *fgets(char *str, int size, FILE *stream)
259259
if(size>0)
260260
{
261261
int str_length=__VERIFIER_nondet_int();
262-
__CPROVER_assume(str_length>=0 && str_length<size);
263-
// check that the memory is accessible
264-
(void)*(char *)str;
265-
(void)*(((const char *)str) + str_length - 1);
262+
__CPROVER_assume(str_length >= 0 && str_length < size);
263+
__CPROVER_precondition(__CPROVER_w_ok(str, size), "fgets buffer writable");
266264
char contents_nondet[str_length];
267265
__CPROVER_array_replace(str, contents_nondet);
268266
if(!error)

0 commit comments

Comments
 (0)