Fix hang in QMacPasteboard::formats()
PasteboardGetItemCount() can return -1 as result to unsigned variable, so the further loop will iterate "forever". Return early to avoid hang. Change-Id: Ie91dba1c193d04513f0496d20bd0b6b0b5b6c151 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
parent
46076f7333
commit
755521aba6
@ -49,6 +49,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "qcocoahelpers.h"
|
#include "qcocoahelpers.h"
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
@ -61,6 +62,23 @@ QT_BEGIN_NAMESPACE
|
|||||||
QMacPasteboard code
|
QMacPasteboard code
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
OSStatus PasteboardGetItemCountSafe(PasteboardRef paste, ItemCount *cnt)
|
||||||
|
{
|
||||||
|
Q_ASSERT(paste);
|
||||||
|
Q_ASSERT(cnt);
|
||||||
|
const OSStatus result = PasteboardGetItemCount(paste, cnt);
|
||||||
|
// Despite being declared unsigned, this API can return -1
|
||||||
|
if (std::make_signed<ItemCount>::type(*cnt) < 0)
|
||||||
|
*cnt = 0;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
// Ensure we don't call the broken one later on
|
||||||
|
#define PasteboardGetItemCount
|
||||||
|
|
||||||
class QMacMimeData : public QMimeData
|
class QMacMimeData : public QMimeData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -210,7 +228,7 @@ QMacPasteboard::hasOSType(int c_flavor) const
|
|||||||
sync();
|
sync();
|
||||||
|
|
||||||
ItemCount cnt = 0;
|
ItemCount cnt = 0;
|
||||||
if (PasteboardGetItemCount(paste, &cnt) || !cnt)
|
if (PasteboardGetItemCountSafe(paste, &cnt) || !cnt)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
#ifdef DEBUG_PASTEBOARD
|
#ifdef DEBUG_PASTEBOARD
|
||||||
@ -257,7 +275,7 @@ QMacPasteboard::hasFlavor(QString c_flavor) const
|
|||||||
sync();
|
sync();
|
||||||
|
|
||||||
ItemCount cnt = 0;
|
ItemCount cnt = 0;
|
||||||
if (PasteboardGetItemCount(paste, &cnt) || !cnt)
|
if (PasteboardGetItemCountSafe(paste, &cnt) || !cnt)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
#ifdef DEBUG_PASTEBOARD
|
#ifdef DEBUG_PASTEBOARD
|
||||||
@ -374,7 +392,7 @@ QMacPasteboard::formats() const
|
|||||||
|
|
||||||
QStringList ret;
|
QStringList ret;
|
||||||
ItemCount cnt = 0;
|
ItemCount cnt = 0;
|
||||||
if (PasteboardGetItemCount(paste, &cnt) || !cnt)
|
if (PasteboardGetItemCountSafe(paste, &cnt) || !cnt)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
#ifdef DEBUG_PASTEBOARD
|
#ifdef DEBUG_PASTEBOARD
|
||||||
@ -417,7 +435,7 @@ QMacPasteboard::hasFormat(const QString &format) const
|
|||||||
sync();
|
sync();
|
||||||
|
|
||||||
ItemCount cnt = 0;
|
ItemCount cnt = 0;
|
||||||
if (PasteboardGetItemCount(paste, &cnt) || !cnt)
|
if (PasteboardGetItemCountSafe(paste, &cnt) || !cnt)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
#ifdef DEBUG_PASTEBOARD
|
#ifdef DEBUG_PASTEBOARD
|
||||||
@ -460,7 +478,7 @@ QMacPasteboard::retrieveData(const QString &format, QVariant::Type) const
|
|||||||
sync();
|
sync();
|
||||||
|
|
||||||
ItemCount cnt = 0;
|
ItemCount cnt = 0;
|
||||||
if (PasteboardGetItemCount(paste, &cnt) || !cnt)
|
if (PasteboardGetItemCountSafe(paste, &cnt) || !cnt)
|
||||||
return QByteArray();
|
return QByteArray();
|
||||||
|
|
||||||
#ifdef DEBUG_PASTEBOARD
|
#ifdef DEBUG_PASTEBOARD
|
||||||
|
Loading…
x
Reference in New Issue
Block a user