diff options
author | Anil Hiranniah <anil.hiranniah@nxp.com> | 2020-02-19 18:12:27 +0530 |
---|---|---|
committer | George Chang <georgekgchang@google.com> | 2020-03-24 11:20:03 +0000 |
commit | 93b6583070ce0617faf640eb0aaba9b7ae8c9329 (patch) | |
tree | 9e431acb822ec191eb4a34bc5791d6183efbcbd3 | |
parent | 770995ba77f814b3c4fc6399003d8dbd2d9d830f (diff) | |
download | secure_element-93b6583070ce0617faf640eb0aaba9b7ae8c9329.tar.gz |
Fix warnings from static analysis tools(se_hal)
1. DEADCODE
a. phNxpEse_api.cc: phNxpEse_openPrioSession()
tpm_enable is always 0. Removed relevant code.
b. LsLib.cpp: LSC_loadapplet()
Removed duplicate status check
2. RESOURCE_LEAK
a. LsClient.cpp: getLSScriptSourcePrefix()
b. LsClient.cpp: performLSDownload_thread()
Added corresponding fclose()
3. UNINITIALIZED Variables
Bug: 142626701
Test: Nfc-On/Off, Tag read, HCE, CE-eSE
Merged-In: I9484f80bd3f6d8e478836d358cbdeca82dd9158e
Change-Id: I9484f80bd3f6d8e478836d358cbdeca82dd9158e
-rw-r--r-- | libese-spi/p73/lib/phNxpEse_Api.cpp | 10 | ||||
-rw-r--r-- | libese-spi/p73/utils/config.cpp | 5 | ||||
-rwxr-xr-x | libese-spi/p73/utils/config.h | 1 | ||||
-rwxr-xr-x | libese-spi/src/adaptation/NfcAdaptation.cpp | 2 | ||||
-rwxr-xr-x | ls_client/src/LsClient.cpp | 12 | ||||
-rwxr-xr-x | ls_client/src/LsLib.cpp | 6 |
6 files changed, 19 insertions, 17 deletions
diff --git a/libese-spi/p73/lib/phNxpEse_Api.cpp b/libese-spi/p73/lib/phNxpEse_Api.cpp index 70070fd..6ffefcf 100644 --- a/libese-spi/p73/lib/phNxpEse_Api.cpp +++ b/libese-spi/p73/lib/phNxpEse_Api.cpp @@ -344,7 +344,7 @@ bool phNxpEse_isOpen() { return nxpese_ctxt.EseLibStatus != ESE_STATUS_CLOSE; } ESESTATUS phNxpEse_openPrioSession(phNxpEse_initParams initParams) { phPalEse_Config_t tPalConfig; ESESTATUS wConfigStatus = ESESTATUS_SUCCESS; - unsigned long int num = 0, tpm_enable = 0; + unsigned long int num = 0; ALOGE("phNxpEse_openPrioSession Enter"); #ifdef SPM_INTEGRATED @@ -481,14 +481,6 @@ ESESTATUS phNxpEse_openPrioSession(phNxpEse_initParams initParams) { } wConfigStatus = phPalEse_ioctl(phPalEse_e_EnablePollMode, nxpese_ctxt.pDevHandle, 1); - if (tpm_enable) { - wConfigStatus = phPalEse_ioctl(phPalEse_e_EnableThroughputMeasurement, - nxpese_ctxt.pDevHandle, 0); - if (wConfigStatus != ESESTATUS_SUCCESS) { - ALOGE("phPalEse_IoCtl Failed"); - goto clean_and_return; - } - } if (wConfigStatus != ESESTATUS_SUCCESS) { ALOGE("phPalEse_IoCtl Failed"); goto clean_and_return; diff --git a/libese-spi/p73/utils/config.cpp b/libese-spi/p73/utils/config.cpp index c304226..5983d59 100644 --- a/libese-spi/p73/utils/config.cpp +++ b/libese-spi/p73/utils/config.cpp @@ -41,6 +41,11 @@ bool parseBytesString(std::string in, std::vector<uint8_t>& out) { } // namespace +ConfigValue::ConfigValue() { + value_unsigned_ = 0; + type_ = UNSIGNED; +} + ConfigValue::Type ConfigValue::getType() const { return type_; } std::string ConfigValue::getString() const { diff --git a/libese-spi/p73/utils/config.h b/libese-spi/p73/utils/config.h index 90bbcc1..6a5ccb1 100755 --- a/libese-spi/p73/utils/config.h +++ b/libese-spi/p73/utils/config.h @@ -23,6 +23,7 @@ class ConfigValue { public: enum Type { UNSIGNED, STRING, BYTES }; + ConfigValue(); Type getType() const; std::string getString() const; unsigned getUnsigned() const; diff --git a/libese-spi/src/adaptation/NfcAdaptation.cpp b/libese-spi/src/adaptation/NfcAdaptation.cpp index 76ca268..55745f5 100755 --- a/libese-spi/src/adaptation/NfcAdaptation.cpp +++ b/libese-spi/src/adaptation/NfcAdaptation.cpp @@ -144,7 +144,7 @@ void ThreadMutex::unlock() { pthread_mutex_unlock(&mMutex); } ** Returns: none ** *******************************************************************************/ -NfcAdaptation::NfcAdaptation() {} +NfcAdaptation::NfcAdaptation() { mCurrentIoctlData = NULL; } /******************************************************************************* ** diff --git a/ls_client/src/LsClient.cpp b/ls_client/src/LsClient.cpp index f7a78de..4c874a9 100755 --- a/ls_client/src/LsClient.cpp +++ b/ls_client/src/LsClient.cpp @@ -130,6 +130,7 @@ void getLSScriptSourcePrefix(std::string& prefix) { if (c == ' ' || c == '\n' || c == '\r' || c == 0x00) break; prefix.push_back(c); } + fclose(fd); } else { ALOGD("%s Cannot open file %s\n", __func__, source_path); } @@ -332,13 +333,20 @@ void* performLSDownload_thread(__attribute__((unused)) void* data) { /*Read the script content to a local buffer*/ fseek(fIn, 0, SEEK_END); long lsBufSize = ftell(fIn); + if (lsBufSize < 0) { + ALOGE("%s Failed to get current value of position indicator\n", __func__); + fclose(fIn); + status = LSCSTATUS_FAILED; + break; + } rewind(fIn); if (lsHashInfo.lsRawScriptBuf == nullptr) { lsHashInfo.lsRawScriptBuf = (uint8_t*)phNxpEse_memalloc(lsBufSize + 1); } memset(lsHashInfo.lsRawScriptBuf, 0x00, (lsBufSize + 1)); - fread(lsHashInfo.lsRawScriptBuf, lsBufSize, 1, fIn); - + if (fread(lsHashInfo.lsRawScriptBuf, (size_t)lsBufSize, 1, fIn) != 1) + ALOGD_IF(ese_debug_enabled, "%s Failed to read file", __func__); + fclose(fIn); LSCSTATUS lsHashStatus = LSCSTATUS_FAILED; /*Get 20bye SHA1 of the script*/ diff --git a/ls_client/src/LsLib.cpp b/ls_client/src/LsLib.cpp index 82f64f0..87a7763 100755 --- a/ls_client/src/LsLib.cpp +++ b/ls_client/src/LsLib.cpp @@ -435,10 +435,6 @@ LSCSTATUS LSC_loadapplet(Lsc_ImageInfo_t* Os_info, LSCSTATUS status, while (!feof(Os_info->fp) && (Os_info->bytes_read < Os_info->fls_size)) { len_byte = 0; offset = 0; - /*Check if the certificate/ is verified or not*/ - if (status != LSCSTATUS_SUCCESS) { - goto exit; - } uint8_t temp_buf[1024]; memset(temp_buf, 0, sizeof(temp_buf)); @@ -572,7 +568,7 @@ LSCSTATUS LSC_Check_KeyIdentifier(Lsc_ImageInfo_t* Os_info, LSCSTATUS status, int32_t wNewLen) { static const char fn[] = "LSC_Check_KeyIdentifier"; status = LSCSTATUS_FAILED; - uint8_t read_buf[1024]; + uint8_t read_buf[1024] = {0}; uint16_t offset = 0, len_byte = 0; int32_t wLen; uint8_t certf_found = LSCSTATUS_FAILED; |