Skip to content

Commit 13880dc

Browse files
authored
Merge pull request #10465 from jarvte/fix_imsi_length
Cellular: fix calls to ATHandler::read_string(...) give correct size
2 parents 4da21c0 + 1abf600 commit 13880dc

File tree

4 files changed

+8
-11
lines changed

4 files changed

+8
-11
lines changed

features/cellular/framework/AT/AT_CellularContext.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,9 @@ bool AT_CellularContext::get_context()
393393
cid_max = cid;
394394
}
395395
char pdp_type_from_context[10];
396-
int pdp_type_len = _at.read_string(pdp_type_from_context, sizeof(pdp_type_from_context) - 1);
396+
int pdp_type_len = _at.read_string(pdp_type_from_context, sizeof(pdp_type_from_context));
397397
if (pdp_type_len > 0) {
398-
apn_len = _at.read_string(apn, sizeof(apn) - 1);
398+
apn_len = _at.read_string(apn, sizeof(apn));
399399
if (apn_len >= 0) {
400400
if (_apn && (strcmp(apn, _apn) != 0)) {
401401
continue;

features/cellular/framework/AT/AT_CellularInformation.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ nsapi_error_t AT_CellularInformation::get_info(const char *cmd, char *buf, size_
7878
_at.cmd_stop();
7979
_at.set_delimiter(0);
8080
_at.resp_start();
81-
_at.read_string(buf, buf_size - 1);
81+
_at.read_string(buf, buf_size);
8282
_at.resp_stop();
8383
_at.set_default_delimiter();
8484
return _at.unlock_return_error();
@@ -93,10 +93,7 @@ nsapi_error_t AT_CellularInformation::get_imsi(char *imsi, size_t buf_size)
9393
_at.cmd_start("AT+CIMI");
9494
_at.cmd_stop();
9595
_at.resp_start();
96-
int len = _at.read_string(imsi, MAX_IMSI_LENGTH);
97-
if (len > 0) {
98-
imsi[len] = '\0';
99-
}
96+
_at.read_string(imsi, MAX_IMSI_LENGTH + 1);
10097
_at.resp_stop();
10198
return _at.unlock_return_error();
10299
}

features/cellular/framework/AT/AT_CellularStack.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const char *AT_CellularStack::get_ip_address()
7070

7171
_at.skip_param();
7272

73-
int len = _at.read_string(_ip, NSAPI_IPv4_SIZE - 1);
73+
int len = _at.read_string(_ip, NSAPI_IPv4_SIZE);
7474
if (len == -1) {
7575
_ip[0] = '\0';
7676
_at.resp_stop();
@@ -81,7 +81,7 @@ const char *AT_CellularStack::get_ip_address()
8181

8282
// in case stack type is not IPV4 only, try to look also for IPV6 address
8383
if (_stack_type != IPV4_STACK) {
84-
(void)_at.read_string(_ip, PDP_IPV6_SIZE - 1);
84+
(void)_at.read_string(_ip, PDP_IPV6_SIZE);
8585
}
8686
}
8787

features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularStack.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ const char *UBLOX_AT_CellularStack::get_ip_address()
444444
if (_at.info_resp()) {
445445
_at.skip_param();
446446
_at.skip_param();
447-
int len = _at.read_string(_ip, NSAPI_IPv4_SIZE - 1);
447+
int len = _at.read_string(_ip, NSAPI_IPv4_SIZE);
448448
if (len == -1) {
449449
_ip[0] = '\0';
450450
_at.unlock();
@@ -454,7 +454,7 @@ const char *UBLOX_AT_CellularStack::get_ip_address()
454454

455455
// in case stack type is not IPV4 only, try to look also for IPV6 address
456456
if (_stack_type != IPV4_STACK) {
457-
len = _at.read_string(_ip, PDP_IPV6_SIZE - 1);
457+
len = _at.read_string(_ip, PDP_IPV6_SIZE);
458458
}
459459
}
460460
_at.resp_stop();

0 commit comments

Comments
 (0)