Merge pull request #1220 from a-wai/prevent-int-overflow
Prevent integer overflow when parsing configuration
This commit is contained in:
commit
1d047839c7
@ -52,6 +52,9 @@ variantToPyObject( const QVariant& variant )
|
|||||||
case QVariant::Int:
|
case QVariant::Int:
|
||||||
return bp::object( variant.toInt() );
|
return bp::object( variant.toInt() );
|
||||||
|
|
||||||
|
case QVariant::LongLong:
|
||||||
|
return bp::object( variant.toLongLong() );
|
||||||
|
|
||||||
case QVariant::Double:
|
case QVariant::Double:
|
||||||
return bp::object( variant.toDouble() );
|
return bp::object( variant.toDouble() );
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ PartitionSize::PartitionSize( const QString& s )
|
|||||||
|
|
||||||
if ( m_unit == SizeUnit::None )
|
if ( m_unit == SizeUnit::None )
|
||||||
{
|
{
|
||||||
m_value = s.toInt();
|
m_value = s.toLongLong();
|
||||||
if ( m_value > 0 )
|
if ( m_value > 0 )
|
||||||
{
|
{
|
||||||
m_unit = SizeUnit::Byte;
|
m_unit = SizeUnit::Byte;
|
||||||
|
@ -58,7 +58,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @brief Specific value and unit. */
|
/** @brief Specific value and unit. */
|
||||||
NamedSuffix( int value, unit_t unit )
|
NamedSuffix( qint64 value, unit_t unit )
|
||||||
: m_value( value )
|
: m_value( value )
|
||||||
, m_unit( unit )
|
, m_unit( unit )
|
||||||
{
|
{
|
||||||
@ -75,7 +75,7 @@ public:
|
|||||||
for ( const auto& suffix : table.table )
|
for ( const auto& suffix : table.table )
|
||||||
if ( s.endsWith( suffix.first ) )
|
if ( s.endsWith( suffix.first ) )
|
||||||
{
|
{
|
||||||
m_value = s.left( s.length() - suffix.first.length() ).toInt();
|
m_value = s.left( s.length() - suffix.first.length() ).toLongLong();
|
||||||
m_unit = suffix.second;
|
m_unit = suffix.second;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -89,7 +89,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
NamedSuffix( const QString& s );
|
NamedSuffix( const QString& s );
|
||||||
|
|
||||||
int value() const { return m_value; }
|
qint64 value() const { return m_value; }
|
||||||
unit_t unit() const { return m_unit; }
|
unit_t unit() const { return m_unit; }
|
||||||
|
|
||||||
/** @brief Check that a value-unit combination is valid.
|
/** @brief Check that a value-unit combination is valid.
|
||||||
@ -100,7 +100,7 @@ public:
|
|||||||
bool isValid() const;
|
bool isValid() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int m_value;
|
qint64 m_value;
|
||||||
unit_t m_unit;
|
unit_t m_unit;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -61,10 +61,10 @@ getString( const QVariantMap& map, const QString& key )
|
|||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
qint64
|
||||||
getInteger( const QVariantMap& map, const QString& key, int d )
|
getInteger( const QVariantMap& map, const QString& key, qint64 d )
|
||||||
{
|
{
|
||||||
int result = d;
|
qint64 result = d;
|
||||||
if ( map.contains( key ) )
|
if ( map.contains( key ) )
|
||||||
{
|
{
|
||||||
auto v = map.value( key );
|
auto v = map.value( key );
|
||||||
@ -72,6 +72,10 @@ getInteger( const QVariantMap& map, const QString& key, int d )
|
|||||||
{
|
{
|
||||||
result = v.toInt();
|
result = v.toInt();
|
||||||
}
|
}
|
||||||
|
else if ( v.type() == QVariant::LongLong )
|
||||||
|
{
|
||||||
|
result = v.toLongLong();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -41,7 +41,7 @@ DLLEXPORT QString getString( const QVariantMap& map, const QString& key );
|
|||||||
/**
|
/**
|
||||||
* Get an integer value from a mapping; returns @p d if no value.
|
* Get an integer value from a mapping; returns @p d if no value.
|
||||||
*/
|
*/
|
||||||
DLLEXPORT int getInteger( const QVariantMap& map, const QString& key, int d );
|
DLLEXPORT qint64 getInteger( const QVariantMap& map, const QString& key, qint64 d );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a double value from a mapping (integers are converted); returns @p d if no value.
|
* Get a double value from a mapping (integers are converted); returns @p d if no value.
|
||||||
|
@ -79,7 +79,7 @@ yamlScalarToVariant( const YAML::Node& scalarNode )
|
|||||||
}
|
}
|
||||||
if ( QRegExp( "[-+]?\\d+" ).exactMatch( scalarString ) )
|
if ( QRegExp( "[-+]?\\d+" ).exactMatch( scalarString ) )
|
||||||
{
|
{
|
||||||
return QVariant( scalarString.toInt() );
|
return QVariant( scalarString.toLongLong() );
|
||||||
}
|
}
|
||||||
if ( QRegExp( "[-+]?\\d*\\.?\\d+" ).exactMatch( scalarString ) )
|
if ( QRegExp( "[-+]?\\d*\\.?\\d+" ).exactMatch( scalarString ) )
|
||||||
{
|
{
|
||||||
|
@ -206,7 +206,7 @@ GeneralRequirements::setConfigurationMap( const QVariantMap& configurationMap )
|
|||||||
|
|
||||||
if ( configurationMap.contains( "requiredStorage" ) &&
|
if ( configurationMap.contains( "requiredStorage" ) &&
|
||||||
( configurationMap.value( "requiredStorage" ).type() == QVariant::Double ||
|
( configurationMap.value( "requiredStorage" ).type() == QVariant::Double ||
|
||||||
configurationMap.value( "requiredStorage" ).type() == QVariant::Int ) )
|
configurationMap.value( "requiredStorage" ).type() == QVariant::LongLong ) )
|
||||||
{
|
{
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
m_requiredStorageGiB = configurationMap.value( "requiredStorage" ).toDouble( &ok );
|
m_requiredStorageGiB = configurationMap.value( "requiredStorage" ).toDouble( &ok );
|
||||||
@ -227,7 +227,7 @@ GeneralRequirements::setConfigurationMap( const QVariantMap& configurationMap )
|
|||||||
|
|
||||||
if ( configurationMap.contains( "requiredRam" ) &&
|
if ( configurationMap.contains( "requiredRam" ) &&
|
||||||
( configurationMap.value( "requiredRam" ).type() == QVariant::Double ||
|
( configurationMap.value( "requiredRam" ).type() == QVariant::Double ||
|
||||||
configurationMap.value( "requiredRam" ).type() == QVariant::Int ) )
|
configurationMap.value( "requiredRam" ).type() == QVariant::LongLong ) )
|
||||||
{
|
{
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
m_requiredRamGiB = configurationMap.value( "requiredRam" ).toDouble( &ok );
|
m_requiredRamGiB = configurationMap.value( "requiredRam" ).toDouble( &ok );
|
||||||
|
Loading…
Reference in New Issue
Block a user