From ad2b5d7635da152c9b85a71a1d6a77f4184efa34 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Fri, 14 Jun 2019 21:52:35 +0200 Subject: [PATCH] pcsc: fix uninitialized variable and class dtor --- srsue/hdr/stack/upper/pcsc_usim.h | 44 +++++++++++++++--------------- srsue/src/stack/upper/pcsc_usim.cc | 11 +++++--- 2 files changed, 29 insertions(+), 26 deletions(-) diff --git a/srsue/hdr/stack/upper/pcsc_usim.h b/srsue/hdr/stack/upper/pcsc_usim.h index 9c6b2fecc..123a4de56 100644 --- a/srsue/hdr/stack/upper/pcsc_usim.h +++ b/srsue/hdr/stack/upper/pcsc_usim.h @@ -107,36 +107,36 @@ public: private: - srslte::log *log; + srslte::log* log = nullptr; // User data - uint8_t amf[2]; // 3GPP 33.102 v10.0.0 Annex H - uint8_t op[16]; - uint64_t imsi; - uint64_t imei; - uint8_t k[16]; + uint8_t amf[2] = {}; // 3GPP 33.102 v10.0.0 Annex H + uint8_t op[16] = {}; + uint64_t imsi = 0; + uint64_t imei = 0; + uint8_t k[16] = {}; std::string imsi_str; std::string imei_str; - uint32_t mnc_length; + uint32_t mnc_length = 0; // Security variables - uint8_t rand[AKA_RAND_LEN]; - uint8_t ck[CK_LEN]; - uint8_t ik[IK_LEN]; - uint8_t ak[AK_LEN]; - uint8_t mac[MAC_LEN]; - uint8_t autn[AKA_AUTN_LEN]; - uint8_t k_asme[KEY_LEN]; - uint8_t nh[KEY_LEN]; - uint8_t k_enb[KEY_LEN]; - uint8_t k_enb_star[KEY_LEN]; - uint8_t auts[AKA_AUTS_LEN]; - - uint32_t current_ncc; - - bool initiated; + uint8_t rand[AKA_RAND_LEN] = {}; + uint8_t ck[CK_LEN] = {}; + uint8_t ik[IK_LEN] = {}; + uint8_t ak[AK_LEN] = {}; + uint8_t mac[MAC_LEN] = {}; + uint8_t autn[AKA_AUTN_LEN] = {}; + uint8_t k_asme[KEY_LEN] = {}; + uint8_t nh[KEY_LEN] = {}; + uint8_t k_enb[KEY_LEN] = {}; + uint8_t k_enb_star[KEY_LEN] = {}; + uint8_t auts[AKA_AUTS_LEN] = {}; + + uint32_t current_ncc = 0; + + bool initiated = false; // Smartcard sub-class which is a port of the PC/SC smartcard implementation // of WPA Supplicant written by Jouni Malinen and licensed under BSD diff --git a/srsue/src/stack/upper/pcsc_usim.cc b/srsue/src/stack/upper/pcsc_usim.cc index 3ebbb55f8..05e5bf8cd 100644 --- a/srsue/src/stack/upper/pcsc_usim.cc +++ b/srsue/src/stack/upper/pcsc_usim.cc @@ -25,14 +25,14 @@ #include "srsue/hdr/stack/upper/pcsc_usim.h" #include "string.h" -#define CHECK_SIM_PIN 1 +#define CHECK_SIM_PIN 0 using namespace srslte; using namespace asn1::rrc; namespace srsue { -pcsc_usim::pcsc_usim() : initiated(false) +pcsc_usim::pcsc_usim() { bzero(ck, CK_LEN); bzero(ik, IK_LEN); @@ -41,7 +41,10 @@ pcsc_usim::pcsc_usim() : initiated(false) pcsc_usim::~pcsc_usim() { - sc.deinit(); + if (initiated) { + sc.deinit(); + initiated = false; + } } int pcsc_usim::init(usim_args_t *args, srslte::log *log_) @@ -407,7 +410,7 @@ int pcsc_usim::scard::init(usim_args_t *args, srslte::log *log_) return ret_value; } - unsigned long len; + unsigned long len = 0; ret = SCardListReaders(scard_context, NULL, NULL, &len); if (ret != SCARD_S_SUCCESS) { log->error("SCardListReaders(): %s\n", pcsc_stringify_error(ret));