mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-15 05:18:47 +00:00
lib: add a few more sanity checks when encoding/decoding routes
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
This commit is contained in:
parent
46b020ce1a
commit
e4081c0e0b
@ -749,10 +749,24 @@ int zapi_route_encode(uint8_t cmd, struct stream *s, struct zapi_route *api)
|
|||||||
stream_reset(s);
|
stream_reset(s);
|
||||||
zclient_create_header(s, cmd, api->vrf_id);
|
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_putc(s, api->type);
|
||||||
|
|
||||||
stream_putw(s, api->instance);
|
stream_putw(s, api->instance);
|
||||||
stream_putl(s, api->flags);
|
stream_putl(s, api->flags);
|
||||||
stream_putc(s, api->message);
|
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);
|
stream_putc(s, api->safi);
|
||||||
|
|
||||||
/* Put prefix information. */
|
/* Put prefix information. */
|
||||||
@ -868,7 +882,7 @@ int zapi_route_decode(struct stream *s, struct zapi_route *api)
|
|||||||
|
|
||||||
/* Type, flags, message. */
|
/* Type, flags, message. */
|
||||||
STREAM_GETC(s, api->type);
|
STREAM_GETC(s, api->type);
|
||||||
if (api->type > ZEBRA_ROUTE_MAX) {
|
if (api->type >= ZEBRA_ROUTE_MAX) {
|
||||||
flog_err(EC_LIB_ZAPI_ENCODE,
|
flog_err(EC_LIB_ZAPI_ENCODE,
|
||||||
"%s: Specified route type: %d is not a legal value\n",
|
"%s: Specified route type: %d is not a legal value\n",
|
||||||
__PRETTY_FUNCTION__, api->type);
|
__PRETTY_FUNCTION__, api->type);
|
||||||
@ -879,6 +893,12 @@ int zapi_route_decode(struct stream *s, struct zapi_route *api)
|
|||||||
STREAM_GETL(s, api->flags);
|
STREAM_GETL(s, api->flags);
|
||||||
STREAM_GETC(s, api->message);
|
STREAM_GETC(s, api->message);
|
||||||
STREAM_GETC(s, api->safi);
|
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. */
|
/* Prefix. */
|
||||||
STREAM_GETC(s, api->prefix.family);
|
STREAM_GETC(s, api->prefix.family);
|
||||||
|
@ -530,6 +530,7 @@ int zsend_redistribute_route(int cmd, struct zserv *client,
|
|||||||
memset(&api, 0, sizeof(api));
|
memset(&api, 0, sizeof(api));
|
||||||
api.vrf_id = re->vrf_id;
|
api.vrf_id = re->vrf_id;
|
||||||
api.type = re->type;
|
api.type = re->type;
|
||||||
|
api.safi = SAFI_UNICAST;
|
||||||
api.instance = re->instance;
|
api.instance = re->instance;
|
||||||
api.flags = re->flags;
|
api.flags = re->flags;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user