summaryrefslogtreecommitdiff
path: root/lib/sockunion.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/sockunion.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/sockunion.c')
-rw-r--r--lib/sockunion.c59
1 files changed, 32 insertions, 27 deletions
diff --git a/lib/sockunion.c b/lib/sockunion.c
index 1dbf77efa4..c701da1e03 100644
--- a/lib/sockunion.c
+++ b/lib/sockunion.c
@@ -673,39 +673,44 @@ static ssize_t printfrr_psu(char *buf, size_t bsz, const char *fmt,
bool endflags = false;
ssize_t consumed = 2;
- while (!endflags) {
- switch (fmt[consumed++]) {
- case 'p':
- include_port = true;
+ if (su) {
+ while (!endflags) {
+ switch (fmt[consumed++]) {
+ case 'p':
+ include_port = true;
+ break;
+ default:
+ consumed--;
+ endflags = true;
+ break;
+ }
+ };
+
+ switch (sockunion_family(su)) {
+ case AF_UNSPEC:
+ bprintfrr(&fb, "(unspec)");
break;
- default:
- consumed--;
- endflags = true;
+ case AF_INET:
+ inet_ntop(AF_INET, &su->sin.sin_addr, buf, bsz);
+ fb.pos += strlen(fb.buf);
+ if (include_port)
+ bprintfrr(&fb, ":%d", su->sin.sin_port);
+ break;
+ case AF_INET6:
+ inet_ntop(AF_INET6, &su->sin6.sin6_addr, buf, bsz);
+ fb.pos += strlen(fb.buf);
+ if (include_port)
+ bprintfrr(&fb, ":%d", su->sin6.sin6_port);
break;
+ default:
+ bprintfrr(&fb, "(af %d)", sockunion_family(su));
}
- };
- switch (sockunion_family(su)) {
- case AF_UNSPEC:
- bprintfrr(&fb, "(unspec)");
- break;
- case AF_INET:
- inet_ntop(AF_INET, &su->sin.sin_addr, buf, bsz);
- fb.pos += strlen(fb.buf);
- if (include_port)
- bprintfrr(&fb, ":%d", su->sin.sin_port);
- break;
- case AF_INET6:
- inet_ntop(AF_INET6, &su->sin6.sin6_addr, buf, bsz);
- fb.pos += strlen(fb.buf);
- if (include_port)
- bprintfrr(&fb, ":%d", su->sin6.sin6_port);
- break;
- default:
- bprintfrr(&fb, "(af %d)", sockunion_family(su));
+ fb.pos[0] = '\0';
+ } else {
+ strlcpy(buf, "NULL", bsz);
}
- fb.pos[0] = '\0';
return consumed;
}