Skip to content

Commit

Permalink
Add checks for null/zero-length key/certficate values in `SSLKeyCertP…
Browse files Browse the repository at this point in the history
…air::assign()` (#1606)

Fixes occurrence of `E:M 0` in debug logs.
  • Loading branch information
mikee47 authored and slaff committed Feb 8, 2019
1 parent 058299a commit 8dc96a5
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions Sming/SmingCore/Network/TcpConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,26 @@ struct SSLKeyCertPair {
{
free();

key = new uint8_t[newKeyLength];
if(key == nullptr) {
return false;
if(newKeyLength != 0 && newKey != nullptr) {
key = new uint8_t[newKeyLength];
if(key == nullptr) {
return false;
}
memcpy(key, newKey, newKeyLength);
keyLength = newKeyLength;
}
memcpy(key, newKey, newKeyLength);
keyLength = newKeyLength;

certificate = new uint8_t[newCertificateLength];
if(certificate == nullptr) {
return false;
if(newCertificateLength != 0 && newCertificate != nullptr) {
certificate = new uint8_t[newCertificateLength];
if(certificate == nullptr) {
return false;
}
memcpy(certificate, newCertificate, newCertificateLength);
certificateLength = newCertificateLength;
}
memcpy(certificate, newCertificate, newCertificateLength);
certificateLength = newCertificateLength;

unsigned passwordLength = (newKeyPassword == nullptr) ? 0 : strlen(newKeyPassword);
if(passwordLength > 0) {
if(passwordLength != 0) {
keyPassword = new char[passwordLength + 1];
if(keyPassword == nullptr) {
return false;
Expand Down

0 comments on commit 8dc96a5

Please sign in to comment.