[netcf-devel] [PATCH 1/2] Explicitly check for existence of the root directory in drv_init

Laine Stump laine at laine.org
Wed Sep 15 15:52:24 UTC 2010


Previously a failure would only occur if bridge_physdevs() tried to
access something in the root directory and failed. That function will
no longer be called (see the next commit), so add a stat() of the
provided root and make sure it's a directory.
---
 src/drv_initscripts.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/src/drv_initscripts.c b/src/drv_initscripts.c
index c0bcfd5..1b9261b 100644
--- a/src/drv_initscripts.c
+++ b/src/drv_initscripts.c
@@ -30,6 +30,7 @@
 #include <stdbool.h>
 #include <string.h>
 #include <unistd.h>
+#include <sys/stat.h>
 
 #include "safe-alloc.h"
 #include "ref.h"
@@ -480,6 +481,7 @@ static void bridge_physdevs(struct netcf *ncf) {
 
 int drv_init(struct netcf *ncf) {
     int r;
+    struct stat stats;
 
     if (ALLOC(ncf->driver) < 0)
         return -1;
@@ -490,6 +492,12 @@ int drv_init(struct netcf *ncf) {
     if (r < 0)
         goto error;
 
+    if (stat(ncf->root, &stats) != 0 || !S_ISDIR(stats.st_mode)) {
+        report_error(ncf, NETCF_EFILE,
+                     "invalid root '%s' is not a directory", ncf->root);
+        return -1;
+    }
+
     // FIXME: Check for errors
     xsltInit();
     exsltStrRegister();
-- 
1.7.2.2



More information about the netcf-devel mailing list