Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to LAVA-M dataset #107

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler/Runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ bool isInterceptedFunction(const Function &f) {
"malloc", "calloc", "mmap", "mmap64", "open", "read", "lseek",
"lseek64", "fopen", "fopen64", "fread", "fseek", "fseeko", "rewind",
"fseeko64", "getc", "ungetc", "memcpy", "memset", "strncpy", "strchr",
"memcmp", "memmove", "ntohl", "fgets", "fgetc", "getchar"};
"memcmp", "memmove", "ntohl", "fgets", "fgetc", "getchar", "freopen",
"fread_unlocked", "getc_unlocked", "getline", "getutxent" };

return (kInterceptedFunctions.count(f.getName()) > 0);
}
106 changes: 106 additions & 0 deletions runtime/LibcWrappers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include "Config.h"
#include "Shadow.h"
#include <Runtime.h>
#include <utmpx.h>
#include <stdio.h>

#define SYM(x) x##_symbolized

Expand Down Expand Up @@ -189,6 +191,25 @@ uint32_t SYM(lseek)(int fd, uint32_t offset, int whence) {
return (uint32_t)-1;
}

FILE *SYM(freopen)(const char *filename, const char *mode, FILE *stream)
{
auto *result = freopen(filename, mode, stream);
_sym_set_return_expression(nullptr);
if (result != nullptr && !g_config.fullyConcrete &&
!g_config.inputFile.empty() &&
strstr(filename, g_config.inputFile.c_str()) != nullptr)
{
if (inputFileDescriptor != -1)
std::cerr << "Warning: input file opened multiple times; this is not yet "
"supported"
<< std::endl;
inputFileDescriptor = fileno(result);
inputOffset = 0;
}

return result;
}

FILE *SYM(fopen)(const char *pathname, const char *mode) {
auto *result = fopen(pathname, mode);
_sym_set_return_expression(nullptr);
Expand Down Expand Up @@ -246,6 +267,32 @@ size_t SYM(fread)(void *ptr, size_t size, size_t nmemb, FILE *stream) {
return result;
}

size_t SYM(fread_unlocked)(void *ptr, size_t size, size_t nmemb, FILE *stream)
{
tryAlternative(ptr, _sym_get_parameter_expression(0), SYM(fread_unlocked));
tryAlternative(size, _sym_get_parameter_expression(1), SYM(fread_unlocked));
tryAlternative(nmemb, _sym_get_parameter_expression(2), SYM(fread_unlocked));

auto result = fread(ptr, size, nmemb, stream);
Yhcrown marked this conversation as resolved.
Show resolved Hide resolved
_sym_set_return_expression(nullptr);

if (fileno(stream) == inputFileDescriptor)
{
// Reading symbolic input.
ReadWriteShadow shadow(ptr, result * size);
std::generate(shadow.begin(), shadow.end(),
[]()
{ return _sym_get_input_byte(inputOffset++); });
}
else if (!isConcrete(ptr, result * size))
{
ReadWriteShadow shadow(ptr, result * size);
std::fill(shadow.begin(), shadow.end(), nullptr);
}

return result;
}

char *SYM(fgets)(char *str, int n, FILE *stream) {
tryAlternative(str, _sym_get_parameter_expression(0), SYM(fgets));
tryAlternative(n, _sym_get_parameter_expression(1), SYM(fgets));
Expand Down Expand Up @@ -329,6 +376,47 @@ int SYM(fseeko64)(FILE *stream, uint64_t offset, int whence) {
return result;
}

struct utmpx *SYM(getutxent)()
Yhcrown marked this conversation as resolved.
Show resolved Hide resolved
{
auto *result = getutxent();
_sym_set_return_expression(nullptr);

// Reading symbolic input.
ReadWriteShadow shadow(result, sizeof (struct utmpx));
std::generate(shadow.begin(), shadow.end(),
[]()
{ return _sym_get_input_byte(inputOffset++); });

return result;
}

ssize_t SYM(getline)(char **ptr, size_t *n, FILE *stream)
{

tryAlternative(ptr, _sym_get_parameter_expression(0), SYM(getline));
tryAlternative(n, _sym_get_parameter_expression(1), SYM(getline));

auto result = getdelim(ptr, n, '\n', stream);

_sym_set_return_expression(nullptr);

if (fileno(stream) == inputFileDescriptor)
{
// Reading symbolic input.
ReadWriteShadow shadow(*ptr, result * (*n));
std::generate(shadow.begin(), shadow.end(),
[]()
{ return _sym_get_input_byte(inputOffset++); });
}
else if (!isConcrete(*ptr, result * (*n)))
{
ReadWriteShadow shadow(*ptr, result * (*n));
std::fill(shadow.begin(), shadow.end(), nullptr);
}

return result;
}

int SYM(getc)(FILE *stream) {
auto result = getc(stream);
if (result == EOF) {
Expand All @@ -345,6 +433,24 @@ int SYM(getc)(FILE *stream) {
return result;
}

int SYM(getc_unlocked)(FILE *stream)
{
auto result = getc(stream);
Yhcrown marked this conversation as resolved.
Show resolved Hide resolved
if (result == EOF)
{
_sym_set_return_expression(nullptr);
return result;
}

if (fileno(stream) == inputFileDescriptor)
_sym_set_return_expression(_sym_build_zext(
_sym_get_input_byte(inputOffset++), sizeof(int) * 8 - 8));
else
_sym_set_return_expression(nullptr);

return result;
}

int SYM(fgetc)(FILE *stream) {
auto result = fgetc(stream);
if (result == EOF) {
Expand Down