[netcf-devel] [PATCH] Be sure to bail if get_augeas() fails

Laine Stump laine at laine.org
Thu Sep 13 19:39:24 UTC 2012


There were a few places where get_augeas() was called at the beginning
of a function, but the function was allowed to continue as normal even
if get_augeas() failed. This was disastrous if any augeas library
function was subsequently called prior to checking for error status -
get_augeas sets ncf->driver->augeas to NULL if there's an error, but
aug_get/aug_put/aug_rm (and possibly others) dereference the aug
pointer they are sent without checking for NULL.

This patch assures that any caller of get_augeas() returns immediately
if get_augeas() fails.
---
 src/drv_debian.c  |  4 +++-
 src/drv_redhat.c  |  4 +++-
 src/drv_suse.c    |  4 +++-
 src/dutil_linux.c | 10 +++++++++-
 4 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/src/drv_debian.c b/src/drv_debian.c
index 04953e3..1856d69 100644
--- a/src/drv_debian.c
+++ b/src/drv_debian.c
@@ -1,7 +1,7 @@
 /*
  * drv_initscripts.c: the initscripts backend for netcf
  *
- * Copyright (C) 2009 Red Hat Inc.
+ * Copyright (C) 2009-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
@@ -906,6 +906,8 @@ struct netcf_if *drv_define(struct netcf *ncf, const char *xml_str) {
     int r;
     struct augeas *aug = get_augeas(ncf);
 
+    ERR_BAIL(ncf);
+
     ncf_xml = parse_xml(ncf, xml_str);
     ERR_BAIL(ncf);
 
diff --git a/src/drv_redhat.c b/src/drv_redhat.c
index 06ad42a..40658dd 100644
--- a/src/drv_redhat.c
+++ b/src/drv_redhat.c
@@ -1,7 +1,7 @@
 /*
  * drv_redhat.c: the Red Hat distro family backend for netcf
  *
- * Copyright (C) 2009 Red Hat Inc.
+ * Copyright (C) 2009-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
@@ -866,6 +866,8 @@ struct netcf_if *drv_define(struct netcf *ncf, const char *xml_str) {
     int r;
     struct augeas *aug = get_augeas(ncf);
 
+    ERR_BAIL(ncf);
+
     ncf_xml = parse_xml(ncf, xml_str);
     ERR_BAIL(ncf);
 
diff --git a/src/drv_suse.c b/src/drv_suse.c
index 7b3aa20..f88764c 100644
--- a/src/drv_suse.c
+++ b/src/drv_suse.c
@@ -2,7 +2,7 @@
  * drv_suse.c: the suse backend for suse
  *
  * Copyright (C) 2010 Novell Inc.
- * Copyright (C) 2009 Red Hat Inc.
+ * Copyright (C) 2009-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
@@ -1008,6 +1008,8 @@ struct netcf_if *drv_define(struct netcf *ncf, const char *xml_str) {
     int r;
     struct augeas *aug = get_augeas(ncf);
 
+    ERR_BAIL(ncf);
+
     ncf_xml = parse_xml(ncf, xml_str);
     ERR_BAIL(ncf);
 
diff --git a/src/dutil_linux.c b/src/dutil_linux.c
index 3cefb9e..da7a586 100644
--- a/src/dutil_linux.c
+++ b/src/dutil_linux.c
@@ -1,7 +1,7 @@
 /*
  * dutil_linux.c: Linux utility functions for driver backends.
  *
- * Copyright (C) 2009, 2011, 2012 Red Hat Inc.
+ * Copyright (C) 2009-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
@@ -441,6 +441,8 @@ int defnode(struct netcf *ncf, const char *name, const char *value,
     char *expr = NULL;
     int r, created;
 
+    ERR_BAIL(ncf);
+
     va_start(ap, format);
     r = vasprintf (&expr, format, ap);
     va_end (ap);
@@ -590,6 +592,8 @@ int aug_get_mac(struct netcf *ncf, const char *intf, const char **mac) {
     char *path;
     struct augeas *aug = get_augeas(ncf);
 
+    ERR_BAIL(ncf);
+
     r = xasprintf(&path, "/files/sys/class/net/%s/address/content", intf);
     ERR_NOMEM(r < 0, ncf);
 
@@ -611,6 +615,8 @@ void modprobed_alias_bond(struct netcf *ncf, const char *name) {
     struct augeas *aug = get_augeas(ncf);
     int r, nmatches;
 
+    ERR_BAIL(ncf);
+
     nmatches = aug_fmt_match(ncf, NULL,
                              "/files/etc/modprobe.d/*/alias[ . = '%s']",
                              name);
@@ -648,6 +654,8 @@ void modprobed_unalias_bond(struct netcf *ncf, const char *name) {
     struct augeas *aug = get_augeas(ncf);
     int r;
 
+    ERR_BAIL(ncf);
+
     r = xasprintf(&path,
          "/files/etc/modprobe.d/*/alias[ . = '%s'][modulename = 'bonding']",
                   name);
-- 
1.7.11.4



More information about the netcf-devel mailing list