sdphost, blhost on Mac OSX

cancel
Showing results for 
Search instead for 
Did you mean: 

sdphost, blhost on Mac OSX

509 Views
Contributor II

Neither the provided binaries nor binaries built from source from the SDK for sdphost and blhost would run on my Mac (OS 10.15.3 Catalina).  I tracked the issue down to a pair of bugs in the function get_string_property_utf8 in middleware/mcu-boot/tools/src/blfwk/src/hid-mac.c.

buf isn't cleared at the start of the function and CFStringGetBytes doesn't terminate the set of bytes pulled so buf may have stale data on return (if, for example, on a previous call a longer string was returned).  This is corrected by clearing buf with memset at the start of the function.

Also, range.length passed to CFStringGetBytes must not exceed the length of the string.  See Apple's documentation:
   CFStringGetBytes(_:_:_:_:_:_:_:_:) - Core Foundation | Apple Developer Documentation

This is fixed by setting range.length with CFStringGetLength(str) instead of the length of buf.  On my Mac both applications abort with an invalid argument exception without this fix.  With it all is well.

The corrected function is below.  I hope this will save someone some time and that it eventually works its way back into the source tree.

   -Andrew

static int get_string_property_utf8(IOHIDDeviceRef device, CFStringRef prop, char *buf, size_t len)
{
    CFStringRef str = IOHIDDeviceGetProperty(device, prop);

    memset(buf,0,len);

    if (str)
    {
        CFRange range;
        range.location = 0;
        range.length = CFStringGetLength(str);
        CFIndex used_buf_len;
        CFStringGetBytes(str, range, kCFStringEncodingUTF8, (char)'?', FALSE, (UInt8 *)buf, len, &used_buf_len);
        return used_buf_len;
    }
    return 0;
}

0 Kudos
4 Replies

275 Views
Contributor II

get_string_property in the same file should also have the same change.

275 Views
NXP Employee
NXP Employee

Hello Andrew,

we already fixed it internally, probably it will take some time to get into the latest SDKs builds. I recommend also in both functions to change

from

buf[len - 1] = 0x00000000;

to

buf[used_buf_len] = 0x00000000;

Regards,

Libor

0 Kudos

275 Views
Contributor II

Any luck pushing this new SDK out (or just a new release of the sdphost and related binaries)? The flashloader archives available for download for both the RT1050 and the RT1060 are from 2018(!)

0 Kudos

222 Views
NXP Employee
NXP Employee

Hello,

a little older post, still it can help someone. The blhost 2.6.2 available here https://www.nxp.com/webapp/Download?colCode=blhost_2.6.2&appType=license has the issue with Mac OS fixed, sources are included.

 

Regards,

Libor

0 Kudos