and xfrmnl_sp_set_sec_ctx(). The user already must pass a NUL
terminated string, where the NUL is included in ctx_len.
Just allocate one more by and ensure the buffer is '\0' terminated.
/* Free up the old context string and allocate new one */
if (sa->sec_ctx)
free (sa->sec_ctx);
- if ((sa->sec_ctx = calloc(1, sizeof (struct xfrmnl_user_sec_ctx) + len)) == NULL)
+ if ((sa->sec_ctx = calloc(1, sizeof (struct xfrmnl_user_sec_ctx) + 1 + len)) == NULL)
return -1;
/* Save the new info */
sa->sec_ctx->ctx_doi = doi;
sa->sec_ctx->ctx_len = len;
memcpy (sa->sec_ctx->ctx, ctx_str, len);
+ sa->sec_ctx->ctx[len] = '\0';
sa->ce_mask |= XFRM_SA_ATTR_SECCTX;
/* Free up the old context string and allocate new one */
if (sp->sec_ctx)
free (sp->sec_ctx);
- if ((sp->sec_ctx = calloc (1, sizeof (struct xfrmnl_user_sec_ctx) + ctx_len)) == NULL)
+ if ((sp->sec_ctx = calloc (1, sizeof (struct xfrmnl_user_sec_ctx) + 1 + ctx_len)) == NULL)
return -1;
/* Save the new info */
sp->sec_ctx->ctx_doi = doi;
sp->sec_ctx->ctx_len = ctx_len;
memcpy ((void *)sp->sec_ctx->ctx, (void *)ctx_str, ctx_len);
+ sp->sec_ctx->ctx[ctx_len] = '\0';
sp->ce_mask |= XFRM_SP_ATTR_SECCTX;