Skip to content

goto-cc incompatible with cbmc's --malloc-may-fail and --malloc-fail-null #5492

Closed
@SaswatPadhi

Description

@SaswatPadhi

CBMC version: 5.13.0
Operating system: Linux 64-bit

Minimal example:

#include <assert.h>
#include <stdlib.h>

int main (void) {
  int*p = malloc(sizeof(*p));
  assert(p);
  return 0;
}

cbmc --malloc-may-fail --malloc-fail-null test.c correctly detects a bug in this .c file.
When we run goto-cc test.c -o test.goto, and then run cbmc --malloc-may-fail --malloc-fail-null test.goto, cbmc incorrectly reports successful verification.

Currently, goto-cc does not accept these two malloc flags, so we cannot add them to the goto-cc invocation.

What behaviour did you expect:

$ cbmc --malloc-may-fail --malloc-fail-null test.c
CBMC version 5.13.0 (cbmc-5.13.1) 64-bit x86_64 linux
Parsing test.c
Converting
Type-checking test
Generating GOTO Program
Adding CPROVER library (x86_64)
Removal of function pointers and virtual functions
Generic Property Instrumentation
Running with 8 object bits, 56 offset bits (default)
Starting Bounded Model Checking
size of program expression: 89 steps
simple slicing removed 5 assignments
Generated 1 VCC(s), 1 remaining after simplification
Passing problem to propositional reduction
converting SSA
Running propositional reduction
Post-processing
Solving with MiniSAT 2.2.1 with simplifier
324 variables, 48 clauses
SAT checker: instance is SATISFIABLE
Runtime decision procedure: 0.0016344s

** Results:
<builtin-library-malloc> function malloc
[malloc.assertion.1] line 26 max allocation size exceeded: SUCCESS
[malloc.assertion.2] line 31 max allocation may fail: SUCCESS

test.c function main
[main.assertion.1] line 6 assertion p: FAILURE

** 1 of 3 failed (2 iterations)
VERIFICATION FAILED

What happened instead:

$ goto-cc test.c -o test.goto; cbmc --malloc-may-fail --malloc-fail-null test.goto
CBMC version 5.13.0 (cbmc-5.13.1) 64-bit x86_64 linux
Reading GOTO program from file
Reading: test.goto
Generating GOTO Program
Adding CPROVER library (x86_64)
file <built-in-additions> line 21: warning: conflicting initializers for variable "__CPROVER_malloc_failure_mode"
using old value in module test file <built-in-additions> line 21
0
ignoring new value in module <built-in-library> file <built-in-additions> line 21
1
file <built-in-additions> line 25: warning: conflicting initializers for variable "__CPROVER_malloc_may_fail"
using old value in module test file <built-in-additions> line 25
FALSE
ignoring new value in module <built-in-library> file <built-in-additions> line 25
TRUE
Removal of function pointers and virtual functions
Generic Property Instrumentation
Running with 8 object bits, 56 offset bits (default)
Starting Bounded Model Checking
size of program expression: 76 steps
simple slicing removed 0 assignments
Generated 1 VCC(s), 0 remaining after simplification

** Results:
<builtin-library-malloc> function malloc
[malloc.assertion.1] line 26 max allocation size exceeded: SUCCESS
[malloc.assertion.2] line 31 max allocation may fail: SUCCESS

test.c function main
[main.assertion.1] line 6 assertion p: SUCCESS

** 0 of 3 failed (1 iterations)
VERIFICATION SUCCESSFUL

Metadata

Metadata

Assignees

No one assigned

    Labels

    awsBugs or features of importance to AWS CBMC usersaws-high

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions