]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: Convert assert to error and record it instead of aborting
authorDonald Sharp <sharpd@nvidia.com>
Wed, 4 Aug 2021 15:13:26 +0000 (11:13 -0400)
committerDonald Sharp <sharpd@nvidia.com>
Wed, 4 Aug 2021 15:13:26 +0000 (11:13 -0400)
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 <sharpd@nvidia.com>
lib/zclient.c

index 0815e77d4edff76b9f8712531c5be807e0340918..f68e0e1b0c17a5aae93bcfe9f9649ded29cd9343 100644 (file)
@@ -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);
        }