Commit 7f0be6a3 authored by Leslie Zhai's avatar Leslie Zhai

Fix K3b::Device::from2Byte out-of-bounds issue.

A great bug report by Mark!

BUG: 382941
parent 7f1ca631
......@@ -212,27 +212,27 @@ void K3b::Device::debugBitfield( unsigned char* data, long len )
}
quint16 K3b::Device::from2Byte( const unsigned char* d )
quint16 K3b::Device::from2Byte(const unsigned char* d)
{
if (d == NULL) {
qWarning() << "Invalid nullptr!";
if (d == NULL || strlen((const char *) d) < 2) {
qWarning() << "Invalid Byte!";
return 0;
}
return ( (d[0] << 8 & 0xFF00) |
(d[1] & 0xFF) );
return ((d[0] << 8 & 0xFF00) |
(d[1] & 0xFF));
}
quint32 K3b::Device::from4Byte( const unsigned char* d )
quint32 K3b::Device::from4Byte(const unsigned char* d)
{
if (d == NULL) {
qWarning() << "Invalid nullptr!";
if (d == NULL || strlen((const char *) d) < 4) {
qWarning() << "Invalid Byte!";
return 0;
}
return ( (d[0] << 24 & 0xFF000000) |
(d[1] << 16 & 0xFF0000) |
(d[2] << 8 & 0xFF00) |
(d[3] & 0xFF) );
return ((d[0] << 24 & 0xFF000000) |
(d[1] << 16 & 0xFF0000) |
(d[2] << 8 & 0xFF00) |
(d[3] & 0xFF));
}
......
......@@ -23,8 +23,10 @@ DeviceGlobalsTest::DeviceGlobalsTest()
void DeviceGlobalsTest::testFrom2Byte()
{
const unsigned char* d = NULL;
unsigned char* d = NULL;
QCOMPARE(K3b::Device::from2Byte(d), (quint16)0);
unsigned char buf[1] = { '\0' };
QCOMPARE(K3b::Device::from2Byte(buf), (quint16)0);
}
void DeviceGlobalsTest::testFrom4Byte()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment