Skip to content

Commit 9cbcd9b

Browse files
committed
app_verify: Fix sign issues.
Use unsigned int for statistics since these will never be negative. Additionally, use unsigned int rather than char to prevent stats from wrapping. Additionally, use a single bit for yes/no settings.
1 parent 19cd862 commit 9cbcd9b

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ A utility to automate the installation, maintenance, and debugging of Asterisk/D
33

44
PhreakScript installs:
55

6-
- Asterisk 20.1.0 (latest LTS release of Asterisk)
6+
- Asterisk 20.2.1 (latest LTS release of Asterisk)
77
- DAHDI Linux 3.2.0 (with optional DAHDI install flag)
88
- DAHDI Tools 3.2.0 (with optional DAHDI install flag)
99
- many additional features and stability improvements

apps/app_verify.c

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -367,11 +367,11 @@ static char *app2 = "OutVerify";
367367
struct call_verify {
368368
ast_mutex_t lock;
369369
char name[AST_MAX_CONTEXT]; /*!< Name - Verify section */
370-
int in; /*!< Total number of incoming calls attempted to verify under this profile */
371-
int insuccess; /*!< Total number of incoming calls successfully passed verification */
372-
int out; /*!< Total number of outgoing calls attempted to out verify under this profile */
373-
int outsuccess; /*!< Total number of outgoing calls out-verified under this profile */
374-
int total_blacklisted; /*!< Total number of incoming calls that have been rejected due to blacklisting */
370+
unsigned int in; /*!< Total number of incoming calls attempted to verify under this profile */
371+
unsigned int insuccess; /*!< Total number of incoming calls successfully passed verification */
372+
unsigned int out; /*!< Total number of outgoing calls attempted to out verify under this profile */
373+
unsigned int outsuccess; /*!< Total number of outgoing calls out-verified under this profile */
374+
unsigned int total_blacklisted; /*!< Total number of incoming calls that have been rejected due to blacklisting */
375375
char verifymethod[PATH_MAX]; /*!< Algorithm to use for verification: direct or reverse */
376376
char requestmethod[PATH_MAX]; /*!< Request method: curl or enum */
377377
char verifyrequest[PATH_MAX]; /*!< Request URL or ENUM lookup */
@@ -387,16 +387,9 @@ struct call_verify {
387387
char token_remote_var[AST_MAX_CONTEXT]; /*!< Variable in which token may arrive */
388388
char setinvars[PATH_MAX]; /*!< Variables to set on incoming call */
389389
char setoutvars[PATH_MAX]; /*!< Variables to set on outgoing call */
390-
int sanitychecks; /*!< Whether or not to do sanity checks on the alleged calling number */
391-
int extendtrust; /*!< Whether to verify through/via calls */
392-
int allowdisathru; /*!< Whether to allow DISA thru calls */
393-
int allowpstnthru; /*!< Whether to allow PSTN thru calls */
394-
int allowtoken; /*!< Whether to allow verification tokens */
395-
int flagprivateip; /*!< Whether to flag private IP addresses as malicious */
396390
char successregex[PATH_MAX]; /*!< Regex to use for direct verification to determine success */
397391
char blacklist_endpoint[PATH_MAX]; /*!< Blacklist endpoint */
398392
float blacklist_threshold; /*!< Blacklist threshold */
399-
int blacklist_failopen; /*!< Allow blacklist to fail open */
400393
char outregex[PATH_MAX]; /*!< Regex to use to verify outgoing URIs */
401394
char exceptioncontext[PATH_MAX]; /*!< Action to take upon failure */
402395
char failureaction[PATH_MAX]; /*!< Action to take upon failure */
@@ -413,6 +406,14 @@ struct call_verify {
413406
char loglevel[AST_MAX_CONTEXT]; /*!< Log level */
414407
char logmsg[PATH_MAX]; /*!< Log message */
415408
AST_LIST_ENTRY(call_verify) entry; /*!< Next Verify record */
409+
/* Flags */
410+
unsigned int sanitychecks:1; /*!< Whether or not to do sanity checks on the alleged calling number */
411+
unsigned int extendtrust:1; /*!< Whether to verify through/via calls */
412+
unsigned int allowdisathru:1; /*!< Whether to allow DISA thru calls */
413+
unsigned int allowpstnthru:1; /*!< Whether to allow PSTN thru calls */
414+
unsigned int allowtoken:1; /*!< Whether to allow verification tokens */
415+
unsigned int flagprivateip:1; /*!< Whether to flag private IP addresses as malicious */
416+
unsigned int blacklist_failopen:1; /*!< Allow blacklist to fail open */
416417
};
417418

418419
#define DEFAULT_CURL_TIMEOUT 5
@@ -422,7 +423,7 @@ static int curltimeout = DEFAULT_CURL_TIMEOUT; /*!< Curl Timeout */
422423

423424
static AST_RWLIST_HEAD_STATIC(verifys, call_verify);
424425

425-
char stir_shaken_stats[2][6];
426+
unsigned int stir_shaken_stats[2][6];
426427
ast_mutex_t ss_lock;
427428

428429
/*! \brief Allocate and initialize verify profile */
@@ -1845,7 +1846,7 @@ static const char *stir_shaken_name(char c)
18451846

18461847
static char *handle_show_stirshaken(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
18471848
{
1848-
int total[2];
1849+
unsigned int total[2];
18491850
char c;
18501851

18511852
total[0] = total[1] = 0;
@@ -1863,13 +1864,13 @@ static char *handle_show_stirshaken(struct ast_cli_entry *e, int cmd, struct ast
18631864

18641865
ast_cli(a->fd, "%-30s %14s %14s\n", "STIR/SHAKEN Rating", "# Direct Calls", "Passthru Calls");
18651866
for (c = 'A'; c <= 'F'; c++) {
1866-
ast_cli(a->fd, "%-30s %14d %14d\n", stir_shaken_name(c), stir_shaken_stats[0][c - 'A'], stir_shaken_stats[1][c - 'A']);
1867+
ast_cli(a->fd, "%-30s %14u %14u\n", stir_shaken_name(c), stir_shaken_stats[0][c - 'A'], stir_shaken_stats[1][c - 'A']);
18671868
total[0] += stir_shaken_stats[0][c - 'A'];
18681869
total[1] += stir_shaken_stats[1][c - 'A'];
18691870
}
18701871
ast_cli(a->fd, "------------------------------ ----------\n");
1871-
ast_cli(a->fd, "%-30s %14d %14d\n", "Total # STIR/SHAKEN Calls", total[0], total[1]);
1872-
ast_cli(a->fd, "%-30s %14s %14d\n", "", "=", total[0] + total[1]);
1872+
ast_cli(a->fd, "%-30s %14u %14u\n", "Total # STIR/SHAKEN Calls", total[0], total[1]);
1873+
ast_cli(a->fd, "%-30s %14s %14u\n", "", "=", total[0] + total[1]);
18731874

18741875
return CLI_SUCCESS;
18751876
}
@@ -1878,7 +1879,7 @@ static char *handle_show_stirshaken(struct ast_cli_entry *e, int cmd, struct ast
18781879
static char *handle_show_profiles(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
18791880
{
18801881
#define FORMAT "%-20s %-7s %-8s %-10s %-13s %-11s %-9s %-11s %-14s\n"
1881-
#define FORMAT2 "%-20s %7s %8d %10d %13d %11d %9d %11d %14d\n"
1882+
#define FORMAT2 "%-20s %7s %8u %10u %13u %11u %9u %11u %14u\n"
18821883
struct call_verify *v;
18831884

18841885
switch(cmd) {
@@ -1982,10 +1983,10 @@ static char *handle_show_profile(struct ast_cli_entry *e, int cmd, struct ast_cl
19821983
ast_cli(a->fd, FORMAT, "code_spoof", v->code_spoof);
19831984
ast_cli(a->fd, FORMAT, "Log Level", v->loglevel);
19841985
ast_cli(a->fd, FORMAT, "Log Msg Fmt", v->logmsg);
1985-
ast_cli(a->fd, "%s%d of %d%s incoming calls in profile '%s' have successfully passed verification\n",
1986+
ast_cli(a->fd, "%s%u of %u%s incoming calls in profile '%s' have successfully passed verification\n",
19861987
ast_term_color(v->insuccess == 0 ? COLOR_RED : COLOR_GREEN, COLOR_BLACK),
19871988
v->insuccess, v->in, ast_term_reset(), v->name);
1988-
ast_cli(a->fd, "%s%d of %d%s outgoing calls in profile '%s' have successfully been out-verified\n",
1989+
ast_cli(a->fd, "%s%u of %u%s outgoing calls in profile '%s' have successfully been out-verified\n",
19891990
ast_term_color(v->outsuccess == 0 ? COLOR_RED : COLOR_GREEN, COLOR_BLACK),
19901991
v->outsuccess, v->out, ast_term_reset(), v->name);
19911992
break;

0 commit comments

Comments
 (0)