From ef80764db37aa00bbb88755cb6cf11c6f2720bd3 Mon Sep 17 00:00:00 2001 From: Marcus Oakland Date: Tue, 25 Mar 2014 17:32:00 +0000 Subject: AArch64: AString::append for longs and pointers The AString::append methods for long, unsigned long and void * pointers were using char arrays of 16 elements, which were not long enough for 64-bit longs and pointers in __LP64__ systems. This resulted in "FORTIFY_SOURCE: vsprintf: prevented write past end of buffer. Calling abort()." when the android.media.cts.DecoderTest#testFlush CTS test was run. The AString::append methods that were using sprintf have been modifed to use snprintf instead, taking the sizeof the "s" array (which has been made 32 char without conditional compilation for __LP64__ where appropriate), and checking the return value to ensure that the string has not been truncated. After this change and changes to the types of OMX_U32 and OMX_S32 in the frameworks/native/include/media/openmax/OMX_Types.h header file, the android.media.cts.DecoderTest#testFlush CTS test passes. Change-Id: I76d897373473c82f52986f43a15b050b844a370a Signed-off-by: Marcus Oakland --- media/libstagefright/foundation/AString.cpp | 42 ++++++++++++++--------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'media/libstagefright/foundation') diff --git a/media/libstagefright/foundation/AString.cpp b/media/libstagefright/foundation/AString.cpp index dee786d..b6b21f1 100644 --- a/media/libstagefright/foundation/AString.cpp +++ b/media/libstagefright/foundation/AString.cpp @@ -189,64 +189,64 @@ void AString::append(const AString &from, size_t offset, size_t n) { void AString::append(int x) { char s[16]; - sprintf(s, "%d", x); - + int result = snprintf(s, sizeof(s), "%d", x); + CHECK((result > 0) && ((size_t) result) < sizeof(s)); append(s); } void AString::append(unsigned x) { char s[16]; - sprintf(s, "%u", x); - + int result = snprintf(s, sizeof(s), "%u", x); + CHECK((result > 0) && ((size_t) result) < sizeof(s)); append(s); } void AString::append(long x) { - char s[16]; - sprintf(s, "%ld", x); - + char s[32]; + int result = snprintf(s, sizeof(s), "%ld", x); + CHECK((result > 0) && ((size_t) result) < sizeof(s)); append(s); } void AString::append(unsigned long x) { - char s[16]; - sprintf(s, "%lu", x); - + char s[32]; + int result = snprintf(s, sizeof(s), "%lu", x); + CHECK((result > 0) && ((size_t) result) < sizeof(s)); append(s); } void AString::append(long long x) { char s[32]; - sprintf(s, "%lld", x); - + int result = snprintf(s, sizeof(s), "%lld", x); + CHECK((result > 0) && ((size_t) result) < sizeof(s)); append(s); } void AString::append(unsigned long long x) { char s[32]; - sprintf(s, "%llu", x); - + int result = snprintf(s, sizeof(s), "%llu", x); + CHECK((result > 0) && ((size_t) result) < sizeof(s)); append(s); } void AString::append(float x) { char s[16]; - sprintf(s, "%f", x); - + int result = snprintf(s, sizeof(s), "%f", x); + CHECK((result > 0) && ((size_t) result) < sizeof(s)); append(s); } void AString::append(double x) { char s[16]; - sprintf(s, "%f", x); - + int result = snprintf(s, sizeof(s), "%f", x); + CHECK((result > 0) && ((size_t) result) < sizeof(s)); append(s); } void AString::append(void *x) { - char s[16]; - sprintf(s, "%p", x); - + char s[32]; + int result = snprintf(s, sizeof(s), "%p", x); + CHECK((result > 0) && ((size_t) result) < sizeof(s)); append(s); } -- cgit v1.1