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

Commit 210648c4 authored by Dan Austin's avatar Dan Austin Committed by Alex Deymo
Browse files

Fix benign integer overflow in printHexDump

There is an instance where an unsigned integer is multiplied by -1.
Refactor the code to eliminate this operation.

Bug: 25085348

(cherry picked from commit c2bf8e83)

Change-Id: I7efa5c3c2f4ff7bd895c1cc74ec244561dc59bb8
parent a5bcc959
Loading
Loading
Loading
Loading
+17 −18
Original line number Diff line number Diff line
@@ -221,7 +221,6 @@ void printHexData(int32_t indent, const void *buf, size_t length,
        for (word = 0; word < bytesPerLine; ) {

            const size_t startIndex = word+(alignment-(alignment?1:0));
            const ssize_t dir = -1;

            for (index = 0; index < alignment || (alignment == 0 && index < bytesPerLine); index++) {

@@ -231,7 +230,7 @@ void printHexData(int32_t indent, const void *buf, size_t length,
                    }

                    if (remain-- > 0) {
                        const unsigned char val = *(pos+startIndex+(index*dir));
                        const unsigned char val = *(pos+startIndex-index);
                        *c++ = makehexdigit(val>>4);
                        *c++ = makehexdigit(val);
                    } else if (!oneLine) {
@@ -248,7 +247,7 @@ void printHexData(int32_t indent, const void *buf, size_t length,
                            *c++ = '0';
                            *c++ = 'x';
                        }
                        const unsigned char val = *(pos+startIndex+(index*dir));
                        const unsigned char val = *(pos+startIndex-index);
                        *c++ = makehexdigit(val>>4);
                        *c++ = makehexdigit(val);
                        remain--;