[PATCH] D55015: Add a new interceptor for nl_langinfo(3) from NetBSD

Kamil Rytarowski via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 28 11:59:46 PST 2018


krytarowski created this revision.
krytarowski added reviewers: vitalybuka, joerg.
krytarowski added a project: Sanitizers.
Herald added subscribers: llvm-commits, kubamracek.

nl_langinfo - gets locale information.

Add a dedicated test.


Repository:
  rL LLVM

https://reviews.llvm.org/D55015

Files:
  lib/sanitizer_common/sanitizer_common_interceptors.inc
  lib/sanitizer_common/sanitizer_platform_interceptors.h
  test/sanitizer_common/TestCases/NetBSD/nl_langinfo.cc


Index: test/sanitizer_common/TestCases/NetBSD/nl_langinfo.cc
===================================================================
--- /dev/null
+++ test/sanitizer_common/TestCases/NetBSD/nl_langinfo.cc
@@ -0,0 +1,19 @@
+// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s
+
+#include <langinfo.h>
+
+#include <stdio.h>
+
+int main(void) {
+  char *info;
+  printf("nl_langinfo\n");
+
+  info = nl_langinfo(DAY_1);
+
+  printf("DAY_1='%s'\n", info);
+
+  // CHECK: nl_langinfo
+  // CHECK: DAY_1='{{.*}}'
+
+  return 0;
+}
Index: lib/sanitizer_common/sanitizer_platform_interceptors.h
===================================================================
--- lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -520,5 +520,6 @@
   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
 
 #endif  // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H
Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
===================================================================
--- lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -7348,6 +7348,20 @@
 #define INIT_SETVBUF
 #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];
   interceptor_metadata_map = new((void *)&metadata_mem) MetadataHashMap();
@@ -7604,6 +7618,7 @@
   INIT_GETMNTINFO;
   INIT_MI_VECTOR_HASH;
   INIT_SETVBUF;
+  INIT_NL_LANGINFO;
 
   INIT___PRINTF_CHK;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55015.175742.patch
Type: text/x-patch
Size: 2061 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181128/f1879dd4/attachment.bin>


More information about the llvm-commits mailing list