From: Hangbin Liu <liuhangbin@gmail.com>
To: Stephen Hemminger <stephen@networkplumber.org>
Cc: netdev@vger.kernel.org, jhs@mojatatu.com
Subject: Re: [PATCH iproute2] tc: u32: check return value from snprintf
Date: Mon, 12 Feb 2024 15:24:49 +0800 [thread overview]
Message-ID: <ZcnHwRCr6s3T8VXt@Laptop-X1> (raw)
In-Reply-To: <20240211010441.8262-1-stephen@networkplumber.org>
On Sat, Feb 10, 2024 at 05:04:23PM -0800, Stephen Hemminger wrote:
> Add assertion to check for case of snprintf failing (bad format?)
> or buffer getting full.
>
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Hi Stephen,
Is there a bug report or something else that we only do the assertion
for tc/f_u32.c?
Thanks
Hangbin
> ---
> tc/f_u32.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/tc/f_u32.c b/tc/f_u32.c
> index 913ec1de435d..8a2413103906 100644
> --- a/tc/f_u32.c
> +++ b/tc/f_u32.c
> @@ -7,6 +7,7 @@
> *
> */
>
> +#include <assert.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <unistd.h>
> @@ -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;
> }
> --
> 2.43.0
>
next prev parent reply other threads:[~2024-02-12 7:24 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-11 1:04 [PATCH iproute2] tc: u32: check return value from snprintf Stephen Hemminger
2024-02-12 7:24 ` Hangbin Liu [this message]
2024-02-12 16:53 ` Stephen Hemminger
2024-02-16 9:58 ` David Laight
2024-02-13 6:25 ` Hangbin Liu
2024-02-15 3:10 ` patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZcnHwRCr6s3T8VXt@Laptop-X1 \
--to=liuhangbin@gmail.com \
--cc=jhs@mojatatu.com \
--cc=netdev@vger.kernel.org \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox