Skip to content

Commit

Permalink
add strcpy() wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
tiedaoxiaotubie authored and sebastianpoeplau committed Feb 22, 2023
1 parent bab79d2 commit 496dac1
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
19 changes: 19 additions & 0 deletions runtime/LibcWrappers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -858,4 +858,23 @@ long int SYM(atol)(const char *s) {

return result;
}

char *SYM(strcpy)(char *dest, const char *src) {
tryAlternative(dest, _sym_get_parameter_expression(0), SYM(strcpy));
tryAlternative(src, _sym_get_parameter_expression(1), SYM(strcpy));

auto *result = strcpy(dest, src);
_sym_set_return_expression(nullptr);

size_t cpyLen = strlen(src);
if (isConcrete(src, cpyLen) && isConcrete(dest, cpyLen))
return result;

auto srcShadow = ReadOnlyShadow(src, cpyLen);
auto destShadow = ReadWriteShadow(dest, cpyLen);

std::copy(srcShadow.begin(), srcShadow.end(), destShadow.begin());

return result;
}
}
31 changes: 31 additions & 0 deletions runtime/test_wrappers/test_strcpy.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
int main(int argc, char *argv[]) {

char buf[1024];
ssize_t i;
if ((i = read(0, buf, sizeof(buf) - 1)) < 24) return 0;
buf[i] = 0;
if (buf[0] != 'A') return 0;
if (buf[1] != 'B') return 0;
if (buf[2] != 'C') return 0;
if (buf[3] != 'D') return 0;
if (memcmp(buf + 4, "1234", 4) || memcmp(buf + 8, "EFGH", 4)) return 0;

char buf_2[4];
strcpy(buf_2, buf+12);
if (memcmp(buf_2, "NICE", 4)){
printf("NOT HIT!\n");
return 0;
} else {
printf("HIT!\n");

}

return 0;

}

0 comments on commit 496dac1

Please sign in to comment.