Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent nullptr dereference on OOM #7823

Merged
merged 1 commit into from
Jan 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions libraries/ESP8266AVRISP/src/ESP8266AVRISP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,12 @@ uint8_t ESP8266AVRISP::flash_read(uint8_t hilo, int addr) {
0);
}

void ESP8266AVRISP::flash_read_page(int length) {
bool ESP8266AVRISP::flash_read_page(int length) {
uint8_t *data = (uint8_t *) malloc(length + 1);
if (!data)
{
return false;
}
for (int x = 0; x < length; x += 2) {
*(data + x) = flash_read(LOW, here);
*(data + x + 1) = flash_read(HIGH, here);
Expand All @@ -369,12 +373,16 @@ void ESP8266AVRISP::flash_read_page(int length) {
*(data + length) = Resp_STK_OK;
_client.write((const uint8_t *)data, (size_t)(length + 1));
free(data);
return;
return true;
}

void ESP8266AVRISP::eeprom_read_page(int length) {
bool ESP8266AVRISP::eeprom_read_page(int length) {
// here again we have a word address
uint8_t *data = (uint8_t *) malloc(length + 1);
if (!data)
{
return false;
}
int start = here * 2;
for (int x = 0; x < length; x++) {
int addr = start + x;
Expand All @@ -384,7 +392,7 @@ void ESP8266AVRISP::eeprom_read_page(int length) {
*(data + length) = Resp_STK_OK;
_client.write((const uint8_t *)data, (size_t)(length + 1));
free(data);
return;
return true;
}

void ESP8266AVRISP::read_page() {
Expand Down
4 changes: 2 additions & 2 deletions libraries/ESP8266AVRISP/src/ESP8266AVRISP.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ class ESP8266AVRISP {
void commit(int addr);
void program_page();
uint8_t flash_read(uint8_t hilo, int addr);
void flash_read_page(int length);
void eeprom_read_page(int length);
bool flash_read_page(int length);
bool eeprom_read_page(int length);
void read_page();
void read_signature();

Expand Down
4 changes: 4 additions & 0 deletions libraries/ESP8266WiFi/src/BearSSLHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,10 @@ namespace brssl {
case BR_KEYTYPE_EC:
ek = br_skey_decoder_get_ec(dc.get());
sk = (private_key*)malloc(sizeof * sk);
if (!sk)
{
return nullptr;
}
sk->key_type = BR_KEYTYPE_EC;
sk->key.ec.curve = ek->curve;
sk->key.ec.x = (uint8_t*)malloc(ek->xlen);
Expand Down