Index: lib/sanitizer_common/sanitizer_common_interceptors.inc =================================================================== --- lib/sanitizer_common/sanitizer_common_interceptors.inc +++ lib/sanitizer_common/sanitizer_common_interceptors.inc @@ -6851,6 +6851,52 @@ #define INIT_STRMODE #endif +#if SANITIZER_INTERCEPT_TTYENT +INTERCEPTOR(struct __sanitizer_ttyent *, getttyent, void) { + void *ctx; + COMMON_INTERCEPTOR_ENTER(ctx, getttyent); + struct __sanitizer_ttyent *ttyent = REAL(getttyent)(); + if (ttyent) + COMMON_INTERCEPTOR_WRITE_RANGE(ctx, ttyent, struct_ttyent_sz); + return ttyent; +} +INTERCEPTOR(struct __sanitizer_ttyent *, getttynam, char *name) { + void *ctx; + COMMON_INTERCEPTOR_ENTER(ctx, getttynam, name); + if (name) + COMMON_INTERCEPTOR_READ_RANGE(ctx, name, REAL(strlen)(name) + 1); + struct __sanitizer_ttyent *ttyent = REAL(getttynam)(name); + if (ttyent) + COMMON_INTERCEPTOR_WRITE_RANGE(ctx, ttyent, struct_ttyent_sz); + return ttyent; +} +INTERCEPTOR(int, setttyent) { + void *ctx; + COMMON_INTERCEPTOR_ENTER(ctx, setttyent); + return REAL(setttyent)(); +} +INTERCEPTOR(int, setttyentpath, char *path) { + void *ctx; + COMMON_INTERCEPTOR_ENTER(ctx, setttyentpath, path); + if (path) + COMMON_INTERCEPTOR_READ_RANGE(ctx, path, REAL(strlen)(path) + 1); + return REAL(setttyentpath)(path); +} +INTERCEPTOR(int, endttyent) { + void *ctx; + COMMON_INTERCEPTOR_ENTER(ctx, endttyent); + return REAL(endttyent)(); +} +#define INIT_TTYENT \ + COMMON_INTERCEPT_FUNCTION(getttyent); \ + COMMON_INTERCEPT_FUNCTION(getttynam); \ + COMMON_INTERCEPT_FUNCTION(setttyent); \ + COMMON_INTERCEPT_FUNCTION(setttyentpath); \ + COMMON_INTERCEPT_FUNCTION(endttyent) +#else +#define INIT_TTYENT +#endif + static void InitializeCommonInterceptors() { static u64 metadata_mem[sizeof(MetadataHashMap) / sizeof(u64) + 1]; interceptor_metadata_map = new((void *)&metadata_mem) MetadataHashMap(); @@ -7081,6 +7127,7 @@ INIT_DEVNAME_R; INIT_FGETLN; INIT_STRMODE; + INIT_TTYENT; #if SANITIZER_NETBSD COMMON_INTERCEPT_FUNCTION(__libc_mutex_lock); Index: lib/sanitizer_common/sanitizer_platform_interceptors.h =================================================================== --- lib/sanitizer_common/sanitizer_platform_interceptors.h +++ lib/sanitizer_common/sanitizer_platform_interceptors.h @@ -461,5 +461,6 @@ #define SANITIZER_INTERCEPT_DEVNAME_R SI_NETBSD #define SANITIZER_INTERCEPT_FGETLN SI_NETBSD #define SANITIZER_INTERCEPT_STRMODE SI_NETBSD +#define SANITIZER_INTERCEPT_TTYENT SI_NETBSD #endif // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H Index: test/sanitizer_common/TestCases/NetBSD/ttyent.cc =================================================================== --- /dev/null +++ test/sanitizer_common/TestCases/NetBSD/ttyent.cc @@ -0,0 +1,66 @@ +// RUN: %clangxx -O0 -g %s -o %t && %run %t + +#include +#include +#include + +#define STRING_OR_NULL(x) ((x) ? (x) : "null") + +void test1() { + struct ttyent *typ = getttyent(); + + printf("%s %s %s %d %s %s %s\n", STRING_OR_NULL(typ->ty_name), + STRING_OR_NULL(typ->ty_getty), STRING_OR_NULL(typ->ty_type), + typ->ty_status, STRING_OR_NULL(typ->ty_window), + STRING_OR_NULL(typ->ty_comment), STRING_OR_NULL(typ->ty_class)); + + endttyent(); +} + +void test2() { + struct ttyent *ttyp = getttynam("console"); + + printf("%s %s %s %d %s %s %s\n", STRING_OR_NULL(typ->ty_name), + STRING_OR_NULL(typ->ty_getty), STRING_OR_NULL(typ->ty_type), + typ->ty_status, STRING_OR_NULL(typ->ty_window), + STRING_OR_NULL(typ->ty_comment), STRING_OR_NULL(typ->ty_class)); + + endttyent(); +} + +void test3() { + if (!setttyent()) + exit(1); + + struct ttyent *typ = getttyent(); + + printf("%s %s %s %d %s %s %s\n", STRING_OR_NULL(typ->ty_name), + STRING_OR_NULL(typ->ty_getty), STRING_OR_NULL(typ->ty_type), + typ->ty_status, STRING_OR_NULL(typ->ty_window), + STRING_OR_NULL(typ->ty_comment), STRING_OR_NULL(typ->ty_class)); + + endttyent(); +} + +void test4() { + if (!setttyentpath(_PATH_TTYS)) + exit(1); + + struct ttyent *typ = getttyent(); + + printf("%s %s %s %d %s %s %s\n", STRING_OR_NULL(typ->ty_name), + STRING_OR_NULL(typ->ty_getty), STRING_OR_NULL(typ->ty_type), + typ->ty_status, STRING_OR_NULL(typ->ty_window), + STRING_OR_NULL(typ->ty_comment), STRING_OR_NULL(typ->ty_class)); + + endttyent(); +} + +int main(void) { + test1(); + test2(); + test3(); + test4(); + + return 0; +}