[llvm-bugs] [Bug 28025] New: UBSan doesn't catch misaligned memcpy

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Jun 6 11:56:09 PDT 2016


https://llvm.org/bugs/show_bug.cgi?id=28025

            Bug ID: 28025
           Summary: UBSan doesn't catch misaligned memcpy
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangbugs at nondot.org
          Reporter: ch3root at openwall.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

When optimizing memcpy, clang uses alignment of types arguments point to. It
would be nice for UBSan to catch misaligned pointer in this context in the same
way as in dereferences.

Example of misaligned memcpy:

----------------------------------------------------------------------
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

int main(int argc, char **argv)
{
  (void)argv;

  long double *p = malloc(16);
  memset(p, 123, 16);

  char *q = malloc(17);
  long double *q1 = (void *)(q + 1);
  // *q1 = *p; // this is caught by UBSan
  memcpy(q1, p, 16); // this is not caught

  printf("%d\n", q[argc]);
}
----------------------------------------------------------------------

Results on x86-64:

----------------------------------------------------------------------
$ clang -std=c11 -Weverything -O3 -fsanitize=undefined test.c && ./a.out
Segmentation fault
----------------------------------------------------------------------

clang version: clang version 3.9.0 (trunk 271312)

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160606/72f05a13/attachment.html>


More information about the llvm-bugs mailing list