From 1ae0e1b315edf256d41760bcbb631b5d2be0d087 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Wed, 4 Aug 2021 11:13:26 -0400 Subject: [PATCH] lib: Convert assert to error and record it instead of aborting When we get a bad value for the opaque data length, instead of stopping the program, discard the data and move on. Signed-off-by: Donald Sharp --- lib/zclient.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/zclient.c b/lib/zclient.c index 0815e77d4e..f68e0e1b0c 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -1299,7 +1299,13 @@ int zapi_route_encode(uint8_t cmd, struct stream *s, struct zapi_route *api) stream_putl(s, api->tableid); if (CHECK_FLAG(api->message, ZAPI_MESSAGE_OPAQUE)) { - assert(api->opaque.length <= ZAPI_MESSAGE_OPAQUE_LENGTH); + if (api->opaque.length > ZAPI_MESSAGE_OPAQUE_LENGTH) { + flog_err( + EC_LIB_ZAPI_ENCODE, + "%s: opaque length %u is greater than allowed value", + __func__, api->opaque.length); + return -1; + } stream_putw(s, api->opaque.length); stream_write(s, api->opaque.data, api->opaque.length); @@ -1537,7 +1543,13 @@ int zapi_route_decode(struct stream *s, struct zapi_route *api) if (CHECK_FLAG(api->message, ZAPI_MESSAGE_OPAQUE)) { STREAM_GETW(s, api->opaque.length); - assert(api->opaque.length <= ZAPI_MESSAGE_OPAQUE_LENGTH); + if (api->opaque.length > ZAPI_MESSAGE_OPAQUE_LENGTH) { + flog_err( + EC_LIB_ZAPI_ENCODE, + "%s: opaque length %u is greater than allowed value", + __func__, api->opaque.length); + return -1; + } STREAM_GET(api->opaque.data, s, api->opaque.length); } -- 2.39.5