Skip to content

Commit

Permalink
b2b_logic: don't crash when searching inexistent tuple by key
Browse files Browse the repository at this point in the history
Searching the current tuple by key for accessing the logic context
should not cause a crash. As the hash is not locked or the structure
ref counted, there is a distinct possibility that the tuple cannot
be found anymore.

Related to #3117

(cherry picked from commit d05d408)
  • Loading branch information
rvlad-patrascu committed Jul 4, 2023
1 parent 0f5a389 commit af86cf6
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions modules/b2b_logic/b2b_logic_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ static b2bl_tuple_t *b2bl_ctx_get_tuple(str *key)
{
b2bl_tuple_t *tuple = b2bl_get_tuple(key);
if (!tuple) {
LM_BUG("could not find logic tuple [%.*s]\n", key->len, key->s);
abort();
LM_ERR("could not find logic tuple [%.*s]\n", key->len, key->s);
return NULL;
}
return tuple;
}
Expand Down Expand Up @@ -55,20 +55,38 @@ int b2bl_ctx_register_ptr(context_destroy_f f)
void b2bl_ctx_put_int(str *key, int pos, int data)
{
b2bl_tuple_t *tuple = b2bl_ctx_get_tuple(key);

if (!tuple) {
LM_ERR("Failed to store data in b2b logic context\n");
return;
}

context_put_int(CONTEXT_B2B_LOGIC, context_of(tuple), pos, data);
b2bl_ctx_release_tuple(tuple);
}

void b2bl_ctx_put_str(str *key, int pos, str *data)
{
b2bl_tuple_t *tuple = b2bl_ctx_get_tuple(key);

if (!tuple) {
LM_ERR("Failed to store data in b2b logic context\n");
return;
}

context_put_str(CONTEXT_B2B_LOGIC, context_of(tuple), pos, data);
b2bl_ctx_release_tuple(tuple);
}

void b2bl_ctx_put_ptr(str *key, int pos, void *data)
{
b2bl_tuple_t *tuple = b2bl_ctx_get_tuple(key);

if (!tuple) {
LM_ERR("Failed to store data in b2b logic context\n");
return;
}

context_put_ptr(CONTEXT_B2B_LOGIC, context_of(tuple), pos, data);
b2bl_ctx_release_tuple(tuple);
}
Expand All @@ -77,6 +95,12 @@ int b2bl_ctx_get_int(str *key, int pos)
{
int ret;
b2bl_tuple_t *tuple = b2bl_ctx_get_tuple(key);

if (!tuple) {
LM_ERR("Failed to retrieve data from b2b logic context\n");
return 0;
}

ret = context_get_int(CONTEXT_B2B_LOGIC, context_of(tuple), pos);
b2bl_ctx_release_tuple(tuple);
return ret;
Expand All @@ -86,6 +110,12 @@ str *b2bl_ctx_get_str(str *key, int pos)
{
str *ret;
b2bl_tuple_t *tuple = b2bl_ctx_get_tuple(key);

if (!tuple) {
LM_ERR("Failed to retrieve data from b2b logic context\n");
return &STR_NULL;
}

ret = context_get_str(CONTEXT_B2B_LOGIC, context_of(tuple), pos);
b2bl_ctx_release_tuple(tuple);
return ret;
Expand All @@ -95,6 +125,12 @@ void *b2bl_ctx_get_ptr(str *key, int pos)
{
void *ret;
b2bl_tuple_t *tuple = b2bl_ctx_get_tuple(key);

if (!tuple) {
LM_ERR("Failed to retrieve data from b2b logic context\n");
return NULL;
}

ret = context_get_ptr(CONTEXT_B2B_LOGIC, context_of(tuple), pos);
b2bl_ctx_release_tuple(tuple);
return ret;
Expand Down

0 comments on commit af86cf6

Please sign in to comment.