Fixed bug when copying apn, username and password.

pull/6082/head
Teppo Järvelin 2018-02-23 08:52:20 +02:00 committed by Ari Parkkila
parent 9016ed5ed8
commit 0c49b669b4
1 changed files with 4 additions and 4 deletions

View File

@ -80,7 +80,7 @@ nsapi_error_t AT_CellularNetwork::set_credentials(const char *apn,
if (apn && (len = strlen(apn)) > 0) { if (apn && (len = strlen(apn)) > 0) {
_apn = (char*)malloc(len*sizeof(char)+1); _apn = (char*)malloc(len*sizeof(char)+1);
if (_apn) { if (_apn) {
memcpy(_apn, apn, len); memcpy(_apn, apn, len+1);
} else { } else {
return NSAPI_ERROR_NO_MEMORY; return NSAPI_ERROR_NO_MEMORY;
} }
@ -89,7 +89,7 @@ nsapi_error_t AT_CellularNetwork::set_credentials(const char *apn,
if (username && (len = strlen(username)) > 0) { if (username && (len = strlen(username)) > 0) {
_uname = (char*)malloc(len*sizeof(char)+1); _uname = (char*)malloc(len*sizeof(char)+1);
if (_uname) { if (_uname) {
memcpy(_uname, username, len); memcpy(_uname, username, len+1);
} else { } else {
return NSAPI_ERROR_NO_MEMORY; return NSAPI_ERROR_NO_MEMORY;
} }
@ -98,7 +98,7 @@ nsapi_error_t AT_CellularNetwork::set_credentials(const char *apn,
if (password && (len = strlen(password)) > 0) { if (password && (len = strlen(password)) > 0) {
_pwd = (char*)malloc(len*sizeof(char)+1); _pwd = (char*)malloc(len*sizeof(char)+1);
if (_pwd) { if (_pwd) {
memcpy(_pwd, password, len); memcpy(_pwd, password, len+1);
} else { } else {
return NSAPI_ERROR_NO_MEMORY; return NSAPI_ERROR_NO_MEMORY;
} }
@ -433,7 +433,7 @@ bool AT_CellularNetwork::get_context(nsapi_ip_stack_t requested_stack)
if (apn_len > 0 && !_apn) { if (apn_len > 0 && !_apn) {
_apn = (char*)malloc(apn_len*sizeof(char)+1); _apn = (char*)malloc(apn_len*sizeof(char)+1);
if (_apn) { if (_apn) {
memcpy(_apn, apn, apn_len); memcpy(_apn, apn, apn_len+1);
} else { } else {
return false; return false;
} }