fixes some memory errors and startup with broken config

Wed, 28 Dec 2016 17:27:14 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 28 Dec 2016 17:27:14 +0100
changeset 139
29ac9aed4889
parent 138
06619bbd14ef
child 140
93247a579184

fixes some memory errors and startup with broken config

src/server/daemon/config.c file | annotate | diff | comparison | revisions
src/server/daemon/configmanager.c file | annotate | diff | comparison | revisions
src/server/safs/pcheck.c file | annotate | diff | comparison | revisions
--- a/src/server/daemon/config.c	Wed Dec 28 12:23:51 2016 +0100
+++ b/src/server/daemon/config.c	Wed Dec 28 17:27:14 2016 +0100
@@ -345,6 +345,8 @@
     LogConfig logcfg;
     logcfg.file = sstrdup(file).ptr;
     logcfg.level = sstrdup(lvl).ptr;
+    logcfg.log_stdout = 0;
+    logcfg.log_stderr = 0;
     /* TODO: stdout, stderr config */
     
     int ret = init_log_file(&logcfg);
@@ -811,7 +813,15 @@
 
                 // get function
                 char *func_name = pblock_findval("fn", d->param);
+                if(!func_name) {
+                    log_ereport(LOG_MISCONFIG, "%s: Missing fn parameter", file);
+                    return NULL;
+                }
                 d->func = get_function(func_name);
+                if(!d->func) {
+                    log_ereport(LOG_MISCONFIG, "func %s not found", func_name);
+                    return NULL;
+                }
 
                 dirs = dirs->next;
 
--- a/src/server/daemon/configmanager.c	Wed Dec 28 12:23:51 2016 +0100
+++ b/src/server/daemon/configmanager.c	Wed Dec 28 17:27:14 2016 +0100
@@ -82,7 +82,9 @@
                     "reload configuration file: %s",
                     f->file.ptr);
         }
-        f->reload(f, conf);
+        if(f->reload(f, conf)) {
+            return -1;
+        }
         f->last_modified = s.st_mtime;
         if(reload) {
             *reload = 1;
--- a/src/server/safs/pcheck.c	Wed Dec 28 12:23:51 2016 +0100
+++ b/src/server/safs/pcheck.c	Wed Dec 28 17:27:14 2016 +0100
@@ -97,7 +97,8 @@
     char *path_info   = pblock_findkeyval (pb_key_path_info  , rq -> vars);
     char *script_name = pblock_findkeyval (pb_key_script_name, rq -> vars);
     //NSFCFileInfo *finfo = NULL;
-    struct stat *finfo;
+    struct stat stbuf;
+    struct stat *finfo = NULL;
 
     rq->directive_is_cacheable = 1;
 
@@ -142,18 +143,22 @@
 
             *path_info = '\0';
             //if ((INTrequest_info_path(path, rq, &finfo) == PR_SUCCESS) && finfo) {
-            if((finfo = request_stat_path(path, rq)) != NULL) {
+            struct stat *st = request_stat_path(path, rq);
+            if(st) {
+                finfo = &stbuf;
+                stbuf = *st;
+                free(st);
+            }
+            if(finfo) {
                 //if (finfo->pr.type != PR_FILE_FILE) {
                 if(S_ISDIR(finfo->st_mode)) {
                     *path_info = FILE_PATHSEP;
                     if (set_path_info(rq, pblock_findkeyval(pb_key_uri, rq->reqpb), 0)) {
-                        free(finfo);
                         return REQ_PROCEED;
                     }
                     break;
                 } else {
                     set_path_info(rq, pblock_findkeyval(pb_key_uri, rq->reqpb), path_info_depth);
-                    free(finfo);
                     return REQ_PROCEED;
                 }
             } else {
@@ -185,7 +190,13 @@
 
             *path_info = '\0';
             //if ((INTrequest_info_path(path, rq, &finfo) == PR_SUCCESS) && finfo) {
-            if((finfo = request_stat_path(path, rq)) != NULL) {
+            struct stat *st = request_stat_path(path, rq);
+            if(st) {
+                stbuf = *st;
+                finfo = &stbuf;
+                free(st);
+            }
+            if(finfo) {
                 //if (finfo->pr.type != PR_FILE_FILE) {
                 if(S_ISDIR(finfo->st_mode)) {
                     *path_info++ = FILE_PATHSEP;
@@ -216,10 +227,8 @@
                             ++path_info_depth;
                     *path_info = '\0';
                     set_path_info(rq, uri, path_info_depth);
-                    free(finfo);
                     return REQ_PROCEED;
                 }
-                free(finfo);
             }
             else {
                *path_info = FILE_PATHSEP;

mercurial