Index: compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc =================================================================== --- compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc +++ compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc @@ -7543,6 +7543,8 @@ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, ttyent, struct_ttyent_sz); return ttyent; } + +#if SANITIZER_NETBSD INTERCEPTOR(int, setttyentpath, char *path) { void *ctx; COMMON_INTERCEPTOR_ENTER(ctx, setttyentpath, path); @@ -7555,6 +7557,11 @@ COMMON_INTERCEPT_FUNCTION(getttynam); \ COMMON_INTERCEPT_FUNCTION(setttyentpath) #else +#define INIT_TTYENT \ + COMMON_INTERCEPT_FUNCTION(getttyent); \ + COMMON_INTERCEPT_FUNCTION(getttynam); +#endif +#else #define INIT_TTYENT #endif Index: compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h =================================================================== --- compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h +++ compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h @@ -521,7 +521,7 @@ #define SANITIZER_INTERCEPT_DEVNAME_R (SI_NETBSD || SI_FREEBSD) #define SANITIZER_INTERCEPT_FGETLN (SI_NETBSD || SI_FREEBSD) #define SANITIZER_INTERCEPT_STRMODE (SI_NETBSD || SI_FREEBSD) -#define SANITIZER_INTERCEPT_TTYENT SI_NETBSD +#define SANITIZER_INTERCEPT_TTYENT (SI_NETBSD || SI_FREEBSD) #define SANITIZER_INTERCEPT_PROTOENT (SI_LINUX || SI_NETBSD || SI_FREEBSD) #define SANITIZER_INTERCEPT_PROTOENT_R SI_GLIBC #define SANITIZER_INTERCEPT_NETENT (SI_LINUX || SI_NETBSD || SI_FREEBSD) Index: compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.h =================================================================== --- compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.h +++ compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.h @@ -383,6 +383,8 @@ extern unsigned path_max; +extern int struct_ttyent_sz; + struct __sanitizer_wordexp_t { uptr we_wordc; char **we_wordv; @@ -412,6 +414,16 @@ } ifc_ifcu; }; +struct __sanitizer__ttyent { + char *ty_name; + char *ty_getty; + char *ty_type; + int ty_status; + char *ty_window; + char *ty_comment; + char *ty_group; +}; + # define IOC_NRBITS 8 # define IOC_TYPEBITS 8 # if defined(__powerpc__) || defined(__powerpc64__) || defined(__mips__) Index: compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.cpp =================================================================== --- compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.cpp +++ compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.cpp @@ -15,81 +15,82 @@ #if SANITIZER_FREEBSD -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-W#warnings" -#include -#pragma clang diagnostic pop -#include -#include -#include -#include -#include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-W#warnings" +# include +# pragma clang diagnostic pop +# include +# include +# include +# include +# include // -#include -#include -#include -#include -#include -#include -#include -#include +# include +# include +# include +# include +# include +# include +# include +# include // -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define _KERNEL // to declare 'shminfo' structure -#include -#undef _KERNEL - -#undef IOC_DIRMASK +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include + +# define _KERNEL // to declare 'shminfo' structure +# include +# undef _KERNEL + +# undef IOC_DIRMASK // Include these after system headers to avoid name clashes and ambiguities. -#include "sanitizer_internal_defs.h" -#include "sanitizer_libc.h" -#include "sanitizer_platform_limits_freebsd.h" +# include "sanitizer_internal_defs.h" +# include "sanitizer_libc.h" +# include "sanitizer_platform_limits_freebsd.h" namespace __sanitizer { void *__sanitizer_get_link_map_by_dlopen_handle(void *handle) { @@ -174,19 +175,21 @@ unsigned path_max = PATH_MAX; +int struct_ttyent_sz = sizeof(struct ttyent); + // ioctl arguments unsigned struct_ifreq_sz = sizeof(struct ifreq); unsigned struct_termios_sz = sizeof(struct termios); unsigned struct_winsize_sz = sizeof(struct winsize); -#if SOUND_VERSION >= 0x040000 +# if SOUND_VERSION >= 0x040000 unsigned struct_copr_buffer_sz = 0; unsigned struct_copr_debug_buf_sz = 0; unsigned struct_copr_msg_sz = 0; -#else +# else unsigned struct_copr_buffer_sz = sizeof(struct copr_buffer); unsigned struct_copr_debug_buf_sz = sizeof(struct copr_debug_buf); unsigned struct_copr_msg_sz = sizeof(struct copr_msg); -#endif +# endif unsigned struct_midi_info_sz = sizeof(struct midi_info); unsigned struct_mtget_sz = sizeof(struct mtget); unsigned struct_mtop_sz = sizeof(struct mtop); @@ -488,7 +491,7 @@ CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_name); CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_addr); CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_netmask); -#undef ifa_dstaddr +# undef ifa_dstaddr CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_dstaddr); CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_data); @@ -514,7 +517,7 @@ CHECK_SIZE_AND_OFFSET(group, gr_gid); CHECK_SIZE_AND_OFFSET(group, gr_mem); -#if HAVE_RPC_XDR_H +# if HAVE_RPC_XDR_H CHECK_TYPE_SIZE(XDR); CHECK_SIZE_AND_OFFSET(XDR, x_op); CHECK_SIZE_AND_OFFSET(XDR, x_ops); @@ -525,7 +528,7 @@ COMPILER_CHECK(__sanitizer_XDR_ENCODE == XDR_ENCODE); COMPILER_CHECK(__sanitizer_XDR_DECODE == XDR_DECODE); COMPILER_CHECK(__sanitizer_XDR_FREE == XDR_FREE); -#endif +# endif CHECK_TYPE_SIZE(sem_t); Index: compiler-rt/test/sanitizer_common/TestCases/FreeBSD/ttyent.cpp =================================================================== --- /dev/null +++ compiler-rt/test/sanitizer_common/TestCases/FreeBSD/ttyent.cpp @@ -0,0 +1,40 @@ +// RUN: %clangxx -O0 -g %s -o %t + +#include +#include +#include + +void test1() { + struct ttyent *typ = getttyent(); + assert(typ && typ->ty_name != nullptr); + assert(typ->ty_type != nullptr); + assert(typ->ty_group != nullptr); + endttyent(); +} + +void test2() { + struct ttyent *typ = getttynam("console"); + assert(typ && typ->ty_name != nullptr); + assert(typ->ty_type != nullptr); + assert(typ->ty_group != nullptr); + endttyent(); +} + +void test3() { + if (!setttyent()) + exit(1); + + struct ttyent *typ = getttyent(); + assert(typ && typ->ty_name != nullptr); + assert(typ->ty_type != nullptr); + assert(typ->ty_group != nullptr); + endttyent(); +} + +int main(void) { + test1(); + test2(); + test3(); + + return 0; +}