From: Stephen Hemminger Date: Sun, 11 Feb 2024 00:47:25 +0000 (-0800) Subject: tc: u32: check return value from snprintf X-Git-Tag: v6.8.0~12 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d06f6a3d1766b42cb0d93537a77c46cdcb877745;p=thirdparty%2Fiproute2.git tc: u32: check return value from snprintf Add assertion to check for case of snprintf failing (bad format?) or buffer getting full. Signed-off-by: Stephen Hemminger --- diff --git a/tc/f_u32.c b/tc/f_u32.c index 913ec1de..8a241310 100644 --- a/tc/f_u32.c +++ b/tc/f_u32.c @@ -7,6 +7,7 @@ * */ +#include #include #include #include @@ -87,6 +88,7 @@ static char *sprint_u32_handle(__u32 handle, char *buf) if (htid) { int l = snprintf(b, bsize, "%x:", htid>>20); + assert(l > 0 && l < bsize); bsize -= l; b += l; } @@ -94,12 +96,14 @@ static char *sprint_u32_handle(__u32 handle, char *buf) if (hash) { int l = snprintf(b, bsize, "%x", hash); + assert(l > 0 && l < bsize); bsize -= l; b += l; } if (nodeid) { int l = snprintf(b, bsize, ":%x", nodeid); + assert(l > 0 && l < bsize); bsize -= l; b += l; }