summaryrefslogtreecommitdiffstats
path: root/src/corelib/io
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2016-01-06 13:31:11 +0100
committerMarc Mutz <marc.mutz@kdab.com>2016-01-12 06:11:53 +0000
commit13189360e50a429ee43ce927c29ebcd3948619b7 (patch)
treea108ca76c2ff9dab68f881124a3cb96c00ff335b /src/corelib/io
parentb4ab4868bc8422e09590d13d35c2bba7a195ccf5 (diff)
Fix UB in QFileDevice::writeData()
Passing nullptr as the 2nd argument of memcpy constitutes undefined behavior. Fix by protecting the block with 'if (len)', which, presumably, is the only valid case where 'data' may be nullptr. Change-Id: I7647d7e0808b1f26444ea3cf8bbf5cda9ddc9e6c Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'src/corelib/io')
-rw-r--r--src/corelib/io/qfiledevice.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/corelib/io/qfiledevice.cpp b/src/corelib/io/qfiledevice.cpp
index 3ee0e33573..2d6be5fb80 100644
--- a/src/corelib/io/qfiledevice.cpp
+++ b/src/corelib/io/qfiledevice.cpp
@@ -560,7 +560,7 @@ qint64 QFileDevice::writeData(const char *data, qint64 len)
char *writePointer = d->writeBuffer.reserve(len);
if (len == 1)
*writePointer = *data;
- else
+ else if (len)
::memcpy(writePointer, data, len);
return len;
}