From nobody Wed Nov 27 05:32:59 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