[PATCH] [compiler-rt] Fix the prototype of ioctl interceptor

Kuba Brecka kuba.brecka at gmail.com
Sat Jan 17 19:58:20 PST 2015


The interceptor of ioctl is using a non-standard prototype:

    INTERCEPTOR(int, ioctl, int d, unsigned request, void *arg)

At least on OS X, the `request` argument should be `unsigned long` and not just `unsigned`, and also instead of the last argument (`arg`), the function should be accepting a variable number of arguments, so the prototype should be (per https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man2/ioctl.2.html):

    int ioctl(int fildes, unsigned long request, ...);

It looks to me that this prototype is valid for Linux as well (http://man7.org/linux/man-pages/man2/ioctl.2.html), but I've also found other documents that have request as `int` and not `long` (http://linux.die.net/man/2/ioctl). I'm not sure if we need an platform-specific #if.

I have actually seen a memory corruption and a crash because of that, but I'm unable to create a reproducible test case for it.

http://reviews.llvm.org/D7038

Files:
  lib/sanitizer_common/sanitizer_common_interceptors.inc

Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
===================================================================
--- lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -1025,8 +1025,12 @@
 
 #if SANITIZER_INTERCEPT_IOCTL
 #include "sanitizer_common_interceptors_ioctl.inc"
-INTERCEPTOR(int, ioctl, int d, unsigned request, void *arg) {
+INTERCEPTOR(int, ioctl, int d, unsigned long request, ...) {
   void *ctx;
+  va_list ap;
+  va_start(ap, request);
+  void *arg = va_arg(ap, void *);
+  va_end(ap);
   COMMON_INTERCEPTOR_ENTER(ctx, ioctl, d, request, arg);
 
   CHECK(ioctl_initialized);

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7038.18352.patch
Type: text/x-patch
Size: 675 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150118/fe759e2a/attachment.bin>


More information about the llvm-commits mailing list