Skip to content

Commit 496dac1

Browse files
tiedaoxiaotubiesebastianpoeplau
authored andcommitted
add strcpy() wrapper
1 parent bab79d2 commit 496dac1

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

runtime/LibcWrappers.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,4 +858,23 @@ long int SYM(atol)(const char *s) {
858858

859859
return result;
860860
}
861+
862+
char *SYM(strcpy)(char *dest, const char *src) {
863+
tryAlternative(dest, _sym_get_parameter_expression(0), SYM(strcpy));
864+
tryAlternative(src, _sym_get_parameter_expression(1), SYM(strcpy));
865+
866+
auto *result = strcpy(dest, src);
867+
_sym_set_return_expression(nullptr);
868+
869+
size_t cpyLen = strlen(src);
870+
if (isConcrete(src, cpyLen) && isConcrete(dest, cpyLen))
871+
return result;
872+
873+
auto srcShadow = ReadOnlyShadow(src, cpyLen);
874+
auto destShadow = ReadWriteShadow(dest, cpyLen);
875+
876+
std::copy(srcShadow.begin(), srcShadow.end(), destShadow.begin());
877+
878+
return result;
879+
}
861880
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <stdio.h>
2+
#include <string.h>
3+
#include <stdarg.h>
4+
#include <stdlib.h>
5+
#include <stdint.h>
6+
#include <unistd.h>
7+
int main(int argc, char *argv[]) {
8+
9+
char buf[1024];
10+
ssize_t i;
11+
if ((i = read(0, buf, sizeof(buf) - 1)) < 24) return 0;
12+
buf[i] = 0;
13+
if (buf[0] != 'A') return 0;
14+
if (buf[1] != 'B') return 0;
15+
if (buf[2] != 'C') return 0;
16+
if (buf[3] != 'D') return 0;
17+
if (memcmp(buf + 4, "1234", 4) || memcmp(buf + 8, "EFGH", 4)) return 0;
18+
19+
char buf_2[4];
20+
strcpy(buf_2, buf+12);
21+
if (memcmp(buf_2, "NICE", 4)){
22+
printf("NOT HIT!\n");
23+
return 0;
24+
} else {
25+
printf("HIT!\n");
26+
27+
}
28+
29+
return 0;
30+
31+
}

0 commit comments

Comments
 (0)