aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/Pl_AES_PDF.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2019-06-22 20:24:49 +0200
committerJay Berkenbilt <ejb@ql.org>2019-06-22 22:57:52 +0200
commit6c39aa87638f7a6f96a97627ac112fb2022bd3a7 (patch)
tree6941498e1cacbd6dcade4a695b27085fa693984f /libqpdf/Pl_AES_PDF.cc
parent12400475283f5081ea55f52a764e43f14032f6ba (diff)
downloadqpdf-6c39aa87638f7a6f96a97627ac112fb2022bd3a7.tar.zst
In shippable code, favor smart pointers (fixes #235)
Use PointerHolder in several places where manually memory allocation and deallocation were being used. This helps to protect against memory leaks when exceptions are thrown in surprising places.
Diffstat (limited to 'libqpdf/Pl_AES_PDF.cc')
-rw-r--r--libqpdf/Pl_AES_PDF.cc24
1 files changed, 14 insertions, 10 deletions
diff --git a/libqpdf/Pl_AES_PDF.cc b/libqpdf/Pl_AES_PDF.cc
index c2c921e6..1099ab13 100644
--- a/libqpdf/Pl_AES_PDF.cc
+++ b/libqpdf/Pl_AES_PDF.cc
@@ -25,29 +25,31 @@ Pl_AES_PDF::Pl_AES_PDF(char const* identifier, Pipeline* next,
{
size_t keybits = 8 * key_bytes;
assert(key_bytes == KEYLENGTH(keybits));
- this->key = new unsigned char[key_bytes];
- this->rk = new uint32_t[RKLENGTH(keybits)];
+ this->key = PointerHolder<unsigned char>(
+ true, new unsigned char[key_bytes]);
+ this->rk = PointerHolder<uint32_t>(
+ true, new uint32_t[RKLENGTH(keybits)]);
size_t rk_bytes = RKLENGTH(keybits) * sizeof(uint32_t);
- std::memcpy(this->key, key, key_bytes);
- std::memset(this->rk, 0, rk_bytes);
+ std::memcpy(this->key.getPointer(), key, key_bytes);
+ std::memset(this->rk.getPointer(), 0, rk_bytes);
std::memset(this->inbuf, 0, this->buf_size);
std::memset(this->outbuf, 0, this->buf_size);
std::memset(this->cbc_block, 0, this->buf_size);
if (encrypt)
{
- this->nrounds = rijndaelSetupEncrypt(this->rk, this->key, keybits);
+ this->nrounds = rijndaelSetupEncrypt(
+ this->rk.getPointer(), this->key.getPointer(), keybits);
}
else
{
- this->nrounds = rijndaelSetupDecrypt(this->rk, this->key, keybits);
+ this->nrounds = rijndaelSetupDecrypt(
+ this->rk.getPointer(), this->key.getPointer(), keybits);
}
assert(this->nrounds == NROUNDS(keybits));
}
Pl_AES_PDF::~Pl_AES_PDF()
{
- delete [] this->key;
- delete [] this->rk;
}
void
@@ -222,7 +224,8 @@ Pl_AES_PDF::flush(bool strip_padding)
this->inbuf[i] ^= this->cbc_block[i];
}
}
- rijndaelEncrypt(this->rk, this->nrounds, this->inbuf, this->outbuf);
+ rijndaelEncrypt(this->rk.getPointer(),
+ this->nrounds, this->inbuf, this->outbuf);
if (this->cbc_mode)
{
memcpy(this->cbc_block, this->outbuf, this->buf_size);
@@ -230,7 +233,8 @@ Pl_AES_PDF::flush(bool strip_padding)
}
else
{
- rijndaelDecrypt(this->rk, this->nrounds, this->inbuf, this->outbuf);
+ rijndaelDecrypt(this->rk.getPointer(),
+ this->nrounds, this->inbuf, this->outbuf);
if (this->cbc_mode)
{
for (unsigned int i = 0; i < this->buf_size; ++i)