Skip to content

Commit

Permalink
fraud_detection: Fix a seq calls computation bug
Browse files Browse the repository at this point in the history
The sequential calls of a user should be counted using the dialed
numbers, NOT the matched fraud rule prefixes (which are almost always
shorter).

Reported by Benjamin Pasquet from OpenIP
  • Loading branch information
liviuchircu committed Sep 23, 2019
1 parent 118a352 commit 3ac00a6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
15 changes: 7 additions & 8 deletions modules/fraud_detection/fraud_detection.c
Expand Up @@ -354,18 +354,17 @@ static int check_fraud(struct sip_msg *msg, char *_user, char *_number, char *_p
/* Update the stats */

lock_get(frd_seq_calls_lock);
if (se->stats.last_called_prefix.len == matched_len &&
memcmp(se->stats.last_called_prefix.s, number.s, matched_len) == 0) {

if (!str_strcmp(&se->stats.last_dial, &number)) {
/* We have called the same number last time */
++se->stats.seq_calls;
}
else {
if (shm_str_extend(&se->stats.last_called_prefix, matched_len) != 0) {
} else {
if (shm_str_sync(&se->stats.last_dial, &number) != 0) {
lock_release(frd_seq_calls_lock);
LM_ERR("oom\n");
return rc_error;
rc = rc_error;
goto out;
}
memcpy(se->stats.last_called_prefix.s, number.s, matched_len);

se->stats.seq_calls = 1;
}
lock_release(frd_seq_calls_lock);
Expand Down
7 changes: 5 additions & 2 deletions modules/fraud_detection/frd_stats.c
Expand Up @@ -164,8 +164,11 @@ int stats_exist(str user, str prefix)

static void destroy_stats_entry(void *e)
{
lock_destroy( &((frd_stats_entry_t*)e)->lock );
shm_free(e);
frd_stats_entry_t *se = (frd_stats_entry_t *)e;

lock_destroy(&se->lock);
shm_free(se->stats.last_dial.s);
shm_free(se);
}

static void destroy_users(void *u)
Expand Down
2 changes: 1 addition & 1 deletion modules/fraud_detection/frd_stats.h
Expand Up @@ -40,7 +40,7 @@ typedef struct {
unsigned int total_calls;
unsigned int concurrent_calls;

str last_called_prefix;
str last_dial;
unsigned int seq_calls;

unsigned int last_matched_rule;
Expand Down

0 comments on commit 3ac00a6

Please sign in to comment.