From 3945bc4c40a9109ff6c62aea3e697a182cbacdb7 Mon Sep 17 00:00:00 2001 From: Conghui Chen Date: Thu, 25 Jul 2019 10:08:50 +0000 Subject: [PATCH] dm: array bound and NULL pointer issue fix Remove the possible NULL pointer access code for virtio-console.c Add '\0' to end of native_patch[], to avoid the potential issue when using %s to print the array for virtio-i2c.c Tracked-On: #3467 Signed-off-by: Conghui Chen Reviewed-by: Yonghua Huang --- devicemodel/hw/pci/virtio/virtio_console.c | 2 +- devicemodel/hw/pci/virtio/virtio_i2c.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/devicemodel/hw/pci/virtio/virtio_console.c b/devicemodel/hw/pci/virtio/virtio_console.c index 1818a422d..c7e5832a4 100644 --- a/devicemodel/hw/pci/virtio/virtio_console.c +++ b/devicemodel/hw/pci/virtio/virtio_console.c @@ -619,7 +619,7 @@ virtio_console_open_backend(const char *path, case VIRTIO_CONSOLE_BE_SOCKET: fd = socket(AF_UNIX, SOCK_STREAM, 0); if (fd < 0) - WPRINTF(("vtcon: socket open failed: %s\n", path)); + WPRINTF(("vtcon: socket open failed \n")); break; default: WPRINTF(("not supported backend %d!\n", be_type)); diff --git a/devicemodel/hw/pci/virtio/virtio_i2c.c b/devicemodel/hw/pci/virtio/virtio_i2c.c index 023783e20..9de044640 100644 --- a/devicemodel/hw/pci/virtio/virtio_i2c.c +++ b/devicemodel/hw/pci/virtio/virtio_i2c.c @@ -444,6 +444,8 @@ native_adapter_create(int bus, uint16_t slave_addr[], int n_slave) } snprintf(native_path, sizeof(native_path), "/dev/i2c-%d", bus); + native_path[sizeof(native_path) - 1] = '\0'; + fd = open(native_path, O_RDWR); if (fd < 0) { WPRINTF("virtio_i2c: failed to open %s\n", native_path);