summaryrefslogtreecommitdiff
path: root/lib/prefix.c
diff options
context:
space:
mode:
authorMark Stapp <mjs@voltanet.io>2021-03-01 15:41:30 -0500
committerMark Stapp <mjs@voltanet.io>2021-03-01 15:41:30 -0500
commit8e2c653ed30f672617ef97f4479aff24db855154 (patch)
treef53a4d41bb799360edbd2bcd757146abd9ce35c4 /lib/prefix.c
parent001ab42b1916e7ad69b77a7defdfd5e728104688 (diff)
lib: protect printfrr extensions from NULL input
Protect the lib printfrr extension handlers from NULL inputs. Signed-off-by: Mark Stapp <mjs@voltanet.io>
Diffstat (limited to 'lib/prefix.c')
-rw-r--r--lib/prefix.c54
1 files changed, 40 insertions, 14 deletions
diff --git a/lib/prefix.c b/lib/prefix.c
index c98e0c1c72..5e5c2d89a8 100644
--- a/lib/prefix.c
+++ b/lib/prefix.c
@@ -1366,7 +1366,11 @@ static ssize_t printfrr_ea(char *buf, size_t bsz, const char *fmt,
{
const struct ethaddr *mac = ptr;
- prefix_mac2str(mac, buf, bsz);
+ if (mac)
+ prefix_mac2str(mac, buf, bsz);
+ else
+ strlcpy(buf, "NULL", bsz);
+
return 2;
}
@@ -1376,7 +1380,11 @@ static ssize_t printfrr_ia(char *buf, size_t bsz, const char *fmt,
{
const struct ipaddr *ipa = ptr;
- ipaddr2str(ipa, buf, bsz);
+ if (ipa)
+ ipaddr2str(ipa, buf, bsz);
+ else
+ strlcpy(buf, "NULL", bsz);
+
return 2;
}
@@ -1384,7 +1392,11 @@ printfrr_ext_autoreg_p("I4", printfrr_i4)
static ssize_t printfrr_i4(char *buf, size_t bsz, const char *fmt,
int prec, const void *ptr)
{
- inet_ntop(AF_INET, ptr, buf, bsz);
+ if (ptr)
+ inet_ntop(AF_INET, ptr, buf, bsz);
+ else
+ strlcpy(buf, "NULL", bsz);
+
return 2;
}
@@ -1392,7 +1404,11 @@ printfrr_ext_autoreg_p("I6", printfrr_i6)
static ssize_t printfrr_i6(char *buf, size_t bsz, const char *fmt,
int prec, const void *ptr)
{
- inet_ntop(AF_INET6, ptr, buf, bsz);
+ if (ptr)
+ inet_ntop(AF_INET6, ptr, buf, bsz);
+ else
+ strlcpy(buf, "NULL", bsz);
+
return 2;
}
@@ -1400,7 +1416,11 @@ printfrr_ext_autoreg_p("FX", printfrr_pfx)
static ssize_t printfrr_pfx(char *buf, size_t bsz, const char *fmt,
int prec, const void *ptr)
{
- prefix2str(ptr, buf, bsz);
+ if (ptr)
+ prefix2str(ptr, buf, bsz);
+ else
+ strlcpy(buf, "NULL", bsz);
+
return 2;
}
@@ -1411,16 +1431,22 @@ static ssize_t printfrr_psg(char *buf, size_t bsz, const char *fmt,
const struct prefix_sg *sg = ptr;
struct fbuf fb = { .buf = buf, .pos = buf, .len = bsz - 1 };
- if (sg->src.s_addr == INADDR_ANY)
- bprintfrr(&fb, "(*,");
- else
- bprintfrr(&fb, "(%pI4,", &sg->src);
+ if (sg) {
+ if (sg->src.s_addr == INADDR_ANY)
+ bprintfrr(&fb, "(*,");
+ else
+ bprintfrr(&fb, "(%pI4,", &sg->src);
- if (sg->grp.s_addr == INADDR_ANY)
- bprintfrr(&fb, "*)");
- else
- bprintfrr(&fb, "%pI4)", &sg->grp);
+ if (sg->grp.s_addr == INADDR_ANY)
+ bprintfrr(&fb, "*)");
+ else
+ bprintfrr(&fb, "%pI4)", &sg->grp);
+
+ fb.pos[0] = '\0';
+
+ } else {
+ strlcpy(buf, "NULL", bsz);
+ }
- fb.pos[0] = '\0';
return 3;
}