]> git.puffer.fish Git - matthieu/frr.git/commitdiff
ospfd: fix crash when logging a Grace-LSA
authorRenato Westphal <renato@opensourcerouting.org>
Mon, 31 May 2021 13:27:51 +0000 (10:27 -0300)
committerIgor Ryzhov <iryzhov@nfware.com>
Wed, 9 Jun 2021 16:26:42 +0000 (19:26 +0300)
Change the "show_ospf_grace_lsa_info" callback to account for the
fact that the "vty" parameter can be null.

This fixes a crash that happens when "debug ospf packet ls-update
detail" is configured and a Grace-LSA is sent or received.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
ospfd/ospf_gr_helper.c

index 6e6e7b5c7df45184e25887f5601bf29d52a6e077..10c5020cd18c31660fe26e935c4b971b644ee45e 100644 (file)
@@ -1020,72 +1020,115 @@ static void show_ospf_grace_lsa_info(struct vty *vty, struct ospf_lsa *lsa)
        lsah = (struct lsa_header *)lsa->data;
 
        if (lsa->size <= OSPF_LSA_HEADER_SIZE) {
-               vty_out(vty, "%% Invalid LSA length: %d\n", length);
+               if (vty)
+                       vty_out(vty, "%% Invalid LSA length: %d\n", length);
+               else
+                       zlog_debug("%% Invalid LSA length: %d", length);
                return;
        }
 
        length = lsa->size - OSPF_LSA_HEADER_SIZE;
 
-       vty_out(vty, "  TLV info:\n");
+       if (vty)
+               vty_out(vty, "  TLV info:\n");
+       else
+               zlog_debug("  TLV info:");
 
        for (tlvh = TLV_HDR_TOP(lsah); sum < length && tlvh;
             tlvh = TLV_HDR_NEXT(tlvh)) {
                /* Check TLV len */
                if (sum + TLV_SIZE(tlvh) > length) {
-                       vty_out(vty, "%% Invalid TLV length: %u\n",
-                               TLV_SIZE(tlvh));
+                       if (vty)
+                               vty_out(vty, "%% Invalid TLV length: %u\n",
+                                       TLV_SIZE(tlvh));
+                       else
+                               zlog_debug("%% Invalid TLV length: %u",
+                                          TLV_SIZE(tlvh));
                        return;
                }
 
                switch (ntohs(tlvh->type)) {
                case GRACE_PERIOD_TYPE:
-                       if (TLV_SIZE(tlvh) <
-                           sizeof(struct grace_tlv_graceperiod)) {
-                               vty_out(vty,
-                                       "%% Invalid grace TLV length %u\n",
-                                       TLV_SIZE(tlvh));
+                       if (TLV_SIZE(tlvh)
+                           < sizeof(struct grace_tlv_graceperiod)) {
+                               if (vty)
+                                       vty_out(vty,
+                                               "%% Invalid grace TLV length %u\n",
+                                               TLV_SIZE(tlvh));
+                               else
+                                       zlog_debug(
+                                               "%% Invalid grace TLV length %u",
+                                               TLV_SIZE(tlvh));
                                return;
                        }
 
                        gracePeriod = (struct grace_tlv_graceperiod *)tlvh;
                        sum += TLV_SIZE(tlvh);
 
-                       vty_out(vty, "   Grace period:%d\n",
-                               ntohl(gracePeriod->interval));
+                       if (vty)
+                               vty_out(vty, "   Grace period:%d\n",
+                                       ntohl(gracePeriod->interval));
+                       else
+                               zlog_debug("   Grace period:%d",
+                                          ntohl(gracePeriod->interval));
                        break;
                case RESTART_REASON_TYPE:
-                       if (TLV_SIZE(tlvh) <
-                           sizeof(struct grace_tlv_restart_reason)) {
-                               vty_out(vty,
-                                       "%% Invalid reason TLV length %u\n",
-                                       TLV_SIZE(tlvh));
+                       if (TLV_SIZE(tlvh)
+                           < sizeof(struct grace_tlv_restart_reason)) {
+                               if (vty)
+                                       vty_out(vty,
+                                               "%% Invalid reason TLV length %u\n",
+                                               TLV_SIZE(tlvh));
+                               else
+                                       zlog_debug(
+                                               "%% Invalid reason TLV length %u",
+                                               TLV_SIZE(tlvh));
                                return;
                        }
 
                        grReason = (struct grace_tlv_restart_reason *)tlvh;
                        sum += TLV_SIZE(tlvh);
 
-                       vty_out(vty, "   Restart reason:%s\n",
-                               ospf_restart_reason2str(grReason->reason));
+                       if (vty)
+                               vty_out(vty, "   Restart reason:%s\n",
+                                       ospf_restart_reason2str(
+                                               grReason->reason));
+                       else
+                               zlog_debug("   Restart reason:%s",
+                                          ospf_restart_reason2str(
+                                                  grReason->reason));
                        break;
                case RESTARTER_IP_ADDR_TYPE:
-                       if (TLV_SIZE(tlvh) <
-                           sizeof(struct grace_tlv_restart_addr)) {
-                               vty_out(vty,
-                                       "%% Invalid addr TLV length %u\n",
-                                       TLV_SIZE(tlvh));
+                       if (TLV_SIZE(tlvh)
+                           < sizeof(struct grace_tlv_restart_addr)) {
+                               if (vty)
+                                       vty_out(vty,
+                                               "%% Invalid addr TLV length %u\n",
+                                               TLV_SIZE(tlvh));
+                               else
+                                       zlog_debug(
+                                               "%% Invalid addr TLV length %u",
+                                               TLV_SIZE(tlvh));
                                return;
                        }
 
                        restartAddr = (struct grace_tlv_restart_addr *)tlvh;
                        sum += TLV_SIZE(tlvh);
 
-                       vty_out(vty, "   Restarter address:%pI4\n",
-                               &restartAddr->addr);
+                       if (vty)
+                               vty_out(vty, "   Restarter address:%pI4\n",
+                                       &restartAddr->addr);
+                       else
+                               zlog_debug("   Restarter address:%pI4",
+                                          &restartAddr->addr);
                        break;
                default:
-                       vty_out(vty, "   Unknown TLV type %d\n",
-                               ntohs(tlvh->type));
+                       if (vty)
+                               vty_out(vty, "   Unknown TLV type %d\n",
+                                       ntohs(tlvh->type));
+                       else
+                               zlog_debug("   Unknown TLV type %d",
+                                          ntohs(tlvh->type));
 
                        break;
                }