Summary: The symbolic execution was not stopping in case an unitialized dangling pointer was passed to a function and then dereferenced inside the callee. What would happen is that a wrong footprint would be added to the unititialized pointer at the end of the function call in the caller proposition. This checks that if we do: frame * new_footprint checks that we do not add heap predicates to the frame into uninitialized local variables. If we can identify the variable then we raise a danglind pointer dereference. If instead we cannot give a good explanation we give an internal error. The latter case should be temporary. We should find a general way to raise dangling pointer deref instead of the internal error. I also fixed the model of getc that was the way I found the problem.master
parent
795742a3a2
commit
7002d0d24c
@ -0,0 +1,12 @@
|
|||||||
|
|
||||||
|
SOURCES = $(shell ls *.c)
|
||||||
|
OBJECTS = $(SOURCES:.c=.o)
|
||||||
|
|
||||||
|
all: clean $(OBJECTS)
|
||||||
|
echo $(OBJECTS)
|
||||||
|
|
||||||
|
.c.o:
|
||||||
|
${CC} -c $<
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf $(OBJECTS)
|
@ -0,0 +1,43 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int *set42(int* x) {
|
||||||
|
|
||||||
|
*x=42;
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nodpd () {
|
||||||
|
|
||||||
|
int w,z;
|
||||||
|
|
||||||
|
z=set42(&w);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void nodpd1 () {
|
||||||
|
|
||||||
|
int *y = malloc(sizeof(int));
|
||||||
|
int *z;
|
||||||
|
z=set42(y);
|
||||||
|
free(y);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void dpd () {
|
||||||
|
|
||||||
|
int *y;
|
||||||
|
int *z;
|
||||||
|
z=set42(y);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void intraprocdpd () {
|
||||||
|
|
||||||
|
int *y;
|
||||||
|
int *z;
|
||||||
|
*y=42;
|
||||||
|
z=y;
|
||||||
|
}
|
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2013- Facebook.
|
||||||
|
* All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package endtoend.c;
|
||||||
|
|
||||||
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
import static utils.matchers.ResultContainsExactly.containsExactly;
|
||||||
|
import static utils.matchers.ResultContainsLineNumbers.containsLines;
|
||||||
|
import static utils.matchers.ResultContainsErrorInMethod.contains;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import utils.InferException;
|
||||||
|
import utils.InferResults;
|
||||||
|
import utils.InferRunner;
|
||||||
|
|
||||||
|
public class DanglingDereferenceTest {
|
||||||
|
|
||||||
|
public static final String SOURCE_FILE =
|
||||||
|
"dangling_deref/dpd.c";
|
||||||
|
|
||||||
|
public static final String DANGLING_POINTER_DEREFERENCE = "DANGLING_POINTER_DEREFERENCE";
|
||||||
|
|
||||||
|
private static InferResults inferResults;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void runInfer() throws InterruptedException, IOException {
|
||||||
|
inferResults = InferResults.loadCInferResults(
|
||||||
|
DanglingDereferenceTest.class,
|
||||||
|
SOURCE_FILE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void DanglingDereferenceTest1() throws InterruptedException, IOException, InferException {
|
||||||
|
assertThat(
|
||||||
|
"Results should contain dangling pointer dereference error",
|
||||||
|
inferResults,
|
||||||
|
contains(
|
||||||
|
DANGLING_POINTER_DEREFERENCE,
|
||||||
|
SOURCE_FILE,
|
||||||
|
"dpd"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void DanglingDereferenceTest2() throws InterruptedException, IOException, InferException {
|
||||||
|
assertThat(
|
||||||
|
"Results should contain dangling pointer dereference error",
|
||||||
|
inferResults,
|
||||||
|
contains(
|
||||||
|
DANGLING_POINTER_DEREFERENCE,
|
||||||
|
SOURCE_FILE,
|
||||||
|
"intraprocdpd"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue