Skip to content
This repository has been archived by the owner on Dec 10, 2019. It is now read-only.

Commit

Permalink
Don't trust input data in decrypt functions. Fix #90
Browse files Browse the repository at this point in the history
  • Loading branch information
librehat committed Dec 14, 2016
1 parent 2959fff commit bf1eeed
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/encryptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,13 @@ QByteArray Encryptor::decrypt(const QByteArray &in)

QByteArray out;
if (!deCipher) {
QByteArray iv = in.mid(0, ep.ivLen);
if (iv.length() != ep.ivLen) {
return out;
}
deCipher = new Cipher(ep.method,
ep.key,
in.mid(0, ep.ivLen),
iv,
false,
this);
out = deCipher->update(in.mid(ep.ivLen));
Expand Down Expand Up @@ -100,7 +104,11 @@ QByteArray Encryptor::decryptAll(const QByteArray &in)
if (deCipher) {
deCipher->deleteLater();
}
deCipher = new Cipher(ep.method, ep.key, in.mid(0, ep.ivLen), false, this);
QByteArray iv = in.mid(0, ep.ivLen);
if (iv.length() != ep.ivLen) {
return QByteArray();
}
deCipher = new Cipher(ep.method, ep.key, iv, false, this);
return deCipher->update(in.mid(ep.ivLen));
}

Expand Down

0 comments on commit bf1eeed

Please sign in to comment.