[compiler-rt] r174960 - [sanitizer] Intercept __isoc99_*scanf.

Evgeniy Stepanov eugeni.stepanov at gmail.com
Tue Feb 12 03:34:52 PST 2013


Author: eugenis
Date: Tue Feb 12 05:34:52 2013
New Revision: 174960

URL: http://llvm.org/viewvc/llvm-project?rev=174960&view=rev
Log:
[sanitizer] Intercept __isoc99_*scanf.

Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
    compiler-rt/trunk/lib/sanitizer_common/scripts/check_lint.sh

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc?rev=174960&r1=174959&r2=174960&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Tue Feb 12 05:34:52 2013
@@ -150,82 +150,80 @@ INTERCEPTOR(int, prctl, int option, unsi
 
 #include "sanitizer_common_interceptors_scanf.inc"
 
-INTERCEPTOR(int, vscanf, const char *format, va_list ap) { // NOLINT
-  void *ctx;
-  COMMON_INTERCEPTOR_ENTER(ctx, vscanf, format, ap);
-  va_list aq;
-  va_copy(aq, ap);
-  int res = REAL(vscanf)(format, ap); // NOLINT
-  if (res > 0)
-    scanf_common(ctx, res, format, aq);
-  va_end(aq);
-  return res;
-}
-
-INTERCEPTOR(int, vsscanf, const char *str, const char *format, // NOLINT
-            va_list ap) {
-  void *ctx;
-  COMMON_INTERCEPTOR_ENTER(ctx, vsscanf, str, format, ap);
-  va_list aq;
-  va_copy(aq, ap);
-  int res = REAL(vsscanf)(str, format, ap); // NOLINT
-  if (res > 0)
-    scanf_common(ctx, res, format, aq);
-  va_end(aq);
-  // FIXME: read of str
-  return res;
-}
-
-INTERCEPTOR(int, vfscanf, void *stream, const char *format, // NOLINT
-            va_list ap) {
-  void *ctx;
-  COMMON_INTERCEPTOR_ENTER(ctx, vfscanf, stream, format, ap);
-  va_list aq;
-  va_copy(aq, ap);
-  int res = REAL(vfscanf)(stream, format, ap); // NOLINT
-  if (res > 0)
-    scanf_common(ctx, res, format, aq);
-  va_end(aq);
-  return res;
-}
-
-INTERCEPTOR(int, scanf, const char *format, ...) { // NOLINT
-  void *ctx;
-  COMMON_INTERCEPTOR_ENTER(ctx, scanf, format);
-  va_list ap;
-  va_start(ap, format);
-  int res = vscanf(format, ap); // NOLINT
-  va_end(ap);
-  return res;
-}
-
-INTERCEPTOR(int, fscanf, void *stream, const char *format, ...) { // NOLINT
-  void *ctx;
-  COMMON_INTERCEPTOR_ENTER(ctx, fscanf, stream, format);
-  va_list ap;
-  va_start(ap, format);
-  int res = vfscanf(stream, format, ap); // NOLINT
-  va_end(ap);
-  return res;
-}
-
-INTERCEPTOR(int, sscanf, const char *str, const char *format, ...) { // NOLINT
-  void *ctx;
-  COMMON_INTERCEPTOR_ENTER(ctx, sscanf, str, format); // NOLINT
-  va_list ap;
-  va_start(ap, format);
-  int res = vsscanf(str, format, ap); // NOLINT
-  va_end(ap);
-  return res;
-}
+#define VSCANF_INTERCEPTOR_IMPL(vname, ...)                                    \
+  {                                                                            \
+    void *ctx;                                                                 \
+    COMMON_INTERCEPTOR_ENTER(ctx, vname, __VA_ARGS__);                         \
+    va_list aq;                                                                \
+    va_copy(aq, ap);                                                           \
+    int res = REAL(vname)(__VA_ARGS__);                                        \
+    if (res > 0)                                                               \
+      scanf_common(ctx, res, format, aq);                                      \
+    va_end(aq);                                                                \
+    return res;                                                                \
+  }
+
+INTERCEPTOR(int, vscanf, const char *format, va_list ap)
+VSCANF_INTERCEPTOR_IMPL(vscanf, format, ap)
+
+INTERCEPTOR(int, vsscanf, const char *str, const char *format, va_list ap)
+VSCANF_INTERCEPTOR_IMPL(vsscanf, str, format, ap)
+
+INTERCEPTOR(int, vfscanf, void *stream, const char *format, va_list ap)
+VSCANF_INTERCEPTOR_IMPL(vfscanf, stream, format, ap)
+
+INTERCEPTOR(int, __isoc99_vscanf, const char *format, va_list ap)
+VSCANF_INTERCEPTOR_IMPL(__isoc99_vscanf, format, ap)
+
+INTERCEPTOR(int, __isoc99_vsscanf, const char *str, const char *format,
+            va_list ap)
+VSCANF_INTERCEPTOR_IMPL(__isoc99_vsscanf, str, format, ap)
+
+INTERCEPTOR(int, __isoc99_vfscanf, void *stream, const char *format, va_list ap)
+VSCANF_INTERCEPTOR_IMPL(__isoc99_vfscanf, stream, format, ap)
+
+#define SCANF_INTERCEPTOR_IMPL(name, vname, ...)                               \
+  {                                                                            \
+    void *ctx;                                                                 \
+    COMMON_INTERCEPTOR_ENTER(ctx, name, __VA_ARGS__);                          \
+    va_list ap;                                                                \
+    va_start(ap, format);                                                      \
+    int res = vname(__VA_ARGS__, ap);                                          \
+    va_end(ap);                                                                \
+    return res;                                                                \
+  }
+
+INTERCEPTOR(int, scanf, const char *format, ...)
+SCANF_INTERCEPTOR_IMPL(scanf, vscanf, format)
+
+INTERCEPTOR(int, fscanf, void *stream, const char *format, ...)
+SCANF_INTERCEPTOR_IMPL(fscanf, vfscanf, stream, format)
+
+INTERCEPTOR(int, sscanf, const char *str, const char *format, ...)
+SCANF_INTERCEPTOR_IMPL(sscanf, vsscanf, str, format)
+
+INTERCEPTOR(int, __isoc99_scanf, const char *format, ...)
+SCANF_INTERCEPTOR_IMPL(__isoc99_scanf, __isoc99_vscanf, format)
+
+INTERCEPTOR(int, __isoc99_fscanf, void *stream, const char *format, ...)
+SCANF_INTERCEPTOR_IMPL(__isoc99_fscanf, __isoc99_vfscanf, stream, format)
+
+INTERCEPTOR(int, __isoc99_sscanf, const char *str, const char *format, ...)
+SCANF_INTERCEPTOR_IMPL(__isoc99_sscanf, __isoc99_vsscanf, str, format)
 
 #define INIT_SCANF                                                             \
   INTERCEPT_FUNCTION(scanf);                                                   \
-  INTERCEPT_FUNCTION(sscanf); /* NOLINT */                                     \
+  INTERCEPT_FUNCTION(sscanf);                                                  \
   INTERCEPT_FUNCTION(fscanf);                                                  \
   INTERCEPT_FUNCTION(vscanf);                                                  \
   INTERCEPT_FUNCTION(vsscanf);                                                 \
-  INTERCEPT_FUNCTION(vfscanf)
+  INTERCEPT_FUNCTION(vfscanf);                                                 \
+  INTERCEPT_FUNCTION(__isoc99_scanf);                                          \
+  INTERCEPT_FUNCTION(__isoc99_sscanf);                                         \
+  INTERCEPT_FUNCTION(__isoc99_fscanf);                                         \
+  INTERCEPT_FUNCTION(__isoc99_vscanf);                                         \
+  INTERCEPT_FUNCTION(__isoc99_vsscanf);                                        \
+  INTERCEPT_FUNCTION(__isoc99_vfscanf);
 
 #else
 #define INIT_SCANF

Modified: compiler-rt/trunk/lib/sanitizer_common/scripts/check_lint.sh
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/scripts/check_lint.sh?rev=174960&r1=174959&r2=174960&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/scripts/check_lint.sh (original)
+++ compiler-rt/trunk/lib/sanitizer_common/scripts/check_lint.sh Tue Feb 12 05:34:52 2013
@@ -30,7 +30,7 @@ TSAN_RTL_LINT_FILTER=${COMMON_LINT_FILTE
 TSAN_TEST_LINT_FILTER=${TSAN_RTL_LINT_FILTER},-runtime/threadsafe_fn,-runtime/int
 TSAN_LIT_TEST_LINT_FILTER=${TSAN_TEST_LINT_FILTER},-whitespace/line_length
 MSAN_RTL_LINT_FILTER=${COMMON_LINT_FILTER}
-COMMON_RTL_INC_LINT_FILTER=${COMMON_LINT_FILTER},-runtime/int,-runtime/sizeof
+COMMON_RTL_INC_LINT_FILTER=${COMMON_LINT_FILTER},-runtime/int,-runtime/sizeof,-runtime/printf
 
 cd ${LLVM_CHECKOUT}
 





More information about the llvm-commits mailing list