Skip to content

Commit 1abf600

Browse files
author
Teppo Järvelin
committed
Cellular: fix calls to ATHandler::read_string(...) give correct size
ATHandler::read_string(...) buffer size param was changed a long time ago to include also NULL. Some calls still gave wrong size after this change.
1 parent 46603f8 commit 1abf600

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
@@ -394,9 +394,9 @@ bool AT_CellularContext::get_context()
394394
cid_max = cid;
395395
}
396396
char pdp_type_from_context[10];
397-
int pdp_type_len = _at.read_string(pdp_type_from_context, sizeof(pdp_type_from_context) - 1);
397+
int pdp_type_len = _at.read_string(pdp_type_from_context, sizeof(pdp_type_from_context));
398398
if (pdp_type_len > 0) {
399-
apn_len = _at.read_string(apn, sizeof(apn) - 1);
399+
apn_len = _at.read_string(apn, sizeof(apn));
400400
if (apn_len >= 0) {
401401
if (_apn && (strcmp(apn, _apn) != 0)) {
402402
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)