[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20210308091841.5d572cf1@hermes.local>
Date: Mon, 8 Mar 2021 09:18:41 -0800
From: Stephen Hemminger <stephen@...workplumber.org>
To: Sabrina Dubroca <sd@...asysnail.net>
Cc: netdev@...r.kernel.org, dsahern@...il.com,
Paul Wouters <pwouters@...hat.com>
Subject: Re: [PATCH iproute2] ip: xfrm: add NUL character to security
context name before printing
On Tue, 16 Feb 2021 17:50:58 +0100
Sabrina Dubroca <sd@...asysnail.net> wrote:
> +static void xfrm_sec_ctx_print(FILE *fp, struct rtattr *attr)
> +{
> + struct xfrm_user_sec_ctx *sctx;
> + char buf[65536] = {};
> +
> + fprintf(fp, "\tsecurity context ");
> +
> + if (RTA_PAYLOAD(attr) < sizeof(*sctx))
> + fprintf(fp, "(ERROR truncated)");
> +
> + sctx = RTA_DATA(attr);
> +
> + memcpy(buf, (char *)(sctx + 1), sctx->ctx_len);
> + fprintf(fp, "%s %s", buf, _SL_);
> +}
The copy buffer is not needed. Use the printf precision as
a mechanism instead.
fprintf(fp, "%.*s %s", sctx->ctx_len, (char *)(sctx + 1));
Powered by blists - more mailing lists