Misc (re #2504): Fix pjsua app: avoid using my_atoi() on non-NULL-terminated strings.

This commit is contained in:
Nanang Izzuddin 2020-11-13 17:19:16 +07:00
parent 603de9bbb3
commit 634e7cf3d8
3 changed files with 13 additions and 8 deletions

View File

@ -819,7 +819,7 @@ static pj_status_t cmd_del_account(pj_cli_cmd_val *cval)
char out_str[64];
unsigned str_len;
int i = my_atoi(cval->argv[1].ptr);
int i = my_atoi2(&cval->argv[1]);
if (!pjsua_acc_is_valid(i)) {
pj_ansi_snprintf(out_str, sizeof(out_str),
@ -860,7 +860,7 @@ static pj_status_t cmd_unreg_account()
/* Select account to be used for sending outgoing request */
static pj_status_t cmd_next_account(pj_cli_cmd_val *cval)
{
int i = my_atoi(cval->argv[1].ptr);
int i = my_atoi2(&cval->argv[1]);
if (pjsua_acc_is_valid(i)) {
pjsua_acc_set_default(i);
PJ_LOG(3,(THIS_FILE, "Current account changed to %d", i));
@ -988,7 +988,7 @@ static pj_status_t cmd_add_buddy(pj_cli_cmd_val *cval)
/* Delete buddy */
static pj_status_t cmd_del_buddy(pj_cli_cmd_val *cval)
{
int i = my_atoi(cval->argv[1].ptr) - 1;
int i = my_atoi2(&cval->argv[1]) - 1;
char out_str[80];
if (!pjsua_buddy_is_valid(i)) {
@ -1798,8 +1798,6 @@ static pj_status_t cmd_transfer_replace_call(pj_cli_cmd_val *cval)
pj_str_t STR_FALSE = { "false", 5 };
pjsua_call_id ids[PJSUA_MAX_CALLS];
pjsua_msg_data msg_data_;
char buf[8] = {0};
pj_str_t tmp = pj_str(buf);
unsigned count;
static const pj_str_t err_invalid_num =
{"Invalid destination call number\n", 32 };
@ -1815,8 +1813,7 @@ static pj_status_t cmd_transfer_replace_call(pj_cli_cmd_val *cval)
return PJ_SUCCESS;
}
pj_strncpy_with_null(&tmp, &cval->argv[1], sizeof(buf));
dst_call = my_atoi(tmp.ptr);
dst_call = my_atoi2(&cval->argv[1]);
/* Check if call is still there. */
if (call != current_call) {

View File

@ -45,8 +45,15 @@ pjsua_msg_data msg_data;
int my_atoi(const char *cs)
{
pj_str_t s;
pj_cstr(&s, cs);
return my_atoi2(&s);
}
int my_atoi2(const pj_str_t *str)
{
const char *cs = str->ptr;
pj_str_t s = *str;
if (cs[0] == '-') {
s.ptr++; s.slen--;
return 0 - (int)pj_strtoul(&s);

View File

@ -169,6 +169,7 @@ extern pjsua_msg_data msg_data;
extern pj_bool_t app_running;
int my_atoi(const char *cs);
int my_atoi2(const pj_str_t *s);
pj_bool_t find_next_call(void);
pj_bool_t find_prev_call(void);
void send_request(char *cstr_method, const pj_str_t *dst_uri);