]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
res_prometheus: Do not crash on invisible bridges
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>
Tue, 20 Sep 2022 00:53:18 +0000 (08:53 +0800)
committerHolger Hans Peter Freyther <automatic@freyther.de>
Tue, 27 Sep 2022 00:27:58 +0000 (19:27 -0500)
Avoid crashing by skipping invisible bridges and checking the
snapshot for a null pointer. In effect this is how the bridges
are enumerated in res/ari/resource_bridges.c already.

ASTERISK-30239
ASTERISK-30237

Change-Id: I58ef9f44036feded5966b5fc70ae754f8182883d

res/prometheus/bridges.c

index 5a916049e0126e973e7ca11235323278675ddb63..505dab839713ade109a25ccbceba1f9ad331556b 100644 (file)
@@ -125,7 +125,17 @@ static void bridges_scrape_cb(struct ast_str **response)
        /* Bridge dependent values */
        it_bridges = ao2_iterator_init(bridges, 0);
        for (i = 0; (bridge = ao2_iterator_next(&it_bridges)); ao2_ref(bridge, -1), i++) {
-               struct ast_bridge_snapshot *snapshot = ast_bridge_get_snapshot(bridge);
+               struct ast_bridge_snapshot *snapshot;
+
+               /* Invisible bridges don't get shown externally and have no snapshot */
+               if (ast_test_flag(&bridge->feature_flags, AST_BRIDGE_FLAG_INVISIBLE)) {
+                       continue;
+               }
+
+               snapshot = ast_bridge_get_snapshot(bridge);
+               if (!snapshot) {
+                       continue;
+               }
 
                for (j = 0; j < ARRAY_LEN(bridge_metric_defs); j++) {
                        int index = i * ARRAY_LEN(bridge_metric_defs) + j;