From patchwork Sat Jul 7 23:23:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rodrigo Siqueira X-Patchwork-Id: 10512975 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6B100603D7 for ; Sat, 7 Jul 2018 23:23:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5A962288E1 for ; Sat, 7 Jul 2018 23:23:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4F1BE288EA; Sat, 7 Jul 2018 23:23:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0A097288E1 for ; Sat, 7 Jul 2018 23:23:35 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8FC6D6E35A; Sat, 7 Jul 2018 23:23:34 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-qt0-x241.google.com (mail-qt0-x241.google.com [IPv6:2607:f8b0:400d:c0d::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id DE7186E35A; Sat, 7 Jul 2018 23:23:33 +0000 (UTC) Received: by mail-qt0-x241.google.com with SMTP id f1-v6so12808715qti.3; Sat, 07 Jul 2018 16:23:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=iozdQpO0kdnclJqbppjON5hqDr3Braocr9SVwVqyIHE=; b=CVmY9Qbg8VNMMBO+HPDqfF54Ku9MIGNhtAMLtZ3vdU9fTxllTNA9de1DQPf7fSCsCN L7H+stM+xhAxCI01pqyuUMKHG4tsxgrOyd+0Mzgov0p3D6F6/jHjdVl7KCw1b8JAp71R wGMqdjo6lzdDRc/Kd4tqAtf19xhrw5gnKdWeZCL1i2FSSQsefmetLH7PMjE+8QGwF0ee y96ruOOz0rYJDeJDYVCb2iApmD4D9wpVsGS6rjcf5V2ZA3WsnXP/c/xSGBQJS+c/LBZU JNBUCB31M9P5USWOxEWGU8mRnfTwOsX3QJzAQm4YzCogaWoc0FgiYn/KHOyuHcb8XWp5 KyfA== X-Gm-Message-State: APt69E3eZNT7Ms/cMxr0DwbkuyHyCbGXkQXQANACcWe6mISl1GoacDcG ddpNAGYLplmD5pDROwHk18s= X-Google-Smtp-Source: AAOMgpcKHxpmZfR7FNRkK/PtwoLRtx2C0CRpvU/qOqvlsuT7meUzAu0Proz7vysiO/fjVSp01BSGcw== X-Received: by 2002:a0c:e2c4:: with SMTP id t4-v6mr13403780qvl.167.1531005813094; Sat, 07 Jul 2018 16:23:33 -0700 (PDT) Received: from smtp.gmail.com ([143.107.45.1]) by smtp.gmail.com with ESMTPSA id m4-v6sm8936109qtm.79.2018.07.07.16.23.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 07 Jul 2018 16:23:32 -0700 (PDT) Date: Sat, 7 Jul 2018 20:23:30 -0300 From: Rodrigo Siqueira To: Petri Latvala , Arkadiusz Hiler Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180622 Subject: [Intel-gfx] [PATCH i-g-t 5/7] Make string commands dynamic allocate X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: igt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP This patch fix the following GCC warning: intel_gvtg_test.c: In function ‘create_guest’: intel_gvtg_test.c:127:50: warning: ‘%s’ directive writing up to 4095 bytes into a region of size 4077 [-Wformat-overflow=] [..] intel_gvtg_test.c:127:5: note: ‘sprintf’ output between 36 and 8226 bytes into a destination of size 4096 [..] This patch changes the approach for allocating memory to handle QEMU commands by dynamically allocate space to save the whole command. Signed-off-by: Rodrigo Siqueira --- tools/intel_gvtg_test.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/tools/intel_gvtg_test.c b/tools/intel_gvtg_test.c index 659b7956..93c05e37 100644 --- a/tools/intel_gvtg_test.c +++ b/tools/intel_gvtg_test.c @@ -120,16 +120,25 @@ static int check_tools(void) static void create_guest(void) { - char create_qcow_cmd[PATH_MAX] = {0}; - char create_vgpu_cmd[PATH_MAX] = {0}; - char create_instance_cmd[PATH_MAX] = {0}; + unsigned int max_size_cmd = sysconf(_SC_ARG_MAX); + char *command; - sprintf(create_qcow_cmd, "qemu-img create -b %s -f qcow2 %s.qcow2", + command = malloc(max_size_cmd); + if (!command) + return; + + sprintf(command, "qemu-img create -b %s -f qcow2 %s.qcow2", hda_path, hda_path); - sprintf(create_vgpu_cmd, "echo \"%s\" > /sys/bus/pci/devices/0000:00:02.0/" + igt_assert_eq(system(command), 0); + memset(command, 0, max_size_cmd); + + sprintf(command, "echo \"%s\" > /sys/bus/pci/devices/0000:00:02.0/" "mdev_supported_types/$(ls /sys/bus/pci/devices/0000:00:02.0/" "mdev_supported_types |awk {'print $1'}|tail -1)/create", uuid); - sprintf(create_instance_cmd, "%s -m 2048 -smp 2 -M pc -name gvtg_guest" + igt_assert_eq(system(command), 0); + memset(command, 0, max_size_cmd); + + sprintf(command, "%s -m 2048 -smp 2 -M pc -name gvtg_guest" " -hda %s.qcow2 -bios %s -enable-kvm --net nic,macaddr=%s -net" " tap,script=/etc/qemu-ifup -vga cirrus -k en-us" " -serial stdio -vnc :1 -machine kernel_irqchip=on -global" @@ -137,9 +146,9 @@ static void create_guest(void) " -usb -usbdevice tablet -device vfio-pci,sysfsdev=" "/sys/bus/pci/devices/0000:00:02.0/%s &", qemu_path, hda_path, bios_path, mac_addr, uuid); - igt_assert_eq(system(create_qcow_cmd), 0); - igt_assert_eq(system(create_vgpu_cmd), 0); - igt_assert_eq(system(create_instance_cmd), 0); + igt_assert_eq(system(command), 0); + + free(command); } static void destroy_all_guest(void)