我现在正在学习KLEE,我写了一个简单的代码:
#include "klee/klee.h"
#include <stdio.h>
#include <stdlib.h>
int test(int *p)
{
int *q = (int *) malloc(sizeof(int));
if ((*p) == (*q)) {
printf("reading uninitialized heap memory");
}
return 0;
}
int main()
{
int *p = (int *) malloc(sizeof(int));
test(p);
return 0;
}首先,我生成LLVM bitcode,然后执行KLEE to the bitcode。以下是所有输出:
KLEE: output directory is "/Users/yjy/WorkSpace/Test/klee-out-13"
Using STP solver backend
KLEE: WARNING: undefined reference to function: printf
KLEE: WARNING ONCE: calling external: printf(140351601907424)
reading uninitialized heap memory
KLEE: done: total instructions = 61
KLEE: done: completed paths = 4
KLEE: done: generated tests = 4我想KLEE应该给我一个Q指针没有初始化的错误,但是它没有,为什么KLEE不给我一个错误或者警告呢?KLEE不能检测到这个错误吗?提前感谢!
发布于 2017-04-21 15:26:19
TLTR:KLEE尚未实现此功能。Clang可以直接检查这一点。
KLEE目前支持add/sub/mul/div溢出检查。要使用此功能,您必须使用clang -fsanitize=signed-integer-overflow或clang -fsanitize=unsigned-integer-overflow编译源代码。
这个想法是,当你使用clang杀菌器时,一个函数调用被插入到字节码(例如__ubsan_handle_add_overflow)中。然后,一旦遇到函数调用,KLEE将处理溢出检查。
Clang support MemorySanitizer,AddressSanitizer UndefinedBehaviorSanitizer。它们在项目/编译器-rt/lib目录中定义。MemorySanitizer就是你要找的那个,它是一个未初始化读取的检测器。
您可以删除KLEE函数调用,并直接使用clang进行检查。
➜ ~ clang -g -fsanitize=memory st.cpp
➜ ~ ./a.out
==16031==WARNING: MemorySanitizer: use-of-uninitialized-value
#0 0x490954 (/home/hailin/a.out+0x490954)
#1 0x7f21b72f382f (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
#2 0x41a1d8 (/home/hailin/a.out+0x41a1d8)
SUMMARY: MemorySanitizer: use-of-uninitialized-value (/home/hailin/a.out+0x490954)
Exitinghttps://stackoverflow.com/questions/41697254
复制相似问题