Commit db4dad97e2589ca700d1b5b54eeb332137a152ad

Anthony Green 2017-09-27T20:47:08

Merge pull request #312 from fjricci/fix_ub Fix misaligned memory access in ffi_call_int

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
diff --git a/src/x86/ffi64.c b/src/x86/ffi64.c
index 2603a3a..757930b 100644
--- a/src/x86/ffi64.c
+++ b/src/x86/ffi64.c
@@ -646,10 +646,10 @@ ffi_call_int (ffi_cif *cif, void (*fn)(void), void *rvalue,
 		  break;
 		case X86_64_SSE_CLASS:
 		case X86_64_SSEDF_CLASS:
-		  reg_args->sse[ssecount++].i64 = *(UINT64 *) a;
+		  memcpy (&reg_args->sse[ssecount++].i64, a, sizeof(UINT64));
 		  break;
 		case X86_64_SSESF_CLASS:
-		  reg_args->sse[ssecount++].i32 = *(UINT32 *) a;
+		  memcpy (&reg_args->sse[ssecount++].i32, a, sizeof(UINT32));
 		  break;
 		default:
 		  abort();