Add a new interceptor for nl_langinfo(3) from NetBSD
authorKamil Rytarowski <n54@gmx.com>
Wed, 5 Dec 2018 15:06:53 +0000 (15:06 +0000)
committerKamil Rytarowski <n54@gmx.com>
Wed, 5 Dec 2018 15:06:53 +0000 (15:06 +0000)
Summary:
nl_langinfo - gets locale information.

Add a dedicated test.

Reviewers: vitalybuka, joerg

Reviewed By: vitalybuka

Subscribers: kubamracek, llvm-commits, mgorny, #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D55015

llvm-svn: 348369

compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
compiler-rt/test/sanitizer_common/TestCases/NetBSD/nl_langinfo.cc [new file with mode: 0644]

index ea97c78..64bfc2f 100644 (file)
@@ -7664,6 +7664,19 @@ INTERCEPTOR(int, sysctlgetmibinfo, char *sname, int *name,
 #define INIT_SYSCTLGETMIBINFO
 #endif
 
+#if SANITIZER_INTERCEPT_NL_LANGINFO
+INTERCEPTOR(char *, nl_langinfo, long item) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, nl_langinfo, item);
+  char *ret = REAL(nl_langinfo)(item);
+  if (ret)
+    COMMON_INTERCEPTOR_WRITE_RANGE(ctx, ret, REAL(strlen)(ret) + 1);
+  return ret;
+}
+#define INIT_NL_LANGINFO COMMON_INTERCEPT_FUNCTION(nl_langinfo)
+#else
+#define INIT_NL_LANGINFO
+#endif
 
 static void InitializeCommonInterceptors() {
   static u64 metadata_mem[sizeof(MetadataHashMap) / sizeof(u64) + 1];
@@ -7927,6 +7940,7 @@ static void InitializeCommonInterceptors() {
   INIT_SYSCTL;
   INIT_ASYSCTL;
   INIT_SYSCTLGETMIBINFO;
+  INIT_NL_LANGINFO;
 
   INIT___PRINTF_CHK;
 }
index 03a0cc0..abac63d 100644 (file)
   SI_LINUX || SI_MAC)
 #define SANITIZER_INTERCEPT_GETMNTINFO SI_NETBSD
 #define SANITIZER_INTERCEPT_MI_VECTOR_HASH SI_NETBSD
+#define SANITIZER_INTERCEPT_NL_LANGINFO SI_NETBSD
 #define SANITIZER_INTERCEPT_GETVFSSTAT SI_NETBSD
 #define SANITIZER_INTERCEPT_REGEX SI_NETBSD
 #define SANITIZER_INTERCEPT_FTS SI_NETBSD
diff --git a/compiler-rt/test/sanitizer_common/TestCases/NetBSD/nl_langinfo.cc b/compiler-rt/test/sanitizer_common/TestCases/NetBSD/nl_langinfo.cc
new file mode 100644 (file)
index 0000000..1c84e5f
--- /dev/null
@@ -0,0 +1,18 @@
+// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s
+
+#include <langinfo.h>
+
+#include <stdio.h>
+
+int main(void) {
+  printf("nl_langinfo\n");
+
+  char *info = nl_langinfo(DAY_1);
+
+  printf("DAY_1='%s'\n", info);
+
+  // CHECK: nl_langinfo
+  // CHECK: DAY_1='{{.*}}'
+
+  return 0;
+}