From nobody Sat Nov 23 11:37:08 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1725295147; cv=none; d=zohomail.com; s=zohoarc; b=jD2IAU5HHd+iq/RR6HXlDP2EbWDV8l/AcD7pz/8rQe1Ff8pkby0E4TlRUcWRURormgt0Kfr3IUxlwyjUQpdeFV6b/l3BsUcHDbwYRW5NovIfiTpVcO+/S6b9HjJyj/gXRS1u9GzFuwPRVghUpR3cBpJ+eSkk0u+x6rvUa4sRdW0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1725295147; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=/6eT7Yk/7LIs6hDfcYQ7HO3X7+DA9vMIsVz9MMYObK8=; b=LuWHKFSYH2zMfjc1LITH1gbozW270vOPv/qej0FksyAibGHtc8tnEYYPu5NhHG2NUzWIfyyXqyiLMxJToO7M9v7GQdSyFPsvO7N+BJbg2gvA9lj2bTDJoC/TvEFELH2w6AlYA3309tgQ/iSjQk82A8So1N74aTG7BF1lxIKj/rY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1725295147711371.01169101258506; Mon, 2 Sep 2024 09:39:07 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.788265.1197750 (Exim 4.92) (envelope-from ) id 1slA4p-0002ZW-By; Mon, 02 Sep 2024 16:38:51 +0000 Received: by outflank-mailman (output) from mailman id 788265.1197750; Mon, 02 Sep 2024 16:38:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1slA4p-0002ZP-9O; Mon, 02 Sep 2024 16:38:51 +0000 Received: by outflank-mailman (input) for mailman id 788265; Mon, 02 Sep 2024 16:38:50 +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 1slA4o-0002KR-3F for xen-devel@lists.xenproject.org; Mon, 02 Sep 2024 16:38:50 +0000 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [2a00:1450:4864:20::532]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id d40e8d87-6949-11ef-a0b2-8be0dac302b0; Mon, 02 Sep 2024 18:38:48 +0200 (CEST) Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-5c25554ec1eso1441889a12.1 for ; Mon, 02 Sep 2024 09:38:48 -0700 (PDT) Received: from localhost.localdomain ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c226c74184sm5714163a12.32.2024.09.02.09.38.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Sep 2024 09:38:47 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: d40e8d87-6949-11ef-a0b2-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1725295128; x=1725899928; 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=/6eT7Yk/7LIs6hDfcYQ7HO3X7+DA9vMIsVz9MMYObK8=; b=BnMi8YCwoctfg1FX4UparMgPtORzPut6xhd1mSVbOhAGL378JAAImRl82zZcgaiH4Z 7H4Ncmkdvdj7E2T/zQJBkSVF5ztLQURemCuDs+APMCdaWCrBEXoSwrM1Q+9QS83LePe8 xQQOwQFOtXTJoDZi7ZYRsUOHPnteVkNbUFIqc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725295128; x=1725899928; 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=/6eT7Yk/7LIs6hDfcYQ7HO3X7+DA9vMIsVz9MMYObK8=; b=i2i3enuLonWR2VlssHW3COzAx7unLjESBm1PdaZZzMwjb9xB4pOVRw6QsVrXA3Zn5M YXS3SXYMM4UiYFZA3Rjbd8hywyStYWAOAfNp0h4T/S3jeLzwo882yiGA3qnTlgR4qr+M GoGiY/edXn+OyNDsEzoyC8LOB4R1cEZGykY3uYj9SFqlrqUM2WaJLnjba4K06p/u+Xe5 c5TBMm4Eq3z8ELLyxpoE+Zljf4gR7JLLLTUdCEHdg4lj173fUwLR+pxiM1ERAc2CsNrx 2YoiFLHhHg1aFi7yxd+GcQXFDHfRoXyk4CvjmYJ4O6EBYOkgi1m0Ppa1YvV1Gll1N8jt l79g== X-Gm-Message-State: AOJu0Yyfnd9ELOSvk1WLgyBypNCxCDF6tgPeFe7/oGMe7E1SijYh4bQa YwpSNXumbanBT3jeU+TDtH/CPTOOBysvsg9h1WrgUmYsx/YKeyI448JQNH6EvSzTKjD5Gq/ONGP q9kg= X-Google-Smtp-Source: AGHT+IFicB+fQM5XiuO8ifLtLIo0YpKL2FO35R3K8EcmdRWCq5G9bU1kGIOqb3I9vrQp+m40W6rnKw== X-Received: by 2002:a05:6402:51d2:b0:5be:eb90:183c with SMTP id 4fb4d7f45d1cf-5c21ed314abmr11860340a12.6.1725295127549; Mon, 02 Sep 2024 09:38:47 -0700 (PDT) From: Javi Merino To: xen-devel@lists.xenproject.org Cc: Javi Merino , Anthony PERARD , Juergen Gross , =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= Subject: [XEN PATCH v3 1/3] libxl: Fix nul-termination of the return value of libxl_xen_console_read_line() Date: Mon, 2 Sep 2024 17:38:37 +0100 Message-ID: <37e935be214083f1b16b5da4d3be09e7cbafc971.1725294334.git.javi.merino@cloud.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1725295148342116600 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=C3=B6r=C3=B6k Reviewed-by: Anthony PERARD Signed-off-by: Javi Merino --- tools/libs/light/libxl_console.c | 19 +++++++++++++++---- tools/libs/light/libxl_internal.h | 1 - 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/tools/libs/light/libxl_console.c b/tools/libs/light/libxl_cons= ole.c index a563c9d3c7f9..9f736b891335 100644 --- a/tools/libs/light/libxl_console.c +++ b/tools/libs/light/libxl_console.c @@ -774,12 +774,17 @@ libxl_xen_console_reader * { GC_INIT(ctx); libxl_xen_console_reader *cr; - unsigned int size =3D 16384; + /* + * We want xen to fill the buffer in as few hypercalls as + * possible, but xen will not nul-terminate it. The default size + * of Xen's console buffer is 16384. Leave one byte at the end + * for the null character. + */ + unsigned int size =3D 16384 + 1; =20 cr =3D libxl__zalloc(NOGC, sizeof(libxl_xen_console_reader)); cr->buffer =3D libxl__zalloc(NOGC, size); cr->size =3D size; - cr->count =3D size; cr->clear =3D clear; cr->incremental =3D 1; =20 @@ -800,10 +805,16 @@ 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 =3D cr->size - 1; GC_INIT(ctx); =20 memset(cr->buffer, 0, cr->size); - ret =3D xc_readconsolering(ctx->xch, cr->buffer, &cr->count, + ret =3D 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 +822,7 @@ int libxl_xen_console_read_line(libxl_ctx *ctx, return ERROR_FAIL; } if (!ret) { - if (cr->count) { + if (nr_chars) { *line_r =3D cr->buffer; ret =3D 1; } else { diff --git a/tools/libs/light/libxl_internal.h b/tools/libs/light/libxl_int= ernal.h index 089a2f949c53..cfac8e18b6d3 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; --=20 2.45.2 From nobody Sat Nov 23 11:37:08 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1725295147; cv=none; d=zohomail.com; s=zohoarc; b=cjEzkQ303rheKqoFwhFl4zjO6JhudbQdnFlWM2enOLlWzgzJNIC13LGEwQ7eSbRQQaPoLV8FkE9d/TNlsJDyQWne5txc7HeE4WxyIZ1CelO/d4thWMRXphw5dHMmwwdzZIWk+XQt8+NDMttDf+U1li7FU0P+RaFEsYTgqXpvLJI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1725295147; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=VWffGUoWm/YnanzIonTob8Et/hrh7mhg2Z2Ub3j/Ojo=; b=Vb9VtI1W/Pw87sJpiMHkUWRC41YOwA3XCmXyIIZyybezAeA/5DEJXqjp463OTeKMUwWrPGOHZzIhKOR6ER4OOFqXmYqwk7O+gb747jw+ggvgZSez+RKDhrKb48YP6IVhr+8EnOyCaDNiG8r03dF79y4Qq1q75Hgahma5ciRRXgY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1725295147721316.7262897854116; Mon, 2 Sep 2024 09:39:07 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.788266.1197756 (Exim 4.92) (envelope-from ) id 1slA4p-0002dV-Pv; Mon, 02 Sep 2024 16:38:51 +0000 Received: by outflank-mailman (output) from mailman id 788266.1197756; Mon, 02 Sep 2024 16:38:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1slA4p-0002d0-J0; Mon, 02 Sep 2024 16:38:51 +0000 Received: by outflank-mailman (input) for mailman id 788266; Mon, 02 Sep 2024 16:38:50 +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 1slA4o-0001qY-Bz for xen-devel@lists.xenproject.org; Mon, 02 Sep 2024 16:38:50 +0000 Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [2a00:1450:4864:20::22b]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id d45234ee-6949-11ef-99a1-01e77a169b0f; Mon, 02 Sep 2024 18:38:48 +0200 (CEST) Received: by mail-lj1-x22b.google.com with SMTP id 38308e7fff4ca-2f4f2868783so44981791fa.2 for ; Mon, 02 Sep 2024 09:38:48 -0700 (PDT) Received: from localhost.localdomain ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c226c74184sm5714163a12.32.2024.09.02.09.38.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Sep 2024 09:38:47 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: d45234ee-6949-11ef-99a1-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1725295128; x=1725899928; 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=VWffGUoWm/YnanzIonTob8Et/hrh7mhg2Z2Ub3j/Ojo=; b=JLFhcMqoBkUgbz2Vt3AuJn5wPt5Q94YIZS+UThWSFPa4Gyl962f5DxybAbIQ+NdYjI 5Ww31XkvsTh7HeuMnZHigDuUurek5gZSeur4FJKmUzCiAUSq31cGppeDsHvw2+eSJcRB JoLRZaLW1Pmhq725qh4svQeQ1YKrmIVryuIR4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725295128; x=1725899928; 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=VWffGUoWm/YnanzIonTob8Et/hrh7mhg2Z2Ub3j/Ojo=; b=HfkiU9Bn0zi/VSfyibc6Lte995hpoxM8xy/yAqRMxrYzwoWQGCVZhEpgp9O1esw049 RwnQuP97zJEBcucrm3r645Yyi71IeSiiLnXJcOZvROhHKSgwu5vHcjrF6AQk2VwsaTW0 Iq9845EfNiVN8mNaglc0YhRkrfLBNHSAoN2qN1HZ9f08ajvuBOW4HQbRwLCqzq7VklZV JBuj1wLWPV5Bgj7VGu4YGMoJM2/v91k1IbvUFy0fa1VkuCL5uOoEvwgNh6QZcngBP0bS MxdGrkr02pJSYzu5HPKTmSfJq09JFAJipfp+2nomRqlBiEoCnp3prqs5aW2EIiM+el2z sOvQ== X-Gm-Message-State: AOJu0YxzeD6GD9pKyVKqOqcP84fCItZWVSHnzmTuF9+Ia/zuT9j9TfAV Ku/256J8IpYw8eCaxvpzHL/X1uQJTqYmxQT8OoXqzm0NmtHxWHxFmGo28fdcnYurNwwYF+l7DtJ cXJY= X-Google-Smtp-Source: AGHT+IHNn355QRqsxQGZcSLypF32F2FhbBsuyloC2cUeI5ll4szv2VFxdws+d9hum67VUClqmo1kSw== X-Received: by 2002:a05:651c:1545:b0:2f1:6821:d15c with SMTP id 38308e7fff4ca-2f61e0b268bmr66067351fa.38.1725295128015; Mon, 02 Sep 2024 09:38:48 -0700 (PDT) From: Javi Merino To: xen-devel@lists.xenproject.org Cc: Javi Merino , Anthony PERARD , Juergen Gross Subject: [XEN PATCH v3 2/3] libxl: Remove unnecessary buffer zeroing and zalloc() Date: Mon, 2 Sep 2024 17:38:38 +0100 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1725295149443116600 Content-Type: text/plain; charset="utf-8" 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_cons= ole.c index 9f736b891335..6c4414fcc1a2 100644 --- a/tools/libs/light/libxl_console.c +++ b/tools/libs/light/libxl_console.c @@ -783,7 +783,7 @@ libxl_xen_console_reader * unsigned int size =3D 16384 + 1; =20 cr =3D libxl__zalloc(NOGC, sizeof(libxl_xen_console_reader)); - cr->buffer =3D libxl__zalloc(NOGC, size); + cr->buffer =3D libxl__malloc(NOGC, size); cr->size =3D size; cr->clear =3D clear; cr->incremental =3D 1; @@ -813,7 +813,6 @@ int libxl_xen_console_read_line(libxl_ctx *ctx, unsigned int nr_chars =3D cr->size - 1; GC_INIT(ctx); =20 - memset(cr->buffer, 0, cr->size); ret =3D xc_readconsolering(ctx->xch, cr->buffer, &nr_chars, cr->clear, cr->incremental, &cr->index); if (ret < 0) { @@ -823,6 +822,7 @@ int libxl_xen_console_read_line(libxl_ctx *ctx, } if (!ret) { if (nr_chars) { + cr->buffer[nr_chars] =3D '\0'; *line_r =3D cr->buffer; ret =3D 1; } else { --=20 2.45.2 From nobody Sat Nov 23 11:37:08 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1725295153; cv=none; d=zohomail.com; s=zohoarc; b=nJlJlDE3jr7qvLBuggBV5r0b70kqAcyZUL5NwuFu1NU971a7tDOOFAI/KTUEvSbelHtAiGLL4c3L8zpSrbbqhkid9c62psJYTfJh0ORN19ByGDNbDg177Lnu4w5H3iXIc+u3Aj1e6CnhtAvKEDYIT/OKbW4syWXYjKsXwcmTC6Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1725295153; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Knysur5vVx3WEMQ6p3lPxj+aKROQfM3qQ3wfpziD/zU=; b=fAKqm1uwRJzLMzJ+ZlQLRSMsyykmuWdmlYTpkCDbgqFbR2dGDWhtg5BPNk9iQsaBWtv9YVEvP031OSzwkSbrzIuZm7y+Es/cABGI5qyw9dT5TqWyo/eoM/UFG59RiyeKWJZt2LpFnmxOCPErgCjL9xFCZm1smyqYj5QrpjSnGPg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1725295153203914.3489950671592; Mon, 2 Sep 2024 09:39:13 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.788267.1197770 (Exim 4.92) (envelope-from ) id 1slA4r-00034x-5m; Mon, 02 Sep 2024 16:38:53 +0000 Received: by outflank-mailman (output) from mailman id 788267.1197770; Mon, 02 Sep 2024 16:38:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1slA4r-00034k-2D; Mon, 02 Sep 2024 16:38:53 +0000 Received: by outflank-mailman (input) for mailman id 788267; Mon, 02 Sep 2024 16:38:51 +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 1slA4p-0002KR-3H for xen-devel@lists.xenproject.org; Mon, 02 Sep 2024 16:38:51 +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 d4b99cc9-6949-11ef-a0b2-8be0dac302b0; Mon, 02 Sep 2024 18:38:49 +0200 (CEST) Received: by mail-ed1-x536.google.com with SMTP id 4fb4d7f45d1cf-5c26852af8fso685192a12.2 for ; Mon, 02 Sep 2024 09:38:49 -0700 (PDT) Received: from localhost.localdomain ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c226c74184sm5714163a12.32.2024.09.02.09.38.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Sep 2024 09:38:48 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: d4b99cc9-6949-11ef-a0b2-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1725295129; x=1725899929; 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=Knysur5vVx3WEMQ6p3lPxj+aKROQfM3qQ3wfpziD/zU=; b=Jsdsr+5rVMoQAOeD+hcQfzorqaxiCNnCbjZXUPbcbnZLjQzVkr5Aapq0ypVNKG12mM GTsFw2OUWJ52+Oe3VGA0oPfWdEMYo5Xkf9rt4hIqwZWGffP2cRzNpmaNKVy5aN/Agwtn NKAaIqKf7N3sUpxqI4Qvk/gE1NtxMadlYYsoo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725295129; x=1725899929; 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=Knysur5vVx3WEMQ6p3lPxj+aKROQfM3qQ3wfpziD/zU=; b=efCd9BJ2BM9JrQWEWk6fv0kcl2zimFaAH+UdDmUUCLoH08H/dQn1kErKdR+WuMJVp+ lAXKaj3G5io2sQbC+qoxE06TvnfAVzZ917EA34tPaAaCBmDHzjJYbYBzrmCPrB8ebQ44 Wo0MNDzeS0RLYgODEXbdP4BOCq1lCRGYOVG7B0ZE1PyCo7Yeb3rHYQ/6mDfd5uCK2BRG XsTEKOaHbhb1uw/fFO8wg29zeJ4aC2YE8tStfnV1tV/E6VMM9BimlNUZjLFh9hVsKSyB +hZBM91Mh4CV033ReFmtL8YChB053gXms86036afBcHw7kZK5Sokn4LlfWX/RbgLUaum 7aug== X-Gm-Message-State: AOJu0YzQK0tBpnbuGJ+EyuvEVYUiw6ESzckvZ+F7Yun4QsNNBuStXZrR IepPWmyd9ovrnACwtYNX8Hv3JUTTFYKIzBnJBpWZH2yrUXVjetho30u5EawwykHM6ns4lL7T5Z+ YS4Y= X-Google-Smtp-Source: AGHT+IETiZmo6gPUKNcnhqTnOgbXXRX4HxaDUi8vo1xGwK4Zx9Mcm9gL4l0cuC8FH7kSkOS5elzNjA== X-Received: by 2002:a05:6402:3889:b0:5c2:2b24:732d with SMTP id 4fb4d7f45d1cf-5c22b247646mr9700969a12.23.1725295128827; Mon, 02 Sep 2024 09:38:48 -0700 (PDT) From: Javi Merino To: xen-devel@lists.xenproject.org Cc: Javi Merino , Anthony PERARD , Juergen Gross Subject: [XEN PATCH v3 3/3] libxl: Update the documentation of libxl_xen_console_read_line() Date: Mon, 2 Sep 2024 17:38:39 +0100 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1725295154402116600 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Anthony PERARD --- tools/include/libxl.h | 2 +- tools/libs/light/libxl_console.c | 29 ++++++++++++++++++----------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/tools/include/libxl.h b/tools/include/libxl.h index f5c71677424b..8d32428ea9fe 100644 --- a/tools/include/libxl.h +++ b/tools/include/libxl.h @@ -2813,7 +2813,7 @@ libxl_xen_console_reader * libxl_xen_console_read_start(libxl_ctx *ctx, int clear); int libxl_xen_console_read_line(libxl_ctx *ctx, libxl_xen_console_reader *cr, - char **line_r); + char **buff); void libxl_xen_console_read_finish(libxl_ctx *ctx, libxl_xen_console_reader *cr); =20 diff --git a/tools/libs/light/libxl_console.c b/tools/libs/light/libxl_cons= ole.c index 6c4414fcc1a2..044ca646765a 100644 --- a/tools/libs/light/libxl_console.c +++ b/tools/libs/light/libxl_console.c @@ -792,17 +792,24 @@ libxl_xen_console_reader * return cr; } =20 -/* 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 - * 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. */ +/* + * Copy part of the console ring into a buffer + * + * Return values: + * 1: Success, *buff points to the string + * 0: No more lines available right now + * -ERROR_* on error + * + * Despite its name, libxl_xen_console_read_line() does not + * necessarily read a complete line. It attempts to fill the buffer + * with as many characters as it can accommodate. The buffer pointed + * to by *buff is updated to contain a nul-terminated string. This + * string remains valid until the next call to + * libxl_xen_console_read_line() on the same console reader. + */ int libxl_xen_console_read_line(libxl_ctx *ctx, libxl_xen_console_reader *cr, - char **line_r) + char **buff) { int ret; /* @@ -823,10 +830,10 @@ int libxl_xen_console_read_line(libxl_ctx *ctx, if (!ret) { if (nr_chars) { cr->buffer[nr_chars] =3D '\0'; - *line_r =3D cr->buffer; + *buff =3D cr->buffer; ret =3D 1; } else { - *line_r =3D NULL; + *buff =3D NULL; ret =3D 0; } } --=20 2.45.2