http://llvm.org/bugs/show_bug.cgi?id=17200

            Bug ID: 17200
           Summary: bad fixit for Wstrncat-size in macro
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]
    Classification: Unclassified

Example:

nlewycky@ducttape:~$ llvm/Debug+Asserts/bin/clang -fsyntax-only strncat-macro.c
In file included from strncat-macro.c:1:
./strncat-hdr.h:6:24: warning: the value of the size argument in 'strncat' is
      too large, might lead to a buffer overflow [-Wstrncat-size]
    (strncat((A), (B), sizeof(A)-strlen(A)), *((A)+sizeof(A)-1) = '\0')
                       ^~~~~~~~~~~~~~~~~~~
./strncat-hdr.h:5:24: note: change the argument to be the free space in the
      destination buffer minus the terminating null byte
    (strncat((A), (B), sizeof(A)-strlen(A)), *((A)+sizeof(A)-1) = '\0')
                       ^~~~~~~~~~~~~~~~~~~
                       sizeof(dtString) - strlen(dtString) - 1
1 warning generated.

Of course writing in "dtString" for macro argument "A" isn't right. Here's the
two-file testcase:

nlewycky@ducttape:~$ cat strncat-macro.c
#include "strncat-hdr.h"

void test() {
  char dtString[64];
  char usecString[64];
  STRSCAT(dtString, usecString);
}

nlewycky@ducttape:~$ cat strncat-hdr.h 
#define strncat(dest, src, n) __builtin_strncat (dest, src, n)
unsigned long strlen(const char *s);

#define STRSCAT(A,B) \
    (strncat((A), (B), sizeof(A)-strlen(A)), *((A)+sizeof(A)-1) = '\0')

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to