From 24cb0334eb73f70e442267c2aab13ef33a8ea20d Mon Sep 17 00:00:00 2001 From: int_szyk Date: Mon, 23 Sep 2019 10:19:22 +0200 Subject: [PATCH 1/4] esp8266-driver: fix variables init in constructor. Fixes Coverity issue about not initialized members. --- components/wifi/esp8266-driver/ESP8266Interface.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/components/wifi/esp8266-driver/ESP8266Interface.cpp b/components/wifi/esp8266-driver/ESP8266Interface.cpp index 37fd282185..3ae1832468 100644 --- a/components/wifi/esp8266-driver/ESP8266Interface.cpp +++ b/components/wifi/esp8266-driver/ESP8266Interface.cpp @@ -67,11 +67,13 @@ ESP8266Interface::ESP8266Interface() _if_connected(_cmutex), _initialized(false), _connect_retval(NSAPI_ERROR_OK), + _disconnect_retval(NSAPI_ERROR_OK), _conn_stat(NSAPI_STATUS_DISCONNECTED), _conn_stat_cb(NULL), _global_event_queue(mbed_event_queue()), // Needs to be set before attaching event() to SIGIO _oob_event_id(0), _connect_event_id(0), + _disconnect_event_id(0), _software_conn_stat(IFACE_STATUS_DISCONNECTED) { memset(_cbs, 0, sizeof(_cbs)); @@ -104,11 +106,14 @@ ESP8266Interface::ESP8266Interface(PinName tx, PinName rx, bool debug, PinName r _if_connected(_cmutex), _initialized(false), _connect_retval(NSAPI_ERROR_OK), + _disconnect_retval(NSAPI_ERROR_OK), _conn_stat(NSAPI_STATUS_DISCONNECTED), _conn_stat_cb(NULL), _global_event_queue(mbed_event_queue()), // Needs to be set before attaching event() to SIGIO _oob_event_id(0), - _connect_event_id(0) + _connect_event_id(0), + _disconnect_event_id(0), + _software_conn_stat(IFACE_STATUS_DISCONNECTED) { memset(_cbs, 0, sizeof(_cbs)); memset(ap_ssid, 0, sizeof(ap_ssid)); From 081183c11edd1e1dcbad6c109d3a0498a9987772 Mon Sep 17 00:00:00 2001 From: int_szyk Date: Mon, 23 Sep 2019 12:02:31 +0200 Subject: [PATCH 2/4] NFC-URI: fix passing null pointer to a function. Fixes Coverity issue about passing nullptr to memcpy. --- features/nfc/source/nfc/ndef/common/URI.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/features/nfc/source/nfc/ndef/common/URI.cpp b/features/nfc/source/nfc/ndef/common/URI.cpp index a392868843..4761251ce1 100644 --- a/features/nfc/source/nfc/ndef/common/URI.cpp +++ b/features/nfc/source/nfc/ndef/common/URI.cpp @@ -40,15 +40,19 @@ URI::URI(uri_identifier_code_t id, const Span &uri_field) : _uri(uri_field.size() ? new uint8_t[uri_id_code_size + uri_field.size()] : NULL), _uri_size(uri_id_code_size + uri_field.size()) { - _uri[uri_id_index] = id; - memcpy(_uri + uri_field_index, uri_field.data(), uri_field.size()); + if (_uri) { + _uri[uri_id_index] = id; + memcpy(_uri + uri_field_index, uri_field.data(), uri_field.size()); + } } URI::URI(const URI &other) : _uri(other._uri ? new uint8_t[other._uri_size] : NULL), _uri_size(other._uri_size) { - memcpy(_uri, other._uri, other._uri_size); + if (_uri) { + memcpy(_uri, other._uri, other._uri_size); + } } URI::~URI() From d83cbb8766f524f929fe182bf52a69d5fefcb75b Mon Sep 17 00:00:00 2001 From: int_szyk Date: Mon, 23 Sep 2019 12:10:13 +0200 Subject: [PATCH 3/4] NFC-Text: fix passing null pointer to a function. Fixes Coverity issue about passing nullptr to memcpy. --- features/nfc/source/nfc/ndef/common/Text.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/features/nfc/source/nfc/ndef/common/Text.cpp b/features/nfc/source/nfc/ndef/common/Text.cpp index b4d18e173b..6ea37be143 100644 --- a/features/nfc/source/nfc/ndef/common/Text.cpp +++ b/features/nfc/source/nfc/ndef/common/Text.cpp @@ -41,7 +41,9 @@ Text::Text(const Text &other) : _text_record(other._text_record ? new uint8_t[other._text_record_size] : NULL), _text_record_size(other._text_record_size) { - memcpy(_text_record, other._text_record, _text_record_size); + if (_text_record) { + memcpy(_text_record, other._text_record, _text_record_size); + } } Text::Text( From 62d07707c9b4be690e2aea5b80b9b6bd8b58bc9d Mon Sep 17 00:00:00 2001 From: int_szyk Date: Mon, 23 Sep 2019 12:27:49 +0200 Subject: [PATCH 4/4] NFCEEPROM: fix _ndef_buffer_reader init in ctor. Fixes Coverity issue about not initialized members. --- features/nfc/source/nfc/NFCEEPROM.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/features/nfc/source/nfc/NFCEEPROM.cpp b/features/nfc/source/nfc/NFCEEPROM.cpp index 01f2715a85..1872376817 100644 --- a/features/nfc/source/nfc/NFCEEPROM.cpp +++ b/features/nfc/source/nfc/NFCEEPROM.cpp @@ -21,7 +21,8 @@ using namespace mbed; using namespace mbed::nfc; NFCEEPROM::NFCEEPROM(NFCEEPROMDriver *driver, events::EventQueue *queue, const Span &ndef_buffer) : NFCTarget(ndef_buffer), - _delegate(NULL), _driver(driver), _event_queue(queue), _initialized(false), _current_op(nfc_eeprom_idle), _ndef_buffer_read_sz(0), _eeprom_address(0), _operation_result(NFC_ERR_UNKNOWN) + _delegate(NULL), _driver(driver), _event_queue(queue), _initialized(false), _current_op(nfc_eeprom_idle), _ndef_buffer_read_sz(0), _eeprom_address(0), + _operation_result(NFC_ERR_UNKNOWN), _ndef_buffer_reader{nullptr, 0, nullptr} { _driver->set_delegate(this); _driver->set_event_queue(queue);