From: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com> To: Petri Latvala <petri.latvala@intel.com>, Arkadiusz Hiler <arkadiusz.hiler@intel.com> Cc: igt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org Subject: [PATCH i-g-t 5/7] Make string commands dynamic allocate Date: Sat, 7 Jul 2018 20:23:30 -0300 [thread overview] Message-ID: <f8ae302060dc9cd7640199f3dca0a275f3351968.1531005542.git.rodrigosiqueiramelo@gmail.com> (raw) In-Reply-To: <cover.1531005542.git.rodrigosiqueiramelo@gmail.com> 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 <rodrigosiqueiramelo@gmail.com> --- 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) -- 2.18.0 _______________________________________________ Intel-gfx mailing list Intel-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/intel-gfx
WARNING: multiple messages have this Message-ID (diff)
From: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com> To: Petri Latvala <petri.latvala@intel.com>, Arkadiusz Hiler <arkadiusz.hiler@intel.com> Cc: igt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org Subject: [Intel-gfx] [PATCH i-g-t 5/7] Make string commands dynamic allocate Date: Sat, 7 Jul 2018 20:23:30 -0300 [thread overview] Message-ID: <f8ae302060dc9cd7640199f3dca0a275f3351968.1531005542.git.rodrigosiqueiramelo@gmail.com> (raw) In-Reply-To: <cover.1531005542.git.rodrigosiqueiramelo@gmail.com> 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 <rodrigosiqueiramelo@gmail.com> --- 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) -- 2.18.0 _______________________________________________ Intel-gfx mailing list Intel-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/intel-gfx
next prev parent reply other threads:[~2018-07-07 23:23 UTC|newest] Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-07-07 23:22 [PATCH i-g-t 0/7] GCC warning cleanup Rodrigo Siqueira 2018-07-07 23:22 ` [igt-dev] " Rodrigo Siqueira 2018-07-07 23:22 ` [PATCH i-g-t 1/7] Remove parameter aliases with another argument Rodrigo Siqueira 2018-07-07 23:22 ` [igt-dev] " Rodrigo Siqueira 2018-07-10 13:50 ` Arkadiusz Hiler 2018-07-10 13:50 ` [Intel-gfx] " Arkadiusz Hiler 2018-07-07 23:22 ` [PATCH i-g-t 2/7] Cast void * pointer used in arithmetic to uint32_t* Rodrigo Siqueira 2018-07-07 23:22 ` [Intel-gfx] " Rodrigo Siqueira 2018-07-10 13:58 ` Arkadiusz Hiler 2018-07-10 13:58 ` [igt-dev] " Arkadiusz Hiler 2018-07-10 14:09 ` Chris Wilson 2018-07-10 14:09 ` [Intel-gfx] " Chris Wilson 2018-07-10 14:38 ` Arkadiusz Hiler 2018-07-10 14:38 ` Arkadiusz Hiler 2018-07-10 14:43 ` Chris Wilson 2018-07-10 14:43 ` [Intel-gfx] " Chris Wilson 2018-07-11 1:58 ` Rodrigo Siqueira 2018-07-11 1:58 ` Rodrigo Siqueira 2018-07-07 23:22 ` [PATCH i-g-t 3/7] Fix comparison that always evaluates to false Rodrigo Siqueira 2018-07-07 23:22 ` [igt-dev] " Rodrigo Siqueira 2018-07-07 23:23 ` [PATCH i-g-t 4/7] Fix truncate string in the snprintf Rodrigo Siqueira 2018-07-07 23:23 ` [igt-dev] " Rodrigo Siqueira 2018-07-10 14:07 ` Arkadiusz Hiler 2018-07-10 14:07 ` [igt-dev] " Arkadiusz Hiler 2018-07-07 23:23 ` Rodrigo Siqueira [this message] 2018-07-07 23:23 ` [Intel-gfx] [PATCH i-g-t 5/7] Make string commands dynamic allocate Rodrigo Siqueira 2018-07-11 12:26 ` Arkadiusz Hiler 2018-07-11 12:26 ` [igt-dev] " Arkadiusz Hiler 2018-07-07 23:23 ` [PATCH i-g-t 6/7] Fix truncate string in the strncpy Rodrigo Siqueira 2018-07-07 23:23 ` [igt-dev] " Rodrigo Siqueira 2018-07-07 23:23 ` [PATCH i-g-t 7/7] Avoid truncate string in __igt_lsof_fds Rodrigo Siqueira 2018-07-07 23:23 ` [Intel-gfx] " Rodrigo Siqueira 2018-07-07 23:46 ` [igt-dev] ✓ Fi.CI.BAT: success for GCC warning cleanup Patchwork 2018-07-08 6:55 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=f8ae302060dc9cd7640199f3dca0a275f3351968.1531005542.git.rodrigosiqueiramelo@gmail.com \ --to=rodrigosiqueiramelo@gmail.com \ --cc=arkadiusz.hiler@intel.com \ --cc=igt-dev@lists.freedesktop.org \ --cc=intel-gfx@lists.freedesktop.org \ --cc=petri.latvala@intel.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.