* [PATCH v2 i-g-t 1/2] Make string commands dynamic allocate
2018-07-29 12:41 [PATCH v2 i-g-t 0/2] Fix some GCC warnings Rodrigo Siqueira
@ 2018-07-29 12:41 ` Rodrigo Siqueira
2018-07-29 12:41 ` [PATCH v2 i-g-t 2/2] Fix truncate string in the snprintf Rodrigo Siqueira
2018-08-20 13:39 ` [PATCH v2 i-g-t 0/2] Fix some GCC warnings Rodrigo Siqueira
2 siblings, 0 replies; 4+ messages in thread
From: Rodrigo Siqueira @ 2018-07-29 12:41 UTC (permalink / raw)
To: Petri Latvala, Arkadiusz Hiler; +Cc: igt-dev, intel-gfx
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.
Changes since v1:
Arkadiusz Hiler:
- Remove overkill allocation for handling commands
- Remove unnecessary use of memset
Signed-off-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
---
tools/intel_gvtg_test.c | 25 ++++++++++++++++---------
1 file changed, 16 insertions(+), 9 deletions(-)
diff --git a/tools/intel_gvtg_test.c b/tools/intel_gvtg_test.c
index 659b7956..ad5ee6a6 100644
--- a/tools/intel_gvtg_test.c
+++ b/tools/intel_gvtg_test.c
@@ -120,16 +120,23 @@ 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 = 4 * PATH_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);
+
+ 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);
+
+ 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 +144,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.17.0
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH v2 i-g-t 2/2] Fix truncate string in the snprintf
2018-07-29 12:41 [PATCH v2 i-g-t 0/2] Fix some GCC warnings Rodrigo Siqueira
2018-07-29 12:41 ` [PATCH v2 i-g-t 1/2] Make string commands dynamic allocate Rodrigo Siqueira
@ 2018-07-29 12:41 ` Rodrigo Siqueira
2018-08-20 13:39 ` [PATCH v2 i-g-t 0/2] Fix some GCC warnings Rodrigo Siqueira
2 siblings, 0 replies; 4+ messages in thread
From: Rodrigo Siqueira @ 2018-07-29 12:41 UTC (permalink / raw)
To: Petri Latvala, Arkadiusz Hiler; +Cc: igt-dev, intel-gfx
This patch fix the following GCC warning:
../tools/intel_reg.c: In function ‘dump_decode’:
../tools/intel_reg.c:203:41: warning: ‘snprintf’ output may be truncated
before the last format character [-Wformat-truncation=]
snprintf(decode, sizeof(decode), "\n%s", bin);
[..]
../tools/intel_reg.c:200:40: warning: ‘%s’ directive output may be
truncated writing up to 1023 bytes into a region of size 1022
[-Wformat-truncation=]
snprintf(decode, sizeof(decode), " (%s)\n%s", tmp, bin);
[..]
../tools/intel_reg.c:200:4: note: ‘snprintf’ output between 5 and 2051
bytes into a destination of size 1024
snprintf(decode, sizeof(decode), " (%s)\n%s", tmp, bin);
[..]
Notice that snprintf writes in the decode variable the values from tmp
and bin. These two variables together have 2048 bytes and some extra
characters added by snprintf, this commit changed the size of decode to
support the combination.
Changes since V1:
- Improve commit message
Signed-off-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
---
tools/intel_reg.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/intel_reg.c b/tools/intel_reg.c
index ddff2794..15ebb86a 100644
--- a/tools/intel_reg.c
+++ b/tools/intel_reg.c
@@ -180,7 +180,7 @@ static void to_binary(char *buf, size_t buflen, uint32_t val)
static void dump_decode(struct config *config, struct reg *reg, uint32_t val)
{
- char decode[1024];
+ char decode[2060];
char tmp[1024];
char bin[1024];
--
2.17.0
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply related [flat|nested] 4+ messages in thread