Avoid uninitialized bytes in QV4::CompiledData
authorSimon Hausmann <simon.hausmann@theqtcompany.com>
Tue, 5 May 2015 11:14:36 +0000 (13:14 +0200)
committerSimon Hausmann <simon.hausmann@theqtcompany.com>
Fri, 8 May 2015 04:08:24 +0000 (04:08 +0000)
When populating the QV4::CompiledData for a JS unit, we memset the malloc'ed
data to zero. We should do the same when creating a unit for QML files. We do
write all the fields that we use, but due to padding we may end up with bytes
that are neither used nor written but still uninitialized. Consequently they
should be zero'ed, otherwise serialization will write garbage.

Change-Id: I0b093e4dde6789d7236247507221f4f3476ba89d
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
src/qml/compiler/qqmlirbuilder.cpp

index c645a29b1536b6644b01401dcecad85d1249b077..63833504f13e71d92b0317cedcd85855ffa39146 100644 (file)
@@ -1319,6 +1319,7 @@ QV4::CompiledData::Unit *QmlUnitGenerator::generate(Document &output)
     const int totalSize = unitSize + importSize + objectOffsetTableSize + objectsSize + output.jsGenerator.stringTable.sizeOfTableAndData();
     char *data = (char*)malloc(totalSize);
     memcpy(data, jsUnit, unitSize);
+    memset(data + unitSize, 0, totalSize - unitSize);
     if (jsUnit != compilationUnit->data)
         free(jsUnit);
     jsUnit = 0;