From: Alfonso Gregory <83477269+AtariDreams@users.noreply.github.com> Date: Sat, 28 Aug 2021 16:04:53 +0000 (-0400) Subject: Fix undefined behavior regarding pData X-Git-Tag: v2.4b1~83^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F228%2Fhead;p=thirdparty%2Fcups.git Fix undefined behavior regarding pData pData is a void pointer, and even though the address at request.pData[2] is being cast to that of a const UInt8 pointer, the request.pData has to be converted first BEFORE doing any pointer arithmetic. For this reason, it is best to write this it as a pointer sum, rather than an array. --- diff --git a/backend/usb-darwin.c b/backend/usb-darwin.c index 7c25905319..b17a9b382a 100644 --- a/backend/usb-darwin.c +++ b/backend/usb-darwin.c @@ -1616,14 +1616,14 @@ static CFStringRef copy_printer_interface_deviceid(printer_interface_t printer, if (actualLength > 2 && actualLength <= bufferLength - 2) { - ret = CFStringCreateWithBytes(NULL, (const UInt8 *) &request.pData[2], actualLength - 2, kCFStringEncodingUTF8, false); + ret = CFStringCreateWithBytes(NULL, (const UInt8 *)request.pData + 2, actualLength - 2, kCFStringEncodingUTF8, false); } else if (actualLength > 2) { err = sendRequest(actualLength); if (err == kIOReturnSuccess && request.wLenDone > 0) { actualLength = OSSwapBigToHostInt16(*((UInt16 *)request.pData)); - ret = CFStringCreateWithBytes(NULL, (const UInt8 *) &request.pData[2], actualLength - 2, kCFStringEncodingUTF8, false); + ret = CFStringCreateWithBytes(NULL, (const UInt8 *)request.pData + 2, actualLength - 2, kCFStringEncodingUTF8, false); } } } @@ -1817,7 +1817,7 @@ static CFStringRef copy_printer_interface_indexed_description(printer_interface_ if ((description[0] & 1) != 0) description[0] &= 0xfe; - char buffer[258] = {}; + char buffer[258] = {0}; unsigned int maxLength = sizeof buffer; if (description[0] > 1) {