forked from OSchip/llvm-project
[Sanitizer] Fix fopencookie() interceptor to work with null hook functions.
llvm-svn: 242193
This commit is contained in:
parent
2e82883620
commit
41bcf0bca2
|
@ -4965,29 +4965,31 @@ struct WrappedCookie {
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -56,4 +56,10 @@ int main() {
|
|||
fread(buf, 50, 1, f);
|
||||
fwrite(buf, 50, 1, f);
|
||||
fclose(f);
|
||||
|
||||
f = fopencookie(cookie, "rw", {nullptr, nullptr, nullptr, nullptr});
|
||||
fseek(f, 100, SEEK_SET);
|
||||
fread(buf, 50, 1, f);
|
||||
fwrite(buf, 50, 1, f);
|
||||
fclose(f);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue