ramosian-glider / memory-sanitizer

Automatically exported from code.google.com/p/memory-sanitizer
0 stars 0 forks source link

Origin lost in unaligned memcpy #82

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Clang r227077.

#include <sanitizer/msan_interface.h>
#include <string.h>

int main() {
  char x[8];
  char y[8];

  memset(x, 0, 8);
  __msan_allocated_memory(&x[6], 1);

  memset(y, 0, 8);
  memcpy(y + 1, x, 7);

  __msan_print_shadow(y + 1, 7);
  return 0;
}

Compile with -fsanitize=memory -fsanitize-memory-track-origins=2.

Output:

Shadow map of [0x3fffb04da71d, 0x3fffb04da724), 7 bytes:
0x3fffb04da71c: ..000000 000000ff ........ ........  |. A . .|

Origin A (origin_id 80000002):
  Uninitialized value was created by an allocation of 'y' in the stack frame of function 'main'
    #0 0x7f2811843410 in main (/code/llvm/build/a.out+0x70410)

memcpy() did not update origin for y.

Original issue reported on code.google.com by euge...@google.com on 26 Jan 2015 at 9:56

GoogleCodeExporter commented 9 years ago
Adding Project:MemorySanitizer as part of GitHub migration.

Original comment by gli...@google.com on 30 Jul 2015 at 9:22