libcalamares: Prevent integer overflows when parsing configuration
Currently, a number of configuration parsing-related functions and classes use only `int` type for dealing with integers. Should the user need a bigger integer value, this would result in an erroneous value being used (`0`), as the correct value would overflow the 32-bits type. In order to prevent these overflow, this patch replaces `int` with `qint64` in the following functions & classes : * CalamaresUtils::yamlScalarToVariant() * CalamaresUtils::getInteger * NamedSuffix * PartitionSize This way, sizes or other integer values greater than 2^31 (for signed types) can be used. Signed-off-by: Arnaud Ferraris <arnaud.ferraris@collabora.com>
This commit is contained in:
parent
8c78a6cdfa
commit
0d06e047ae
@ -50,7 +50,7 @@ PartitionSize::PartitionSize( const QString& s )
|
||||
|
||||
if ( m_unit == SizeUnit::None )
|
||||
{
|
||||
m_value = s.toInt();
|
||||
m_value = s.toLongLong();
|
||||
if ( m_value > 0 )
|
||||
{
|
||||
m_unit = SizeUnit::Byte;
|
||||
|
@ -58,7 +58,7 @@ public:
|
||||
}
|
||||
|
||||
/** @brief Specific value and unit. */
|
||||
NamedSuffix( int value, unit_t unit )
|
||||
NamedSuffix( qint64 value, unit_t unit )
|
||||
: m_value( value )
|
||||
, m_unit( unit )
|
||||
{
|
||||
@ -75,7 +75,7 @@ public:
|
||||
for ( const auto& suffix : table.table )
|
||||
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;
|
||||
break;
|
||||
}
|
||||
@ -89,7 +89,7 @@ public:
|
||||
*/
|
||||
NamedSuffix( const QString& s );
|
||||
|
||||
int value() const { return m_value; }
|
||||
qint64 value() const { return m_value; }
|
||||
unit_t unit() const { return m_unit; }
|
||||
|
||||
/** @brief Check that a value-unit combination is valid.
|
||||
@ -100,7 +100,7 @@ public:
|
||||
bool isValid() const;
|
||||
|
||||
protected:
|
||||
int m_value;
|
||||
qint64 m_value;
|
||||
unit_t m_unit;
|
||||
};
|
||||
|
||||
|
@ -61,10 +61,10 @@ getString( const QVariantMap& map, const QString& key )
|
||||
return QString();
|
||||
}
|
||||
|
||||
int
|
||||
getInteger( const QVariantMap& map, const QString& key, int d )
|
||||
qint64
|
||||
getInteger( const QVariantMap& map, const QString& key, qint64 d )
|
||||
{
|
||||
int result = d;
|
||||
qint64 result = d;
|
||||
if ( map.contains( key ) )
|
||||
{
|
||||
auto v = map.value( key );
|
||||
@ -72,6 +72,10 @@ getInteger( const QVariantMap& map, const QString& key, int d )
|
||||
{
|
||||
result = v.toInt();
|
||||
}
|
||||
else if ( v.type() == QVariant::LongLong )
|
||||
{
|
||||
result = v.toLongLong();
|
||||
}
|
||||
}
|
||||
|
||||
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.
|
||||
*/
|
||||
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.
|
||||
|
@ -79,7 +79,7 @@ yamlScalarToVariant( const YAML::Node& scalarNode )
|
||||
}
|
||||
if ( QRegExp( "[-+]?\\d+" ).exactMatch( scalarString ) )
|
||||
{
|
||||
return QVariant( scalarString.toInt() );
|
||||
return QVariant( scalarString.toLongLong() );
|
||||
}
|
||||
if ( QRegExp( "[-+]?\\d*\\.?\\d+" ).exactMatch( scalarString ) )
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user