Skip to content

Commit 97709f5

Browse files
Teppo JärvelinAri Parkkila
authored andcommitted
Cellular: fix possible crash in state machine
_sim_pin was changed to pointer from array and length was checked with strlen. If _sim_pin was null it caused crash. Fix by checking _sim_pin against NULL. Power class could have been called without checking if power is NULL. Fix by checking that power class is not null. Fix state machine to return correct states when queried.
1 parent fa5d0fc commit 97709f5

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

features/cellular/framework/device/CellularStateMachine.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ bool CellularStateMachine::open_sim()
153153
}
154154

155155
if (state == CellularDevice::SimStatePinNeeded) {
156-
if (strlen(_sim_pin)) {
156+
if (_sim_pin) {
157157
tr_info("Entering PIN to open SIM");
158158
_cb_data.error = _cellularDevice.set_pin(_sim_pin);
159159
if (_cb_data.error) {
@@ -428,13 +428,13 @@ void CellularStateMachine::state_sim_pin()
428428
}
429429

430430
if (_network->is_active_context()) { // check if context was already activated
431-
tr_debug("ACTIVE CONTEXT FOUND, skip registering.");
431+
tr_debug("Active context found.");
432432
_network_status |= ACTIVE_PDP_CONTEXT;
433433
}
434434
CellularNetwork::AttachStatus status; // check if modem is already attached to a network
435435
if (_network->get_attach(status) == NSAPI_ERROR_OK && status == CellularNetwork::Attached) {
436436
_network_status |= ATTACHED_TO_NETWORK;
437-
tr_debug("DEVICE IS ALREADY ATTACHED TO NETWORK, skip registering and attach.");
437+
tr_debug("Cellular already attached.");
438438
}
439439
if (_plmn) {
440440
enter_to_state(STATE_MANUAL_REGISTERING_NETWORK);

features/cellular/framework/device/CellularStateMachine.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class CellularStateMachine {
4242
// friend of CellularDevice so that it's the only way to close/delete this class.
4343
friend class CellularDevice;
4444
friend class AT_CellularDevice;
45+
friend class UT_CellularStateMachine; // for unit tests
4546
/** Constructor
4647
*
4748
* @param device reference to CellularDevice
@@ -98,7 +99,7 @@ class CellularStateMachine {
9899
* @param timeout timeout array using seconds
99100
* @param array_len length of the array
100101
*/
101-
void set_retry_timeout_array(uint16_t timeout[], int array_len);
102+
void set_retry_timeout_array(uint16_t *timeout, int array_len);
102103

103104
/** Sets the operator plmn which is used when registering to a network specified by plmn. If plmn is not set then automatic
104105
* registering is used when registering to a cellular network. Does not start any operations.

0 commit comments

Comments
 (0)