diff options
author | arsharma <ankitprasad.r.sharma@intel.com> | 2015-02-23 21:31:06 +0000 |
---|---|---|
committer | Adam Jackson <ajax@redhat.com> | 2016-05-02 09:28:51 -0400 |
commit | af2fdf1bdc4532410f49fc0854ae4c0f9086cce9 (patch) | |
tree | 07aea923fcc9f603af3ab304ce7d9b61e52e5153 | |
parent | c1de5dc0541e58372dcddc5120e1e68e03f4f619 (diff) | |
download | xorg-lib-libpciaccess-af2fdf1bdc4532410f49fc0854ae4c0f9086cce9.tar.gz |
vgaarb: add a the trailing NULL character on read(vgaarb_fd)
Issue was spotted by Klocwork, and fixed by arsharma as part of
Android-ia. Not 100% sure if the data read from /dev/vga_arbiter is not
already null terminated, but making sure won't hurt either.
[Emil Velikov: Split from larger patch, write commit message]
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
-rw-r--r-- | src/common_vgaarb.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/common_vgaarb.c b/src/common_vgaarb.c index 7a7d204..515275f 100644 --- a/src/common_vgaarb.c +++ b/src/common_vgaarb.c @@ -126,7 +126,7 @@ int pci_device_vgaarb_init(void) { struct pci_slot_match match; - char buf[BUFSIZE]; + char buf[BUFSIZE + 1]; /* reading BUFSIZE characters, + 1 for NULL */ int ret, rsrc; if (!pci_sys) @@ -140,6 +140,8 @@ pci_device_vgaarb_init(void) if (ret <= 0) return -1; + buf[ret] = 0; /* ret will never be greater than BUFSIZE */ + memset(&match, 0xff, sizeof(match)); /* need to find the device to go back to and what it was decoding */ rsrc = parse_string_to_decodes_rsrc(buf, &pci_sys->vga_count, &match); @@ -226,7 +228,7 @@ int pci_device_vgaarb_set_target(struct pci_device *dev) { int len; - char buf[BUFSIZE]; + char buf[BUFSIZE + 1]; /* reading BUFSIZE characters, + 1 for NULL */ int ret; if (!dev) @@ -245,6 +247,8 @@ pci_device_vgaarb_set_target(struct pci_device *dev) if (ret <= 0) return -1; + buf[ret] = 0; /* ret will never be greater than BUFSIZE */ + dev->vgaarb_rsrc = parse_string_to_decodes_rsrc(buf, &pci_sys->vga_count, NULL); pci_sys->vga_target = dev; return 0; @@ -254,7 +258,7 @@ int pci_device_vgaarb_decodes(int new_vgaarb_rsrc) { int len; - char buf[BUFSIZE]; + char buf[BUFSIZE + 1]; /* reading BUFSIZE characters, + 1 for NULL */ int ret; struct pci_device *dev = pci_sys->vga_target; @@ -272,6 +276,8 @@ pci_device_vgaarb_decodes(int new_vgaarb_rsrc) if (ret <= 0) return -1; + buf[ret] = 0; /* ret will never be greater than BUFSIZE */ + parse_string_to_decodes_rsrc(buf, &pci_sys->vga_count, NULL); return ret; |