From patchwork Fri Aug 23 17:05:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Javi Merino X-Patchwork-Id: 13775590 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 45657C52D7C for ; Fri, 23 Aug 2024 17:05:42 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.782501.1192006 (Exim 4.92) (envelope-from ) id 1shXjD-0004V2-JG; Fri, 23 Aug 2024 17:05:35 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 782501.1192006; Fri, 23 Aug 2024 17:05:35 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1shXjD-0004Uv-G8; Fri, 23 Aug 2024 17:05:35 +0000 Received: by outflank-mailman (input) for mailman id 782501; Fri, 23 Aug 2024 17:05:34 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1shXjC-00048i-IT for xen-devel@lists.xenproject.org; Fri, 23 Aug 2024 17:05:34 +0000 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [2a00:1450:4864:20::536]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id e8f107b9-6171-11ef-a50a-bb4a2ccca743; Fri, 23 Aug 2024 19:05:34 +0200 (CEST) Received: by mail-ed1-x536.google.com with SMTP id 4fb4d7f45d1cf-5bed83489c3so2851608a12.3 for ; Fri, 23 Aug 2024 10:05:34 -0700 (PDT) Received: from localhost.localdomain ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c04a3eb329sm2311240a12.55.2024.08.23.10.05.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Aug 2024 10:05:32 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: e8f107b9-6171-11ef-a50a-bb4a2ccca743 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1724432733; x=1725037533; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9VIye94cR8IJfpIZ8L9EApwOAmNPuWDMwQhUPHfNmgs=; b=MSJWAcbFddUMHEy6LfiUEbx7Di0J8MDNgNIDqxZE/MWH4ArPw3Pm8uj0ZQ0CfrJSLv XVdR5pG08UBTVq1NzreOJY/6MimeAyPrClfhisHOVTdMZ5224biUvfJyGYF6fqqZSr1x jSM5wfkte8dAYnVeQr1hhXh398n6rCDNDmu5M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724432733; x=1725037533; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9VIye94cR8IJfpIZ8L9EApwOAmNPuWDMwQhUPHfNmgs=; b=FdTsfJpVuh2gZIQO1TCZ/0QkUiVH5SO7pjp5zyvh2mlBSU9vbAZHZN1F3W8Uu6NiMO nn1gPqLr/XwY1K3IKVMXuxvXdPLYEHbPr4xnr6uV9rGDhjYQtbE082kDiDLPf09j/v6R PQSPj0LjIFBbLUew0pHoWG/2RNQ4USAyR5D27S8j8pfO3lqLZsUQlXBVJwGPOayg5vfT 4aSa3VxSZUAshCNjJ1k7zd8b7u8obAARglmRLpGaffImTa2B/OLL6muG1wOZ6CRHfaNf pLj/E7S8gluOiqNIwz1bfzM6lHTpNi7HNs+t1IIFtl6R8F2ENABGp0d+NbWmLg+FlnZe xK+A== X-Gm-Message-State: AOJu0Yzopp+Vggh6S2Q2LQ2ndzkDVth1pW3T0c0rJC5i+RN3JxHvmb5W 8hSAFi9WgPy7HRjpWSi4uzqp1jyqoQpX6uUK1jLK2b1Y2jlvacWmo5wR2FFbf4M68ZZI9hni7vG c X-Google-Smtp-Source: AGHT+IHcVUId93VWEXlfsjTxnksH0mjTfTAjn1kakV6hRAVCHTAcJ6ZkNu8RxbgHVtSlFErE5o2Rxg== X-Received: by 2002:a05:6402:1d4f:b0:5bf:b29:6ec6 with SMTP id 4fb4d7f45d1cf-5c0891a9e7emr1746069a12.37.1724432732619; Fri, 23 Aug 2024 10:05:32 -0700 (PDT) From: Javi Merino To: xen-devel@lists.xenproject.org Cc: jbeulich@suse.com, andrew.cooper3@citrix.com, Javi Merino , Anthony PERARD , Juergen Gross , =?utf-8?b?RWR3aW4gVMO2csO2aw==?= Subject: [XEN PATCH v2 1/3] libxl: Fix nul-termination of the return value of libxl_xen_console_read_line() Date: Fri, 23 Aug 2024 18:05:03 +0100 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 When built with ASAN, "xl dmesg" crashes in the "printf("%s", line)" call in main_dmesg(). ASAN reports a heap buffer overflow: an off-by-one access to cr->buffer. The readconsole sysctl copies up to count characters into the buffer, but it does not add a null character at the end. Despite the documentation of libxl_xen_console_read_line(), line_r is not nul-terminated if 16384 characters were copied to the buffer. Fix this by asking xc_readconsolering() to fill the buffer up to size - 1. As the number of characters in the buffer is only needed in libxl_xen_console_read_line(), make it a local variable there instead of part of the libxl__xen_console_reader struct. Fixes: 4024bae739cc ("xl: Add subcommand 'xl dmesg'") Reported-by: Edwin Török Signed-off-by: Javi Merino Reviewed-by: Anthony PERARD --- tools/libs/light/libxl_console.c | 14 ++++++++++---- tools/libs/light/libxl_internal.h | 1 - 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/tools/libs/light/libxl_console.c b/tools/libs/light/libxl_console.c index a563c9d3c7f9..012fd996fba9 100644 --- a/tools/libs/light/libxl_console.c +++ b/tools/libs/light/libxl_console.c @@ -774,12 +774,14 @@ libxl_xen_console_reader * { GC_INIT(ctx); libxl_xen_console_reader *cr; - unsigned int size = 16384; + /* We want xen to fill the buffer in as few hypercalls as + * possible, but xen will not nul-terminate it. Leave one byte at + * the end for the null */ + unsigned int size = 16384 + 1; cr = libxl__zalloc(NOGC, sizeof(libxl_xen_console_reader)); cr->buffer = libxl__zalloc(NOGC, size); cr->size = size; - cr->count = size; cr->clear = clear; cr->incremental = 1; @@ -800,10 +802,14 @@ int libxl_xen_console_read_line(libxl_ctx *ctx, char **line_r) { int ret; + /* number of chars to copy into the buffer. xc_readconsolering() + * does not add a null character at the end, so leave a space for + * us to add it. */ + unsigned int nr_chars = cr->size - 1; GC_INIT(ctx); memset(cr->buffer, 0, cr->size); - ret = xc_readconsolering(ctx->xch, cr->buffer, &cr->count, + ret = xc_readconsolering(ctx->xch, cr->buffer, &nr_chars, cr->clear, cr->incremental, &cr->index); if (ret < 0) { LOGE(ERROR, "reading console ring buffer"); @@ -811,7 +817,7 @@ int libxl_xen_console_read_line(libxl_ctx *ctx, return ERROR_FAIL; } if (!ret) { - if (cr->count) { + if (nr_chars) { *line_r = cr->buffer; ret = 1; } else { diff --git a/tools/libs/light/libxl_internal.h b/tools/libs/light/libxl_internal.h index 3b58bb2d7f43..96d14f5746e1 100644 --- a/tools/libs/light/libxl_internal.h +++ b/tools/libs/light/libxl_internal.h @@ -2077,7 +2077,6 @@ _hidden char *libxl__uuid2string(libxl__gc *gc, const libxl_uuid uuid); struct libxl__xen_console_reader { char *buffer; unsigned int size; - unsigned int count; unsigned int clear; unsigned int incremental; unsigned int index; From patchwork Fri Aug 23 17:05:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javi Merino X-Patchwork-Id: 13775591 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 02F5FC531DC for ; Fri, 23 Aug 2024 17:05:52 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.782503.1192016 (Exim 4.92) (envelope-from ) id 1shXjM-0004tn-QP; Fri, 23 Aug 2024 17:05:44 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 782503.1192016; Fri, 23 Aug 2024 17:05:44 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1shXjM-0004tb-N6; Fri, 23 Aug 2024 17:05:44 +0000 Received: by outflank-mailman (input) for mailman id 782503; Fri, 23 Aug 2024 17:05:43 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1shXjL-0004r8-Kc for xen-devel@lists.xenproject.org; Fri, 23 Aug 2024 17:05:43 +0000 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [2a00:1450:4864:20::534]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id ed7acc3a-6171-11ef-8776-851b0ebba9a2; Fri, 23 Aug 2024 19:05:41 +0200 (CEST) Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-5a10835487fso3577961a12.1 for ; Fri, 23 Aug 2024 10:05:41 -0700 (PDT) Received: from localhost.localdomain ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c04a3eb329sm2311240a12.55.2024.08.23.10.05.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Aug 2024 10:05:40 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: ed7acc3a-6171-11ef-8776-851b0ebba9a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1724432741; x=1725037541; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XFEkl0EMoN1DvmJO1HoJ/u/U+K3mFLD5lcEOzlHVel4=; b=UCiVZZg1bJTFmbBpU01imLK7TmyVi6D7DcnZTx7wKIuD96xdWYUsByjyuz0WnEdtV3 CAbLLrZUdXazikE81I3kXtlQNyKJ6a68RgPfg500e6Xk5zeTDMBhoBa8a9FkWkL4MW4O R4ACI+WozH06pXnqWrXckRKhdMomE9pTyOB+s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724432741; x=1725037541; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XFEkl0EMoN1DvmJO1HoJ/u/U+K3mFLD5lcEOzlHVel4=; b=XgedvPSjn7u+qBt2XJdxyDjRR0WUSuT/70psMKpwXyZI3FMD1ZyKzwALPnegjHi3eb IlD9AQ5RCn1dogG0pd10pc+xo6R7ykv84irbyr+NfKAvZ8MFY2Y98DNUm5a6kyMPDHcF Y6iOAIltMxPDnpSrhTY9xmzbxaXqzP3xWk8LO2EadnUR7YEQE79HjniFCp2+MaJldRCL SCzTWkPB3cvGXHXW5g/3xFQQ52mVw4g4uTuBGh84WUsA7ChxVsFTobotdQBlDc59WhUc NiKeLjQBCl4hCUqBKyTMk3aYnjMzoAYmpne4MjcdkYavXoVpE7ajUzmmKA8uCaoxgWnJ Pbww== X-Gm-Message-State: AOJu0YzYaM/0eaq2BaQOOLc46oe+1EL8ZMPFKc6LgPjU0y2OIRNi/ZsO Xa3tHDUpTAGn5BhiSXsUknJwd8Oqc4ZrqK8ej3RvcG6foJZzy/PD0UeLi4ut3P3ghekzvLM+KJB 7 X-Google-Smtp-Source: AGHT+IH6FyymKyCPUj5/UdPZsLtONLq48URxhfGe+UappiQ0B70aRoGrd/MjeFqdgoKUW8HST4a5Pg== X-Received: by 2002:a05:6402:1d49:b0:5a2:fc48:db12 with SMTP id 4fb4d7f45d1cf-5c0891758d1mr2240292a12.19.1724432740912; Fri, 23 Aug 2024 10:05:40 -0700 (PDT) From: Javi Merino To: xen-devel@lists.xenproject.org Cc: jbeulich@suse.com, andrew.cooper3@citrix.com, Javi Merino , Anthony PERARD , Juergen Gross Subject: [XEN PATCH v2 2/3] libxl: Remove unnecessary buffer zeroing and zalloc() Date: Fri, 23 Aug 2024 18:05:04 +0100 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 When reading the console, xen overwrites the contents of the buffer, so there is no need to zero the buffer before passing it to xen. Instead, add a NULL at the end of the buffer. While we are at it, change the zalloc() of the buffer back to malloc() as it was before bdf4131 (libxl: don't leak buf in libxl_xen_console_read_start error handling, 2013-12-03). The comment in that commit message says that the intent of the commit was to change malloc+memset to zalloc(), but only for the libxl_xen_console_reader struct, not for the buffer. Signed-off-by: Javi Merino Reviewed-by: Anthony PERARD --- tools/libs/light/libxl_console.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/libs/light/libxl_console.c b/tools/libs/light/libxl_console.c index 012fd996fba9..f42f6a51ee6f 100644 --- a/tools/libs/light/libxl_console.c +++ b/tools/libs/light/libxl_console.c @@ -780,7 +780,7 @@ libxl_xen_console_reader * unsigned int size = 16384 + 1; cr = libxl__zalloc(NOGC, sizeof(libxl_xen_console_reader)); - cr->buffer = libxl__zalloc(NOGC, size); + cr->buffer = libxl__malloc(NOGC, size); cr->size = size; cr->clear = clear; cr->incremental = 1; @@ -808,7 +808,6 @@ int libxl_xen_console_read_line(libxl_ctx *ctx, unsigned int nr_chars = cr->size - 1; GC_INIT(ctx); - memset(cr->buffer, 0, cr->size); ret = xc_readconsolering(ctx->xch, cr->buffer, &nr_chars, cr->clear, cr->incremental, &cr->index); if (ret < 0) { @@ -818,6 +817,7 @@ int libxl_xen_console_read_line(libxl_ctx *ctx, } if (!ret) { if (nr_chars) { + cr->buffer[nr_chars] = '\0'; *line_r = cr->buffer; ret = 1; } else { From patchwork Fri Aug 23 17:05:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javi Merino X-Patchwork-Id: 13775592 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 89C80C531DC for ; Fri, 23 Aug 2024 17:05:56 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.782504.1192026 (Exim 4.92) (envelope-from ) id 1shXjQ-0005Ca-2f; Fri, 23 Aug 2024 17:05:48 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 782504.1192026; Fri, 23 Aug 2024 17:05:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1shXjP-0005CO-VR; Fri, 23 Aug 2024 17:05:47 +0000 Received: by outflank-mailman (input) for mailman id 782504; Fri, 23 Aug 2024 17:05:46 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1shXjO-00048i-Bs for xen-devel@lists.xenproject.org; Fri, 23 Aug 2024 17:05:46 +0000 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [2a00:1450:4864:20::52b]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id efd1f8cb-6171-11ef-a50a-bb4a2ccca743; Fri, 23 Aug 2024 19:05:45 +0200 (CEST) Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-5becd359800so2673563a12.0 for ; Fri, 23 Aug 2024 10:05:45 -0700 (PDT) Received: from localhost.localdomain ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c04a3eb329sm2311240a12.55.2024.08.23.10.05.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Aug 2024 10:05:44 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: efd1f8cb-6171-11ef-a50a-bb4a2ccca743 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1724432745; x=1725037545; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=y9zU8RmotkcMzPPMMUF5U/qTDP3KTxHaHOi0grkKB0I=; b=fL+Z3U8Is+8tPbrNmEB6OTzoHvtWXkKlYupaIw6Z2IEsbuwAOiJ7dbxVSCrW2rkxWD LlwSTvNPh0flO/KhhtKy37eYWXSH6y1AhZq3Ot6T4bOu8hk6aJ17V+NRGYD83D3+40mp G2QBnk0ArKa7aJ9z8YKbcqcQfZjTSUt+m2prY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724432745; x=1725037545; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=y9zU8RmotkcMzPPMMUF5U/qTDP3KTxHaHOi0grkKB0I=; b=l1epFnY2V/YVtworvEVqJ+edIoIDtM83a4GTDcq3SrQQ/MYsxuiNMrMHJZdtXNhg4w v23oPe/ljIAsdepZ+5nal2AMcYOum5kh13domyhQmzQoVah8ppRvpSz359nNBoY2iPrm Lbv0hdWz7FcrRpdbD+KnxH0kgBPUVAHe2qf02gkUetRWCsw8OpeD8B2Fw3vseo1BEPGV YxwPYhe8Z74C1+s7/l+wkksT1mNvD9+jbNmqEINJ/gMxRfipyQNDeXedwoSXl+3FMvST KjKMnp25xbEElcqs+a0Rb9+0PcnOdm/4c2LnfcDqbLU50bf90h2HbCAv+BiuQlFo0bcX tEZA== X-Gm-Message-State: AOJu0YwpfHzL2GO0UHBdrTRRXTUqxzrIHc/m7elhzNjo/i1r36/PANMA 8HUKFoN0IqBKoKWISmmgGSXTTh53lkz2vkiFUXT2YM50lC8B74VbR84AzGu+wT9RR7OMlLcWMh3 I X-Google-Smtp-Source: AGHT+IH9gi47eRDyTWF0F5XtXBpBWXTDCGEMNeCDo7kB6ResJleCMbF7ptrc272MMZ0N4AvTK/Oeww== X-Received: by 2002:a05:6402:34c5:b0:5be:9bc5:f6b3 with SMTP id 4fb4d7f45d1cf-5c089158f81mr2090157a12.2.1724432744780; Fri, 23 Aug 2024 10:05:44 -0700 (PDT) From: Javi Merino To: xen-devel@lists.xenproject.org Cc: jbeulich@suse.com, andrew.cooper3@citrix.com, Javi Merino , Anthony PERARD , Juergen Gross Subject: [XEN PATCH v2 3/3] libxl: Update the documentation of libxl_xen_console_read_line() Date: Fri, 23 Aug 2024 18:05:05 +0100 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 Despite its name, libxl_xen_console_read_line() does not read a line, it fills the buffer with as many characters as fit. Update the documentation to reflect the real behaviour of the function. Rename line_r to avoid confusion since it is a pointer to an array of characters. Signed-off-by: Javi Merino --- tools/libs/light/libxl_console.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/tools/libs/light/libxl_console.c b/tools/libs/light/libxl_console.c index f42f6a51ee6f..652897e4ef6d 100644 --- a/tools/libs/light/libxl_console.c +++ b/tools/libs/light/libxl_console.c @@ -789,17 +789,19 @@ libxl_xen_console_reader * return cr; } -/* return values: *line_r - * 1 success, whole line obtained from buffer non-0 - * 0 no more lines available right now 0 - * negative error code ERROR_* 0 - * On success *line_r is updated to point to a nul-terminated +/* Copy part of the console ring into a buffer + * + * Return values: + * 1: Success, the buffer obtained from the console ring an + * 0: No more lines available right now + * -ERROR_* on error + * + * On success, *line_r is updated to point to a nul-terminated * string which is valid until the next call on the same console - * reader. The libxl caller may overwrite parts of the string - * if it wishes. */ + * reader. */ int libxl_xen_console_read_line(libxl_ctx *ctx, libxl_xen_console_reader *cr, - char **line_r) + char **buff) { int ret; /* number of chars to copy into the buffer. xc_readconsolering() @@ -818,10 +820,10 @@ int libxl_xen_console_read_line(libxl_ctx *ctx, if (!ret) { if (nr_chars) { cr->buffer[nr_chars] = '\0'; - *line_r = cr->buffer; + *buff = cr->buffer; ret = 1; } else { - *line_r = NULL; + *buff = NULL; ret = 0; } }