]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - lib/mpls_ntop.c
rdma: Properly mark RDMAtool license
[mirror_iproute2.git] / lib / mpls_ntop.c
index 945d6d5e453516419ef2bd2587e9ffe80f4c6a4d..f8d89f421ecba6b09af1fd191d5c8a9af320439e 100644 (file)
@@ -1,3 +1,5 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
 #include <errno.h>
 #include <string.h>
 #include <sys/types.h>
@@ -10,18 +12,20 @@ static const char *mpls_ntop1(const struct mpls_label *addr, char *buf, size_t b
 {
        size_t destlen = buflen;
        char *dest = buf;
-       int count;
+       int count = 0;
 
-       for (count = 0; count < MPLS_MAX_LABELS; count++) {
-               uint32_t entry = ntohl(addr[count].entry);
+       while (1) {
+               uint32_t entry = ntohl(addr[count++].entry);
                uint32_t label = (entry & MPLS_LS_LABEL_MASK) >> MPLS_LS_LABEL_SHIFT;
                int len = snprintf(dest, destlen, "%u", label);
 
+               if (len >= destlen)
+                       break;
+
                /* Is this the end? */
                if (entry & MPLS_LS_S_MASK)
                        return buf;
 
-
                dest += len;
                destlen -= len;
                if (destlen) {