Skip to content

Commit

Permalink
[call_center] fix overflowing the per-agent array of skills
Browse files Browse the repository at this point in the history
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.

(cherry picked from commit 6617ecc)
  • Loading branch information
bogdan-iancu committed May 4, 2023
1 parent 308d17e commit 9419b3c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions modules/call_center/call_center.c
Original file line number Diff line number Diff line change
Expand Up @@ -1873,6 +1873,7 @@ static mi_response_t *mi_agent_login(const mi_params_t *params,

if (get_mi_int_param(params, "state", &logged_in) < 0)
return init_mi_param_error();
logged_in = logged_in ? 1 : 0;

/* block access to data */
lock_get( data->lock );
Expand Down
18 changes: 14 additions & 4 deletions modules/call_center/cc_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ int add_cc_agent( struct cc_data *data, str *id, struct media_info *media,

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

if (agent==NULL) {
/* new agent -> create and populate one */
Expand Down Expand Up @@ -572,18 +573,27 @@ int add_cc_agent( struct cc_data *data, str *id, struct media_info *media,
if (skills && skills->len) {
p = skills->s;
while (p) {
if (agent->no_skills==MAX_SKILLS_PER_AGENT) {
LM_WARN("too many skills (%d) for the agent <%.*s>, "
"discarding <%.*s>\n",
agent->no_skills, agent->id.len, agent->id.s,
(int)(skills->s+skills->len-p), p);
break;
}
skill.s = p;
p = q_memchr(skill.s, ',', skills->s+skills->len-skill.s);
skill.len = p?(p-skill.s):(skills->s+skills->len-skill.s);
trim(&skill);
if (skill.len) {
skill_id = get_skill_id(data,&skill);
if (skill_id==0) {
LM_ERR("cannot get skill id\n");
goto error;
LM_WARN("unknown skill <%.*s> for the agent <%.*s>,"
"discarding\n",
skill.len, skill.s, agent->id.len, agent->id.s);
} else {
n = agent->no_skills++;
agent->skills[n] = skill_id;
}
n = agent->no_skills++;
agent->skills[n] = skill_id;
}
if(p)
p++;
Expand Down
2 changes: 1 addition & 1 deletion modules/call_center/cc_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ struct cc_flow {
};


#define MAX_SKILLS_PER_AGENT 32
#define MAX_SKILLS_PER_AGENT 64

typedef enum {
CC_AGENT_FREE,
Expand Down

0 comments on commit 9419b3c

Please sign in to comment.