Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ef80764d authored by Marcus Oakland's avatar Marcus Oakland Committed by Ashok Bhat
Browse files

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: default avatarMarcus Oakland <marcus.oakland@arm.com>
parent 9829344d
Loading
Loading
Loading
Loading
+21 −21
Original line number Diff line number Diff line
@@ -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);
}