static uptr wrapped_read(void *cookie, char *buf, uptr size) {
COMMON_INTERCEPTOR_UNPOISON_PARAM(3);
WrappedCookie *wrapped_cookie = (WrappedCookie *)cookie;
- return wrapped_cookie->real_io_funcs.read(wrapped_cookie->real_cookie, buf,
- size);
+ __sanitizer_cookie_io_read real_read = wrapped_cookie->real_io_funcs.read;
+ return real_read ? real_read(wrapped_cookie->real_cookie, buf, size) : 0;
}
static uptr wrapped_write(void *cookie, const char *buf, uptr size) {
COMMON_INTERCEPTOR_UNPOISON_PARAM(3);
WrappedCookie *wrapped_cookie = (WrappedCookie *)cookie;
- return wrapped_cookie->real_io_funcs.write(wrapped_cookie->real_cookie, buf,
- size);
+ __sanitizer_cookie_io_write real_write = wrapped_cookie->real_io_funcs.write;
+ return real_write ? real_write(wrapped_cookie->real_cookie, buf, size) : size;
}
static int wrapped_seek(void *cookie, u64 *offset, int whence) {
COMMON_INTERCEPTOR_UNPOISON_PARAM(3);
COMMON_INTERCEPTOR_INITIALIZE_RANGE(offset, sizeof(*offset));
WrappedCookie *wrapped_cookie = (WrappedCookie *)cookie;
- return wrapped_cookie->real_io_funcs.seek(wrapped_cookie->real_cookie, offset,
- whence);
+ __sanitizer_cookie_io_seek real_seek = wrapped_cookie->real_io_funcs.seek;
+ return real_seek ? real_seek(wrapped_cookie->real_cookie, offset, whence)
+ : -1;
}
static int wrapped_close(void *cookie) {
COMMON_INTERCEPTOR_UNPOISON_PARAM(1);
WrappedCookie *wrapped_cookie = (WrappedCookie *)cookie;
- int res = wrapped_cookie->real_io_funcs.close(wrapped_cookie->real_cookie);
+ __sanitizer_cookie_io_close real_close = wrapped_cookie->real_io_funcs.close;
+ int res = real_close ? real_close(wrapped_cookie->real_cookie) : 0;
InternalFree(wrapped_cookie);
return res;
}