From: Stefan Berger Date: Fri, 4 May 2012 17:22:22 +0000 (-0400) Subject: node_device: fix possible non-terminated string X-Git-Tag: v0.9.12-rc2~27 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=43d1616ff59eb6dd5d1f484d1e9de9133ca034a6;p=thirdparty%2Flibvirt.git node_device: fix possible non-terminated string Error: STRING_NULL: /libvirt/src/node_device/node_device_linux_sysfs.c:80: string_null_argument: Function "saferead" does not terminate string "*buf". /libvirt/src/util/util.c:101: string_null_argument: Function "read" fills array "*buf" with a non-terminated string. /libvirt/src/node_device/node_device_linux_sysfs.c:87: string_null: Passing unterminated string "buf" to a function expecting a null-terminated string. --- diff --git a/src/node_device/node_device_linux_sysfs.c b/src/node_device/node_device_linux_sysfs.c index 380be9c61b..6df73a389b 100644 --- a/src/node_device/node_device_linux_sysfs.c +++ b/src/node_device/node_device_linux_sysfs.c @@ -70,14 +70,13 @@ int read_wwn_linux(int host, const char *file, char **wwn) { char *p = NULL; int fd = -1, retval = 0; - char buf[64]; + char buf[65] = ""; if (open_wwn_file(LINUX_SYSFS_FC_HOST_PREFIX, host, file, &fd) < 0) { goto out; } - memset(buf, 0, sizeof(buf)); - if (saferead(fd, buf, sizeof(buf)) < 0) { + if (saferead(fd, buf, sizeof(buf) - 1) < 0) { retval = -1; VIR_DEBUG("Failed to read WWN for host%d '%s'", host, file);