Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-46875

Exception in QSerialPortInfo::availablePorts() on OS X 10.10 with some USB devices

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 4.8.x, 5.5.1
    • 5.2.1, 5.4.2
    • Serial Port
    • None
    • OS X 10.10
    • macOS

    Description

      CFTypeRef returned by IORegistryEntrySearchCFProperty sometimes may be of unexpected type.
      That leads to exception and/or crash with some USB devices when product id is parsed in the internal loop of QSerialPortInfo::availablePorts() in qserialportinfo_mac.cpp.

      Console output is attached:

      • main-thread.log: the exception when the availablePorts function is called from the main thread;
      • qthread-crash.log: the crash when the availablePorts function is called from QThread.

      It occurred by checking type with CFGetTypeID() that returned type of CFTypeRef corresponds to CFString instead of CFNumber for kUSBProductID during the first internal loop run. CFNumberRef is returned only during the second loop run.

      So, CFStringRef is used as an argument for CFNumberGetValue() instead of CFNumberRef.

      On OS X versions before 10.10 the wrong type was handled by CFNumberGetValue(). The return value was 'false'. So, on Qt5.2.1 the hasProductIdentifier field was 'false', and on Qt5.4.2 the product id was correct.
      Starting from OS X 10.10 CFNumberGetValue() throws the exception in that case and there is no a workaround.

      The simplest fix is to check the type in searchShortIntProperty() before calling CFNumberGetValue():
      CFGetTypeID(result.as<CFNumberRef>()) == CFNumberGetTypeID().

      Attachments

        1. main-thread.log
          5 kB
          Orest Hera
        2. qthread-crash.log
          5 kB
          Orest Hera
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            kuzulis Denis Shienkov
            orest Orest Hera
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes