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

Commit c2bf8e83 authored by Dan Austin's avatar Dan Austin
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
Change-Id: I9c5dc1cc22a27dc998ae8eeacc9f889373d993cd
parent a763da3f
Loading
Loading
Loading
Loading
+17 −18
Original line number Original line 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; ) {
        for (word = 0; word < bytesPerLine; ) {


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


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