Skip to content

Commit

Permalink
acc: Fix possible crash if 'aaa' module not loaded
Browse files Browse the repository at this point in the history
If do_accounting("aaa") is used without a backend module loaded,
OpenSIPS would actually start, then crash when generating an acc record.

Credits to Simon Gajski and Bogdan Iancu for reporting and diagnosing
the issue here.
  • Loading branch information
liviuchircu committed Dec 11, 2023
1 parent 894d9bb commit 42f1eb7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
14 changes: 13 additions & 1 deletion modules/acc/acc.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ event_id_t acc_cdr_event = EVI_ERROR;
event_id_t acc_event = EVI_ERROR;
event_id_t acc_missed_event = EVI_ERROR;

static db_func_t acc_dbf;
db_func_t acc_dbf;
static db_con_t* db_handle=0;
extern int acc_log_facility;

Expand Down Expand Up @@ -850,6 +850,12 @@ int acc_aaa_request( struct sip_msg *req, struct sip_msg *rpl)
struct acc_extra* extra;
acc_ctx_t* ctx = try_fetch_ctx();

if (!proto.create_aaa_message) {
LM_BUG("failed to generate AAA record ('aaa' accounting was enabled"
", but no 'aaa' module is available!)");
return -1;
}

if ((send = proto.create_aaa_message(conn, AAA_ACCT)) == NULL) {
LM_ERR("failed to create new aaa message for acct\n");
return -1;
Expand Down Expand Up @@ -949,6 +955,12 @@ int acc_aaa_cdrs(struct dlg_cell *dlg, struct sip_msg *msg, acc_ctx_t* ctx)

struct acc_extra* extra;

if (!proto.create_aaa_message) {
LM_BUG("failed to generate AAA record ('aaa' accounting was enabled"
", but no 'aaa' module is available!)");
return -1;
}

core_s.s = extra_s.s = leg_s.s = 0;

ret = prebuild_core_arr(dlg, &core_s, &start_time);
Expand Down
1 change: 1 addition & 0 deletions modules/acc/acc.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
#include "acc_logic.h"

extern struct dlg_binds dlg_api;
extern db_func_t acc_dbf;


int store_extra_values(extra_value_t* values, str *values_str,
Expand Down
13 changes: 12 additions & 1 deletion modules/acc/acc_logic.c
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ static void acc_cdr_cb( struct cell* t, int type, struct tmcb_params *ps )
}

if (is_aaa_acc_on(ctx->flags) && acc_aaa_cdrs(dlg, ps->req, ctx) < 0) {
LM_ERR("Cannot create radius accounting\n");
LM_ERR("Cannot perform radius accounting\n");
return;
}

Expand Down Expand Up @@ -1037,9 +1037,20 @@ unsigned long long do_acc_type_parser(str* token)
return DO_ACC_LOG;
} else if (token->len == do_acc_aaa_s.len &&
!strncasecmp(token->s, do_acc_aaa_s.s, token->len)) {
if (!proto.create_aaa_message) {
LM_ERR("do_accounting(\"aaa\") was used"
", but no 'aaa' module is loaded!\n");
return DO_ACC_ERR;
}

return DO_ACC_AAA;
} else if (token->len == do_acc_db_s.len &&
!strncasecmp(token->s, do_acc_db_s.s, token->len)) {
if (!acc_dbf.init) {
LM_ERR("do_accounting(\"db\") was used"
", but no 'db' module is loaded!\n");
return DO_ACC_ERR;
}
return DO_ACC_DB;
} else if (token->len == do_acc_evi_s.len &&
!strncasecmp(token->s, do_acc_evi_s.s, token->len)) {
Expand Down

0 comments on commit 42f1eb7

Please sign in to comment.