[OpenSIPS-Devel] [OpenSIPS/opensips] 50fe41: Fix crash in db_timer_udomain() when the database ...

Liviu Chircu noreply at github.com
Mon Apr 26 11:36:15 EST 2021


  Branch: refs/heads/master
  Home:   https://github.com/OpenSIPS/opensips
  Commit: 50fe41d2d07fffab91f22034518c2cf1cb631a3d
      https://github.com/OpenSIPS/opensips/commit/50fe41d2d07fffab91f22034518c2cf1cb631a3d
  Author: Walter Doekes <walter+github at wjd.nu>
  Date:   2021-04-13 (Tue, 13 Apr 2021)

  Changed paths:
    M modules/usrloc/udomain.c

  Log Message:
  -----------
  Fix crash in db_timer_udomain() when the database has little work

The previous code, added in 1f0be8f02 but mostly fixed by 0d0909fc1,
added this interesting erroneous pattern:

    static db_ps_t my_ps = NULL;
    db_key_t keys[2];
    db_op_t  ops[2];

    if (my_ps == NULL) {
        keys[0] = &expires_col;
        ops[0] = "<";
        ...

That is: the initialisation of the stack depended on a global (local
static). Once it was set, the initialisation would be skipped, causing
keys and ops to contain undefined values.

Due to the way the CON_PS_REFERENCE() prepared statement handle code has
become, my_ps would always be reset to NULL after use, hiding this bug.

However, if you have a flaky database connection (for instance
an auto-closing socket on a machine with little traffic) then the
following happens:

    CRITICAL:db_mysql:wrapper_single_mysql_stmt_execute: driver error
      (2003): Lost connection to backend server.
    ERROR:usrloc:db_timer_udomain: failed to delete from table location
    ERROR:usrloc:synchronize_all_udomains: synchronizing cache failed

When this happens, my_ps is _not_ reset to NULL, and the next time this
function is invoked, keys and ops are undefined, causing a segfault
down the road.

This changeset adds an if around use_table() because all the other code
in this module does so. The actual fix is the removal of if(my_ps==NULL).

(An alternative fix could have been to explicitly reset the prepared
statement handle to NULL like 57caa6c03 does. Or to make keys and ops
static too and set them only once.)


  Commit: f7b8e1bf0c9cf4f5d3064934feb78b50dc7bf5f3
      https://github.com/OpenSIPS/opensips/commit/f7b8e1bf0c9cf4f5d3064934feb78b50dc7bf5f3
  Author: Liviu Chircu <liviu at opensips.org>
  Date:   2021-04-26 (Mon, 26 Apr 2021)

  Changed paths:
    M modules/usrloc/udomain.c

  Log Message:
  -----------
  Merge branch 'fix-usrloc-crash-in-db_timer_udomain' of https://github.com/wdoekes/opensips into wdoekes-fix-usrloc-crash-in-db_timer_udomain


Compare: https://github.com/OpenSIPS/opensips/compare/551c1ed41d93...f7b8e1bf0c9c



More information about the Devel mailing list