[libvirt] [PATCH] uuid: fix off-by-one

Detected by Coverity. Although unlikely, if we are ever started with stdin closed, we could reach a situation where we open a uuid file but then fail to close it, making that file the new stdin for the rest of the process. * src/util/uuid.c (getDMISystemUUID): Allow for stdin. --- src/util/uuid.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/uuid.c b/src/util/uuid.c index 823a2b9..15ba5af 100644 --- a/src/util/uuid.c +++ b/src/util/uuid.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007-2011 Red Hat, Inc. + * Copyright (C) 2007-2012 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -236,7 +236,7 @@ getDMISystemUUID(char *uuid, int len) while (paths[i]) { int fd = open(paths[i], O_RDONLY); - if (fd > 0) { + if (fd >= 0) { if (saferead(fd, uuid, len) == len) { VIR_FORCE_CLOSE(fd); return 0; -- 1.7.7.5

On 12.01.2012 01:46, Eric Blake wrote:
Detected by Coverity. Although unlikely, if we are ever started with stdin closed, we could reach a situation where we open a uuid file but then fail to close it, making that file the new stdin for the rest of the process.
* src/util/uuid.c (getDMISystemUUID): Allow for stdin. --- src/util/uuid.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
ACK Michal

On 01/12/2012 01:30 AM, Michal Privoznik wrote:
On 12.01.2012 01:46, Eric Blake wrote:
Detected by Coverity. Although unlikely, if we are ever started with stdin closed, we could reach a situation where we open a uuid file but then fail to close it, making that file the new stdin for the rest of the process.
* src/util/uuid.c (getDMISystemUUID): Allow for stdin. --- src/util/uuid.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
ACK
Thanks; pushed. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
participants (2)
-
Eric Blake
-
Michal Privoznik