Skip to content

Commit

Permalink
[MOS] Fix signed bit shifts leading to out-of-bounds access
Browse files Browse the repository at this point in the history
The event tracing code uses a const char array and bit shifts to convert byte
values (to be output into the trace) into two-character hex representation
through addressing the const array depending on the byte value. Since
char is signed, using char to represent byte values sometimes leads to
addressing an element of the const char array by a negative index. Replaced
with unsigned char.
  • Loading branch information
vshampor authored and oliver-sang committed Apr 17, 2018
1 parent 58e9c4e commit 45f063f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions media_driver/linux/common/os/mos_utilities_specific.c
Original file line number Diff line number Diff line change
Expand Up @@ -2825,7 +2825,7 @@ void MOS_TraceEvent(
// convert raw event data to string. native raw data will be supported
// from linux kernel 4.10, hopefully we can skip this convert in the future.
const static char n2c[] = "0123456789ABCDEF";
char *pData = (char *)pArg1;
unsigned char *pData = (unsigned char *)pArg1;

pTraceBuf[nLen++] = '|'; // prefix splite marker.
while(dwSize1-- > 0 && nLen < TRACE_EVENT_MAX_SIZE-2)
Expand All @@ -2835,7 +2835,7 @@ void MOS_TraceEvent(
}
if (pArg2)
{
pData = (char *)pArg2;
pData = (unsigned char *)pArg2;
while(dwSize2-- > 0 && nLen < TRACE_EVENT_MAX_SIZE-2)
{
pTraceBuf[nLen++] = n2c[(*pData) >> 4];
Expand Down

0 comments on commit 45f063f

Please sign in to comment.