summaryrefslogtreecommitdiffstats
path: root/libutils/BlobCache.cpp
diff options
context:
space:
mode:
authorAntoine Labour <piman@google.com>2014-07-28 15:35:15 -0700
committerAntoine Labour <piman@google.com>2014-07-28 15:50:33 -0700
commit5f6ebc2f9c9820c8faa2f83b265e31842dc5ed6d (patch)
tree1f896e562c347aeb93edf5f85004686372d919ba /libutils/BlobCache.cpp
parent1e92ed5e83474c157237de18af5b2201095f37e3 (diff)
downloadcore-5f6ebc2f9c9820c8faa2f83b265e31842dc5ed6d.tar.gz
core-5f6ebc2f9c9820c8faa2f83b265e31842dc5ed6d.tar.bz2
core-5f6ebc2f9c9820c8faa2f83b265e31842dc5ed6d.zip
BlobCache: fix uninitialized memory
When flattening the BlobCache, we insert padding for alignment. Make sure to zero the padding bytes to have reproducible results. Bug: 16569863 Change-Id: Id39eac5e6a1687459eb6bc2074b1339393fce711
Diffstat (limited to 'libutils/BlobCache.cpp')
-rw-r--r--libutils/BlobCache.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/libutils/BlobCache.cpp b/libutils/BlobCache.cpp
index f00bf1469..8edb4013d 100644
--- a/libutils/BlobCache.cpp
+++ b/libutils/BlobCache.cpp
@@ -213,7 +213,14 @@ status_t BlobCache::flatten(void* buffer, size_t size) const {
memcpy(eheader->mData, keyBlob->getData(), keySize);
memcpy(eheader->mData + keySize, valueBlob->getData(), valueSize);
- byteOffset += align4(entrySize);
+ size_t totalSize = align4(entrySize);
+ if (totalSize > entrySize) {
+ // We have padding bytes. Those will get written to storage, and contribute to the CRC,
+ // so make sure we zero-them to have reproducible results.
+ memset(eheader->mData + keySize + valueSize, 0, totalSize - entrySize);
+ }
+
+ byteOffset += totalSize;
}
return OK;