Skip to content

Commit de3e888

Browse files
tiedaoxiaotubiesebastianpoeplau
authored andcommitted
Add input symbolization in mmap()
The original wrapper didn't do symbolization work, which will lose constraints.
1 parent ef61053 commit de3e888

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

runtime/LibcWrappers.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,31 @@ void *SYM(calloc)(size_t nmemb, size_t size) {
128128
void *SYM(mmap64)(void *addr, size_t len, int prot, int flags, int fildes,
129129
uint64_t off) {
130130
auto *result = mmap64(addr, len, prot, flags, fildes, off);
131+
_sym_set_return_expression(nullptr);
132+
133+
if (result == MAP_FAILED) // mmap failed
134+
return result;
135+
136+
if (fildes == inputFileDescriptor) {
137+
/* we update the inputOffset only when mmap() is reading from input file
138+
* HACK! update inputOffset with off parameter sometimes will be dangerous
139+
* We don't know whether there is read() before/after mmap,
140+
* if there is, we have to fix this tricky method :P
141+
*/
142+
inputOffset = off + len;
143+
// Reading symbolic input.
144+
ReadWriteShadow shadow(result, len);
145+
uint8_t *resultBytes = (uint8_t *)result;
146+
std::generate(shadow.begin(), shadow.end(), [resultBytes, i = 0]() mutable {
147+
return _sym_get_input_byte(inputOffset, resultBytes[i++]);
148+
});
149+
} else if (!isConcrete(result, len)) {
150+
ReadWriteShadow shadow(result, len);
151+
std::fill(shadow.begin(), shadow.end(), nullptr);
152+
}
131153

132154
tryAlternative(len, _sym_get_parameter_expression(1), SYM(mmap64));
133155

134-
_sym_set_return_expression(nullptr);
135156
return result;
136157
}
137158

0 commit comments

Comments
 (0)