From nobody Sun May 19 04:05:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1653989904; cv=none; d=zohomail.com; s=zohoarc; b=GkSSLBXEa6F+KS3x8367TznVh+kLDGzZ2tRMP37rhKXII0DlYKu7g6avRDLJn+GT6y8VAnHZYg/1FzNCKgl8PDzQCG0QULck0D05gfZcp5GeqknOUSIxl2LKYcWmVLB5DtQewYFs0R/8ENhB6hlQoU3c7T6Xq3ORIFl5ZGKDL9E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653989904; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=BMyW7YvYfdXoUUQ6CLwB02Lx4UJvEtP1magnfsvicy0=; b=TaC487qhSX8CAbwjZNHmF9BJD/tjX9/Z4idEcFfn8nhT5nwF7y+ofGajyo0WNm/ayGEiO4DUoQBRFoJrx7/OblXxjg6/bOxFnnloYO7avdsHBLc/6OXYPryRd9Vk6Df5R5RWv32TaiqC7OLNAVDf2NFd2KyDdjC3EH7vVCftUIU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653989904931884.6970037872371; Tue, 31 May 2022 02:38:24 -0700 (PDT) Received: from localhost ([::1]:55546 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nvyKV-0007YK-IZ for importer@patchew.org; Tue, 31 May 2022 05:38:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52718) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nvy8h-0008Ix-W3 for qemu-devel@nongnu.org; Tue, 31 May 2022 05:26:12 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:39846) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nvy8X-0008AD-MO for qemu-devel@nongnu.org; Tue, 31 May 2022 05:26:11 -0400 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 0D4241F97B; Tue, 31 May 2022 09:25:58 +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 CCA3A132F9; Tue, 31 May 2022 09:25:57 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id nNtaMCXflWIBEQAAMHmgww (envelope-from ); Tue, 31 May 2022 09:25:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1653989158; 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=BMyW7YvYfdXoUUQ6CLwB02Lx4UJvEtP1magnfsvicy0=; b=S4X4Sp86n4Rf+1C0G1UB0pVtVXjdJzy4HIK6rQ7K6HYIm/g7dEL7Oy3g5/XahfgnwRyI8/ ymru9s2CTZ/yUDQVeDav5lM294q9SqrCmufKPI32NbUVLc5TNjQA1GjqXUJi28tgLVwjnn i/YzBpToA+c7e45+EEdT1sZuY12KopQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1653989158; 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=BMyW7YvYfdXoUUQ6CLwB02Lx4UJvEtP1magnfsvicy0=; b=0Nbyj5bIxkZV8zmwh4WYZ+/FLzBP10GC3LvqAmDQ7BA2vWGW0E2Rtuyz97sQ0EiFkSvAPp AyfXuoBocLdKqzDQ== From: Claudio Fontana To: "Michael S. Tsirkin" Cc: Marcel Apfelbaum , qemu-devel@nongnu.org, Dario Faggioli , Claudio Fontana Subject: [PATCH] pci: fix overflow in printf string formatting Date: Tue, 31 May 2022 11:25:39 +0200 Message-Id: <20220531092540.10151-1-cfontana@suse.de> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=195.135.220.29; envelope-from=cfontana@suse.de; helo=smtp-out2.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1653989905621100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Claudio Fontana --- hw/pci/pci.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index a9b37f8000..6e7015329c 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -2640,15 +2640,15 @@ static char *pci_dev_fw_name(DeviceState *dev, char= *buf, int len) static char *pcibus_get_fw_dev_path(DeviceState *dev) { PCIDevice *d =3D (PCIDevice *)dev; - char path[50], name[33]; - int off; - - off =3D snprintf(path, sizeof(path), "%s@%x", - pci_dev_fw_name(dev, name, sizeof name), - PCI_SLOT(d->devfn)); - if (PCI_FUNC(d->devfn)) - snprintf(path + off, sizeof(path) + off, ",%x", PCI_FUNC(d->devfn)= ); - return g_strdup(path); + char name[33]; + int has_func =3D !!PCI_FUNC(d->devfn); + + return g_strdup_printf("%s@%x%s%.*x", + pci_dev_fw_name(dev, name, sizeof(name)), + PCI_SLOT(d->devfn), + has_func ? "," : "", + has_func, + PCI_FUNC(d->devfn)); } =20 static char *pcibus_get_dev_path(DeviceState *dev) --=20 2.26.2