From: Liliang Subject: [PATCH] libxl: fix the bug which will cause heap to break down Date: Fri, 27 Jun 2014 14:21:17 +0800 Message-ID: <1403850077-6693-1-git-send-email-liangx.z.li@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1X0Pa5-0000wJ-0w for xen-devel@lists.xenproject.org; Fri, 27 Jun 2014 06:24:17 +0000 List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xenproject.org Cc: Li Liang , ian.campbell@citrix.com List-Id: xen-devel@lists.xenproject.org From: Li Liang If the JSON message contains more bytes than QMP_RECEIVE_BUFFER_SIZE, this bug will break down the heap, that leads to core dump. One more byte should be allocated to contain the appended null character. Signed-off-by: Li Liang --- tools/libxl/libxl_qmp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c index 8433e42..5cc56b1 100644 --- a/tools/libxl/libxl_qmp.c +++ b/tools/libxl/libxl_qmp.c @@ -456,7 +456,7 @@ static int qmp_next(libxl__gc *gc, libxl__qmp_handler *qmp) if (incomplete) { size_t current_pos = s - incomplete; incomplete = libxl__realloc(gc, incomplete, - incomplete_size + rd); + incomplete_size + rd + 1); strncat(incomplete + incomplete_size, qmp->buffer, rd); s = incomplete + current_pos; incomplete_size += rd; -- 1.9.1