check return value of gsm48_multirate_config()

Check the return value of gsm48_multirate_config() in function
lchan_set_single_amr_mode(). This prevents an invalid AMR mode
from being configured for a logical channel.

Because the VTY parsier limits the AMR mode range to 0-7 this
is just a theoretical issue. However, this fact is beyond the
understanding of a static code analyzer, and the absence of
error handling was indeed setting a bad example.

Change-Id: I61153a44e8b7a38332bf38718397be9b339d5f25
Related: CID#188940
This commit is contained in:
Stefan Sperling 2018-11-06 14:24:56 +01:00 committed by Harald Welte
parent 42bd128ffc
commit 42f59d52f8
1 changed files with 21 additions and 6 deletions

View File

@ -4493,10 +4493,11 @@ DEFUN(pdch_act, pdch_act_cmd,
}
/* configure the lchan for a single AMR mode (as specified) */
static int lchan_set_single_amr_mode(struct gsm_lchan *lchan, uint8_t amr_mode)
static int lchan_set_single_amr_mode(struct vty *vty, struct gsm_lchan *lchan, uint8_t amr_mode)
{
struct amr_multirate_conf mr;
struct gsm48_multi_rate_conf *mr_conf;
int rc, vty_rc = CMD_SUCCESS;
mr_conf = (struct gsm48_multi_rate_conf *) &mr.gsm48_ie;
if (amr_mode > 7)
@ -4515,10 +4516,22 @@ static int lchan_set_single_amr_mode(struct gsm_lchan *lchan, uint8_t amr_mode)
/* encode this configuration into the lchan for both uplink and
* downlink direction */
gsm48_multirate_config(lchan->mr_ms_lv, mr_conf, mr.ms_mode, mr.num_modes);
gsm48_multirate_config(lchan->mr_bts_lv, mr_conf, mr.bts_mode, mr.num_modes);
rc = gsm48_multirate_config(lchan->mr_ms_lv, mr_conf, mr.ms_mode, mr.num_modes);
if (rc != 0) {
vty_out(vty,
"Invalid AMR multirate configuration (%s, amr mode %d, ms) - check parameters%s",
gsm_lchant_name(lchan->type), amr_mode, VTY_NEWLINE);
vty_rc = CMD_WARNING;
}
rc = gsm48_multirate_config(lchan->mr_bts_lv, mr_conf, mr.bts_mode, mr.num_modes);
if (rc != 0) {
vty_out(vty,
"Invalid AMR multirate configuration (%s, amr mode %d, bts) - check parameters%s",
gsm_lchant_name(lchan->type), amr_mode, VTY_NEWLINE);
vty_rc = CMD_WARNING;
}
return 0;
return vty_rc;
}
/* Debug/Measurement command to activate a given logical channel
@ -4574,14 +4587,16 @@ DEFUN(lchan_act, lchan_act_cmd,
else if (!strcmp(codec_str, "efr"))
lchan->tch_mode = GSM48_CMODE_SPEECH_EFR;
else if (!strcmp(codec_str, "amr")) {
int amr_mode;
int amr_mode, vty_rc;
if (argc < 7) {
vty_out(vty, "%% AMR requires specification of AMR mode%s", VTY_NEWLINE);
return CMD_WARNING;
}
amr_mode = atoi(argv[6]);
lchan->tch_mode = GSM48_CMODE_SPEECH_AMR;
lchan_set_single_amr_mode(lchan, amr_mode);
vty_rc = lchan_set_single_amr_mode(vty, lchan, amr_mode);
if (vty_rc != CMD_SUCCESS)
return vty_rc;
}
vty_out(vty, "%% activating lchan %s%s", gsm_lchan_name(lchan), VTY_NEWLINE);
rsl_tx_chan_activ(lchan, RSL_ACT_TYPE_INITIAL, 0);