Subject: Re: [PATCH iproute2] ip: xfrm: add NUL character to security context name before printing

From: Stephen Hemminger <[email-masked]>
Date: Mon, 8 Mar 2021 09:18:41 -0800

On Tue, 16 Feb 2021 17:50:58 +0100
Sabrina Dubroca <[email-masked]> 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));