[libvirt] [PATCH V2 0/2] Various coverity fixes

Coverity fixes from a previous post split into individual patches. Regards, Stefan

Error: STRING_NULL: /libvirt/src/util/uuid.c:273: string_null_argument: Function "getDMISystemUUID" does not terminate string "*dmiuuid". /libvirt/src/util/uuid.c:241: string_null_argument: Function "saferead" fills array "*uuid" with a non-terminated string. /libvirt/src/util/util.c:101: string_null_argument: Function "read" fills array "*buf" with a non-terminated string. /libvirt/src/util/uuid.c:274: string_null: Passing unterminated string "dmiuuid" to a function expecting a null-terminated string. /libvirt/src/util/uuid.c:138: var_assign_parm: Assigning: "cur" = "uuidstr". They now point to the same thing. /libvirt/src/util/uuid.c:164: string_null_sink_loop: Searching for null termination in an unterminated array "cur". --- src/util/uuid.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) Index: libvirt-acl/src/util/uuid.c =================================================================== --- libvirt-acl.orig/src/util/uuid.c +++ libvirt-acl/src/util/uuid.c @@ -238,7 +238,8 @@ getDMISystemUUID(char *uuid, int len) while (paths[i]) { int fd = open(paths[i], O_RDONLY); if (fd >= 0) { - if (saferead(fd, uuid, len) == len) { + if (saferead(fd, uuid, len - 1) == len - 1) { + uuid[len - 1] = '\0'; VIR_FORCE_CLOSE(fd); return 0; } @@ -270,7 +271,7 @@ virSetHostUUIDStr(const char *uuid) if (!uuid) { memset(dmiuuid, 0, sizeof(dmiuuid)); - if (!getDMISystemUUID(dmiuuid, sizeof(dmiuuid) - 1)) { + if (!getDMISystemUUID(dmiuuid, sizeof(dmiuuid))) { if (!virUUIDParse(dmiuuid, host_uuid)) return 0; }

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. --- src/node_device/node_device_linux_sysfs.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) Index: libvirt-acl/src/node_device/node_device_linux_sysfs.c =================================================================== --- libvirt-acl.orig/src/node_device/node_device_linux_sysfs.c +++ libvirt-acl/src/node_device/node_device_linux_sysfs.c @@ -70,14 +70,13 @@ int read_wwn_linux(int host, const char { 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);

On 05/04/2012 10:48 AM, Stefan Berger wrote:
Coverity fixes from a previous post split into individual patches.
ACK series. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
participants (2)
-
Eric Blake
-
Stefan Berger