From nobody Sat May 4 02:03:20 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1642662027; cv=none; d=zohomail.com; s=zohoarc; b=H+fR7GxrN1ripKvQIAXWUrQmy+GhCUtaayrSjylEhxV7JFMp8FeeUVizCQ3uPnTe6zoKhRqu1FMm2TAg7sYyNRa+XwoFinYnvtXUvlB2eFjGPTa7cc2hwkVdBn2r1FkEAISpM+hZQHzSW3G9jCP6YKFhBOnWHsS51wWJ+Pi9AqE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642662027; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=2KZJ7dpOrpoQgnfImzy80Zel1Z7WNKKERfI5Sl9gGsg=; b=E7weIp+SgyxJ0V6dWCIRXEBpilk7KLEu9JNAiIfzEPXt7X2gkzQbomDASWq7Te5D8FlTkt04O7sfPNkziaetTMW7z1gLF2XuyEhdnzCYerDcOsgR7rrn/VfNhkuuy2slEKtFj/wlOofBgF4m2yoIDobUbrJiLUl/LmUlL+v5mfE= 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=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1642662026924261.5901546642515; Wed, 19 Jan 2022 23:00:26 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.258977.446560 (Exim 4.92) (envelope-from ) id 1nARQG-0004j1-Hw; Thu, 20 Jan 2022 06:59:52 +0000 Received: by outflank-mailman (output) from mailman id 258977.446560; Thu, 20 Jan 2022 06:59:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nARQG-0004iu-Eg; Thu, 20 Jan 2022 06:59:52 +0000 Received: by outflank-mailman (input) for mailman id 258977; Thu, 20 Jan 2022 06:59: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 1nARQF-0004io-RV for xen-devel@lists.xenproject.org; Thu, 20 Jan 2022 06:59:51 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 8f7d965c-79be-11ec-8fa7-f31e035a9116; Thu, 20 Jan 2022 07:59:50 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id A82321F391; Thu, 20 Jan 2022 06:59:49 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 7323913CFB; Thu, 20 Jan 2022 06:59:49 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id oaxVGmUI6WG0eQAAMHmgww (envelope-from ); Thu, 20 Jan 2022 06:59:49 +0000 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: 8f7d965c-79be-11ec-8fa7-f31e035a9116 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1642661989; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=2KZJ7dpOrpoQgnfImzy80Zel1Z7WNKKERfI5Sl9gGsg=; b=mlicGFTyn5+v/dVBkz9rp/r3LFNJGxAISEEb5sytWveoC05SqABTlHfrOHosFx+s2MQa9B +PSCvPZ/4jxN3aZnPACxx6PGnhj0H/ADfCDOEs4bDxSlD3QhWNsGox8/ZqLwXWk2F2P2oo yBkbzzwt4q4e2penQwALQCGufrkB8zA= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH] tools/xenstore: use talloc_asprintf_append() in do_control_help() Date: Thu, 20 Jan 2022 07:59:47 +0100 Message-Id: <20220120065947.31587-1-jgross@suse.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1642662028003100001 Content-Type: text/plain; charset="utf-8" Instead of calculating the length of all help output and then allocating the space for it, just use talloc_asprintf_append() to expand the text as needed. Signed-off-by: Juergen Gross Reviewed-by: Anthony PERARD --- tools/xenstore/xenstored_control.c | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/tools/xenstore/xenstored_control.c b/tools/xenstore/xenstored_= control.c index adb8d51b04..61bcbc069d 100644 --- a/tools/xenstore/xenstored_control.c +++ b/tools/xenstore/xenstored_control.c @@ -853,36 +853,23 @@ static struct cmd_s cmds[] =3D { static int do_control_help(void *ctx, struct connection *conn, char **vec, int num) { - int cmd, len =3D 0; + int cmd; char *resp; =20 if (num) return EINVAL; =20 - for (cmd =3D 0; cmd < ARRAY_SIZE(cmds); cmd++) { - len +=3D strlen(cmds[cmd].cmd) + 1; - len +=3D strlen(cmds[cmd].pars) + 1; - } - len++; - - resp =3D talloc_array(ctx, char, len); + resp =3D talloc_asprintf(ctx, "%s", ""); if (!resp) return ENOMEM; - - len =3D 0; for (cmd =3D 0; cmd < ARRAY_SIZE(cmds); cmd++) { - strcpy(resp + len, cmds[cmd].cmd); - len +=3D strlen(cmds[cmd].cmd); - resp[len] =3D '\t'; - len++; - strcpy(resp + len, cmds[cmd].pars); - len +=3D strlen(cmds[cmd].pars); - resp[len] =3D '\n'; - len++; + resp =3D talloc_asprintf_append(resp, "%s\t%s\n", + cmds[cmd].cmd, cmds[cmd].pars); + if (!resp) + return ENOMEM; } - resp[len] =3D 0; =20 - send_reply(conn, XS_CONTROL, resp, len); + send_reply(conn, XS_CONTROL, resp, strlen(resp) + 1); return 0; } =20 --=20 2.31.1