Skip to content

Commit

Permalink
Fix 32bit int overflow
Browse files Browse the repository at this point in the history
Do not continue if the conversion to 32bit int would cause an overflow.

Change-Id: I8a198dce5962e7ebd248b9baa92aba8730bfd3b0
Reviewed-by: Edward Welbourne <[email protected]>
  • Loading branch information
Allan Sandfeld Jensen committed Apr 27, 2020
1 parent 41387bb commit a1f9729
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/network/ssl/qasn1element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include <QtCore/qvector.h>
#include <QDebug>

#include <limits>
#include <locale>

QT_BEGIN_NAMESPACE
Expand Down Expand Up @@ -120,7 +121,7 @@ bool QAsn1Element::read(QDataStream &stream)
return false;

// length
qint64 length = 0;
quint64 length = 0;
quint8 first;
stream >> first;
if (first & 0x80) {
Expand All @@ -139,11 +140,13 @@ bool QAsn1Element::read(QDataStream &stream)
length = (first & 0x7f);
}

if (length > quint64(std::numeric_limits<int>::max()))
return false;
// value
QByteArray tmpValue;
tmpValue.resize(length);
int count = stream.readRawData(tmpValue.data(), tmpValue.size());
if (count != length)
if (count != int(length))
return false;

mType = tmpType;
Expand Down

0 comments on commit a1f9729

Please sign in to comment.