Index: lib/sanitizer_common/sanitizer_common_interceptors.inc =================================================================== --- lib/sanitizer_common/sanitizer_common_interceptors.inc +++ lib/sanitizer_common/sanitizer_common_interceptors.inc @@ -6807,6 +6807,22 @@ #define INIT_DEVNAME_R #endif +#if SANITIZER_INTERCEPT_FGETLN +INTERCEPTOR(char *, fgetln, __sanitizer_FILE *stream, SIZE_T *len) { + void *ctx; + COMMON_INTERCEPTOR_ENTER(ctx, fgetln, stream, len); + char *str = REAL(fgetln)(stream, len); + if (str && len) { + COMMON_INTERCEPTOR_WRITE_RANGE(ctx, len, sizeof(*len)); + COMMON_INTERCEPTOR_WRITE_RANGE(ctx, str, *len); + } + return str; +} +#define INIT_FGETLN COMMON_INTERCEPT_FUNCTION(fgetln) +#else +#define INIT_FGETLN +#endif + static void InitializeCommonInterceptors() { static u64 metadata_mem[sizeof(MetadataHashMap) / sizeof(u64) + 1]; interceptor_metadata_map = new((void *)&metadata_mem) MetadataHashMap(); @@ -7035,6 +7051,7 @@ INIT_STRLCPY; INIT_DEVNAME; INIT_DEVNAME_R; + INIT_FGETLN; #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 @@ -459,5 +459,6 @@ #define SANITIZER_INTERCEPT_DEVNAME SI_NETBSD #define SANITIZER_INTERCEPT_DEVNAME_R SI_NETBSD +#define SANITIZER_INTERCEPT_FGETLN SI_NETBSD #endif // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H Index: test/sanitizer_common/TestCases/NetBSD/fgetln.cc =================================================================== --- test/sanitizer_common/TestCases/NetBSD/fgetln.cc +++ test/sanitizer_common/TestCases/NetBSD/fgetln.cc @@ -0,0 +1,23 @@ +// RUN: %clangxx -O0 -g %s -o %t && %run %t + +#include +#include + +int main(void) { + FILE *fp; + size_t len; + char *s; + + fp = fopen("/etc/hosts", "r"); + if (!fp) + exit(1); + + s = fgetln(fp, &len); + + printf("%.*s\n", (int)len, s); + + if (fclose(fp) == EOF) + exit(1); + + return 0; +}