Skip to content

Commit 6617ecc

Browse files
committed
[call_center] fix overflowing the per-agent array of skills
As the array of skills is pre-allocated inside the agent struct, be sure you do not overflow it when populating the agent's skills (from DB). Also, the logstate/logged_in value for an agent is read from DB or MI and it must be forced to 0/1 values, as it is later used as index. Yet another overflow fixed here.
1 parent 54b03a1 commit 6617ecc

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

modules/call_center/call_center.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,6 +1873,7 @@ static mi_response_t *mi_agent_login(const mi_params_t *params,
18731873

18741874
if (get_mi_int_param(params, "state", &logged_in) < 0)
18751875
return init_mi_param_error();
1876+
logged_in = logged_in ? 1 : 0;
18761877

18771878
/* block access to data */
18781879
lock_get( data->lock );

modules/call_center/cc_data.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ int add_cc_agent( struct cc_data *data, str *id, struct media_info *media,
522522

523523
/* is the agent a new one? - search by ID */
524524
agent = get_agent_by_name( data, id, &prev_agent);
525+
logstate = logstate ? 1 : 0;
525526

526527
if (agent==NULL) {
527528
/* new agent -> create and populate one */
@@ -572,18 +573,27 @@ int add_cc_agent( struct cc_data *data, str *id, struct media_info *media,
572573
if (skills && skills->len) {
573574
p = skills->s;
574575
while (p) {
576+
if (agent->no_skills==MAX_SKILLS_PER_AGENT) {
577+
LM_WARN("too many skills (%d) for the agent <%.*s>, "
578+
"discarding <%.*s>\n",
579+
agent->no_skills, agent->id.len, agent->id.s,
580+
(int)(skills->s+skills->len-p), p);
581+
break;
582+
}
575583
skill.s = p;
576584
p = q_memchr(skill.s, ',', skills->s+skills->len-skill.s);
577585
skill.len = p?(p-skill.s):(skills->s+skills->len-skill.s);
578586
trim(&skill);
579587
if (skill.len) {
580588
skill_id = get_skill_id(data,&skill);
581589
if (skill_id==0) {
582-
LM_ERR("cannot get skill id\n");
583-
goto error;
590+
LM_WARN("unknown skill <%.*s> for the agent <%.*s>,"
591+
"discarding\n",
592+
skill.len, skill.s, agent->id.len, agent->id.s);
593+
} else {
594+
n = agent->no_skills++;
595+
agent->skills[n] = skill_id;
584596
}
585-
n = agent->no_skills++;
586-
agent->skills[n] = skill_id;
587597
}
588598
if(p)
589599
p++;

modules/call_center/cc_data.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ struct cc_flow {
8282
};
8383

8484

85-
#define MAX_SKILLS_PER_AGENT 32
85+
#define MAX_SKILLS_PER_AGENT 64
8686

8787
typedef enum {
8888
CC_AGENT_FREE,

0 commit comments

Comments
 (0)