summaryrefslogtreecommitdiff
path: root/lib/zclient.c
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@users.noreply.github.com>2019-01-22 13:53:08 -0500
committerGitHub <noreply@github.com>2019-01-22 13:53:08 -0500
commitb9c25a2a906116dd4924045b7f663318e623b932 (patch)
tree4a3ff33778adb5131f2cf9bf83531ef29d1e68dd /lib/zclient.c
parentb3cfe1e2da00c3a0233885d83d7d7246291c8e40 (diff)
parent7fcb24bbaa91762965ad15aff10956919fdc3c08 (diff)
Merge pull request #3559 from opensourcerouting/zapi-sanity-checks
add a few moar sanity checks when encoding/decoding zapi routes
Diffstat (limited to 'lib/zclient.c')
-rw-r--r--lib/zclient.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/lib/zclient.c b/lib/zclient.c
index 4f39774e38..0e58d97174 100644
--- a/lib/zclient.c
+++ b/lib/zclient.c
@@ -754,10 +754,24 @@ int zapi_route_encode(uint8_t cmd, struct stream *s, struct zapi_route *api)
stream_reset(s);
zclient_create_header(s, cmd, api->vrf_id);
+ if (api->type >= ZEBRA_ROUTE_MAX) {
+ flog_err(EC_LIB_ZAPI_ENCODE,
+ "%s: Specified route type (%u) is not a legal value\n",
+ __PRETTY_FUNCTION__, api->type);
+ return -1;
+ }
stream_putc(s, api->type);
+
stream_putw(s, api->instance);
stream_putl(s, api->flags);
stream_putc(s, api->message);
+
+ if (api->safi < SAFI_UNICAST || api->safi >= SAFI_MAX) {
+ flog_err(EC_LIB_ZAPI_ENCODE,
+ "%s: Specified route SAFI (%u) is not a legal value\n",
+ __PRETTY_FUNCTION__, api->safi);
+ return -1;
+ }
stream_putc(s, api->safi);
/* Put prefix information. */
@@ -873,7 +887,7 @@ int zapi_route_decode(struct stream *s, struct zapi_route *api)
/* Type, flags, message. */
STREAM_GETC(s, api->type);
- if (api->type > ZEBRA_ROUTE_MAX) {
+ if (api->type >= ZEBRA_ROUTE_MAX) {
flog_err(EC_LIB_ZAPI_ENCODE,
"%s: Specified route type: %d is not a legal value\n",
__PRETTY_FUNCTION__, api->type);
@@ -884,6 +898,12 @@ int zapi_route_decode(struct stream *s, struct zapi_route *api)
STREAM_GETL(s, api->flags);
STREAM_GETC(s, api->message);
STREAM_GETC(s, api->safi);
+ if (api->safi < SAFI_UNICAST || api->safi >= SAFI_MAX) {
+ flog_err(EC_LIB_ZAPI_ENCODE,
+ "%s: Specified route SAFI (%u) is not a legal value\n",
+ __PRETTY_FUNCTION__, api->safi);
+ return -1;
+ }
/* Prefix. */
STREAM_GETC(s, api->prefix.family);