From c8411a0281c5ebf830920bdce05160c8b0682248 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sat, 14 Sep 2013 18:09:10 +0200 Subject: [PATCH] tst_qurlinternal: fix a use of memcpy on overlapping memory The old code smply copied 100 shorts from the pointer passed into the ushortarray ctor, regardless of the actual bounds of the original array. Fix by making the ctor take the array by deference, deducing the size as a template parameter, and only copying that much. Fixes asan trace: ==18660==ERROR: AddressSanitizer: memcpy-param-overlap: memory ranges [0x7fff3c56de00,0x7fff3c56dec8) and [0x7fff3c56dd60, 0x7fff3c56de28) overlap #0 0x457161 in memcpy asan_interceptors.cc:330 #1 0x4c40fe in ushortarray::ushortarray(unsigned short*) qtbase/tests/auto/corelib/io/qurlinternal/tst_qurlinternal.cpp:62 #2 0x4b0437 in ushortarray::ushortarray(unsigned short*) qtbase/tests/auto/corelib/io/qurlinternal/tst_qurlinternal.cpp:63 #3 0x47b643 in tst_QUrlInternal::idna_testsuite_data() qtbase/tests/auto/corelib/io/qurlinternal/tst_qurlinternal.cpp:119 ... Change-Id: Ie497bc8d337bc680a562482ca71ace535797ffb3 Reviewed-by: Thiago Macieira --- tests/auto/corelib/io/qurlinternal/tst_qurlinternal.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/auto/corelib/io/qurlinternal/tst_qurlinternal.cpp b/tests/auto/corelib/io/qurlinternal/tst_qurlinternal.cpp index 20140451718..4b74dd7906e 100644 --- a/tests/auto/corelib/io/qurlinternal/tst_qurlinternal.cpp +++ b/tests/auto/corelib/io/qurlinternal/tst_qurlinternal.cpp @@ -56,10 +56,11 @@ #define STRINGPREP_BIDI_LEADTRAIL_NOT_RAL 5 struct ushortarray { - ushortarray(unsigned short *array = 0) + ushortarray() {} + template + ushortarray(unsigned short (&array)[N]) { - if (array) - memcpy(points, array, sizeof(points)); + memcpy(points, array, N*sizeof(unsigned short)); } unsigned short points[100];