diff options
author | Marcus Oakland <marcus.oakland@arm.com> | 2014-03-25 17:32:00 +0000 |
---|---|---|
committer | Ashok Bhat <ashok.bhat@arm.com> | 2014-04-15 13:58:18 +0100 |
commit | ef80764db37aa00bbb88755cb6cf11c6f2720bd3 (patch) | |
tree | 2adc4fe23addd6229400624ecb760a44744b42d7 /media/libstagefright/foundation | |
parent | 9829344d526f87ca745208f04216ec795b239581 (diff) | |
download | frameworks_av-ef80764db37aa00bbb88755cb6cf11c6f2720bd3.zip frameworks_av-ef80764db37aa00bbb88755cb6cf11c6f2720bd3.tar.gz frameworks_av-ef80764db37aa00bbb88755cb6cf11c6f2720bd3.tar.bz2 |
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 <marcus.oakland@arm.com>
Diffstat (limited to 'media/libstagefright/foundation')
-rw-r--r-- | media/libstagefright/foundation/AString.cpp | 42 |
1 files changed, 21 insertions, 21 deletions
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); } |