[Libvir] [PATCH] Handle failed openvzLocateConfDir.

While looking at misuses of write, I found problems in src/openvz_conf.c Here's the first fix: Handle failed openvzLocateConfDir. * src/openvz_conf.c (openvzLocateConfDir, openvzGetVPSUUID): (openvzSetUUID): Don't dereference NULL upon failure. Signed-off-by: Jim Meyering <meyering@redhat.com> --- src/openvz_conf.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-) diff --git a/src/openvz_conf.c b/src/openvz_conf.c index 482de82..fb38b43 100644 --- a/src/openvz_conf.c +++ b/src/openvz_conf.c @@ -641,6 +641,8 @@ openvzGetVPSUUID(int vpsid, char *uuidstr) int fd, ret; conf_dir = openvzLocateConfDir(); + if (conf_dir != NULL) + return -1 sprintf(conf_file, "%s/%d.conf", conf_dir, vpsid); free(conf_dir); @@ -681,6 +683,8 @@ openvzSetUUID(int vpsid) int fd, ret; conf_dir = openvzLocateConfDir(); + if (conf_dir != NULL) + return -1; sprintf(conf_file, "%s/%d.conf", conf_dir, vpsid); free(conf_dir); @@ -722,6 +726,8 @@ int openvzAssignUUIDs(void) char ext[8]; conf_dir = openvzLocateConfDir(); + if (conf_dir != NULL) + return -1; dp = opendir(conf_dir); if(dp == NULL) { -- 1.5.4.2.134.g82883

Jim Meyering <jim@meyering.net> wrote:
While looking at misuses of write, I found problems in src/openvz_conf.c Here's the first fix:
Handle failed openvzLocateConfDir. * src/openvz_conf.c (openvzLocateConfDir, openvzGetVPSUUID): (openvzSetUUID): Don't dereference NULL upon failure.
Signed-off-by: Jim Meyering <meyering@redhat.com> --- src/openvz_conf.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/src/openvz_conf.c b/src/openvz_conf.c index 482de82..fb38b43 100644 --- a/src/openvz_conf.c +++ b/src/openvz_conf.c @@ -641,6 +641,8 @@ openvzGetVPSUUID(int vpsid, char *uuidstr) int fd, ret;
conf_dir = openvzLocateConfDir(); + if (conf_dir != NULL) + return -1
Oops. Notice that missing semicolon. That's because the fix is in the subsequent patch. I'm redoing them now so they're independent. FYI, with this series of three, all tests did pass.

Jim Meyering <jim@meyering.net> wrote:
While looking at misuses of write, I found problems in src/openvz_conf.c Here's the first fix:
Handle failed openvzLocateConfDir. * src/openvz_conf.c (openvzLocateConfDir, openvzGetVPSUUID): (openvzSetUUID): Don't dereference NULL upon failure.
Signed-off-by: Jim Meyering <meyering@redhat.com> --- src/openvz_conf.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/src/openvz_conf.c b/src/openvz_conf.c index 482de82..fb38b43 100644 --- a/src/openvz_conf.c +++ b/src/openvz_conf.c @@ -641,6 +641,8 @@ openvzGetVPSUUID(int vpsid, char *uuidstr) int fd, ret;
conf_dir = openvzLocateConfDir(); + if (conf_dir != NULL) + return -1
Whoa. Chris Lalance pointed out another obvious flaw. I meant to add *this*:
+ if (conf_dir == NULL) + return -1
Will repost shortly. Thanks, Chris!

Jim Meyering <jim@meyering.net> wrote: ...
+ if (conf_dir != NULL) + return -1
Whoa. Chris Lalance pointed out another obvious flaw. I meant to add *this*:
+ if (conf_dir == NULL) + return -1
Will repost shortly. Thanks, Chris!
Here's the corrected patch: Handle failed openvzLocateConfDir. * src/openvz_conf.c (openvzLocateConfDir, openvzGetVPSUUID): (openvzSetUUID): Don't dereference NULL upon failure. Signed-off-by: Jim Meyering <meyering@redhat.com> --- src/openvz_conf.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-) diff --git a/src/openvz_conf.c b/src/openvz_conf.c index 482de82..a274223 100644 --- a/src/openvz_conf.c +++ b/src/openvz_conf.c @@ -641,6 +641,8 @@ openvzGetVPSUUID(int vpsid, char *uuidstr) int fd, ret; conf_dir = openvzLocateConfDir(); + if (conf_dir == NULL) + return -1; sprintf(conf_file, "%s/%d.conf", conf_dir, vpsid); free(conf_dir); @@ -681,6 +683,8 @@ openvzSetUUID(int vpsid) int fd, ret; conf_dir = openvzLocateConfDir(); + if (conf_dir == NULL) + return -1; sprintf(conf_file, "%s/%d.conf", conf_dir, vpsid); free(conf_dir); @@ -722,6 +726,8 @@ int openvzAssignUUIDs(void) char ext[8]; conf_dir = openvzLocateConfDir(); + if (conf_dir == NULL) + return -1; dp = opendir(conf_dir); if(dp == NULL) { -- 1.5.4.2.134.g82883

On Wed, Feb 20, 2008 at 03:23:52PM +0100, Jim Meyering wrote:
Jim Meyering <jim@meyering.net> wrote: ...
+ if (conf_dir != NULL) + return -1
Whoa. Chris Lalance pointed out another obvious flaw. I meant to add *this*:
+ if (conf_dir == NULL) + return -1
Will repost shortly. Thanks, Chris!
Here's the corrected patch:
Okay, curiously I didn't spotted those problems :-\ Daniel -- Red Hat Virtualization group http://redhat.com/virtualization/ Daniel Veillard | virtualization library http://libvirt.org/ veillard@redhat.com | libxml GNOME XML XSLT toolkit http://xmlsoft.org/ http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/

On Wed, Feb 20, 2008 at 02:56:06PM +0100, Jim Meyering wrote:
While looking at misuses of write, I found problems in src/openvz_conf.c Here's the first fix:
Handle failed openvzLocateConfDir. * src/openvz_conf.c (openvzLocateConfDir, openvzGetVPSUUID): (openvzSetUUID): Don't dereference NULL upon failure.
Looks fine to me +1, Daniel -- Red Hat Virtualization group http://redhat.com/virtualization/ Daniel Veillard | virtualization library http://libvirt.org/ veillard@redhat.com | libxml GNOME XML XSLT toolkit http://xmlsoft.org/ http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/
participants (2)
-
Daniel Veillard
-
Jim Meyering