xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Ian Campbell <ian.campbell@citrix.com>
To: ian.jackson@eu.citrix.com, wei.liu2@citrix.com, xen-devel@lists.xen.org
Subject: Re: [PATCH] libxl: qmp: ensure qmp read buffer is NULL terminated
Date: Tue, 23 Feb 2016 10:30:42 +0000	[thread overview]
Message-ID: <1456223442.6225.125.camel@citrix.com> (raw)
In-Reply-To: <1455706940-27999-1-git-send-email-ian.campbell@citrix.com>

On Wed, 2016-02-17 at 11:02 +0000, Ian Campbell wrote:
> Coverity rightly points out that qmp->buffer may not be NULL
> terminated when passed to strncat.
> 
> Make the actual buffer a byte bigger than QMP_RECEIVE_BUFFER_SIZE and
> always append a NULL byte.
> 
> I suspect that in practice we have not yet seen QMP messages
> approaching the buffer size (4K).
> 
> Compile tested only.
> 
> CID: 1055989
> 
> Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

ping.

> ---
>  tools/libxl/libxl_qmp.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c
> index 714038b..c45702e 100644
> --- a/tools/libxl/libxl_qmp.c
> +++ b/tools/libxl/libxl_qmp.c
> @@ -67,7 +67,7 @@ struct libxl__qmp_handler {
>      /* wait_for_id will be used by the synchronous send function */
>      int wait_for_id;
>  
> -    char buffer[QMP_RECEIVE_BUFFER_SIZE];
> +    char buffer[QMP_RECEIVE_BUFFER_SIZE + 1];
>      libxl__yajl_ctx *yajl_ctx;
>  
>      libxl_ctx *ctx;
> @@ -457,6 +457,7 @@ static int qmp_next(libxl__gc *gc, libxl__qmp_handler
> *qmp)
>              LOGE(ERROR, "Socket read error");
>              return rd;
>          }
> +        qmp->buffer[rd] = '\0';
>  
>          DEBUG_REPORT_RECEIVED(qmp->buffer, rd);
>  

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

  reply	other threads:[~2016-02-23 10:30 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-17 11:02 [PATCH] libxl: qmp: ensure qmp read buffer is NULL terminated Ian Campbell
2016-02-23 10:30 ` Ian Campbell [this message]
2016-03-01 16:17 ` Ian Jackson

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=1456223442.6225.125.camel@citrix.com \
    --to=ian.campbell@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.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;
as well as URLs for NNTP newsgroup(s).