[Asterisk-cvs] asterisk config.c,1.80,1.81

kpfleming kpfleming
Mon Oct 31 16:17:01 CST 2005


Update of /usr/cvsroot/asterisk
In directory mongoose.digium.com:/tmp/cvs-serv5229

Modified Files:
	config.c 
Log Message:
ignore non-regular files during config parsing (issue #5510, different fix)


Index: config.c
===================================================================
RCS file: /usr/cvsroot/asterisk/config.c,v
retrieving revision 1.80
retrieving revision 1.81
diff -u -d -r1.80 -r1.81
--- config.c	26 Oct 2005 18:54:24 -0000	1.80
+++ config.c	31 Oct 2005 21:08:55 -0000	1.81
@@ -30,6 +30,7 @@
 #include <string.h>
 #include <errno.h>
 #include <time.h>
+#include <sys/stat.h>
 #define AST_INCLUDE_GLOB 1
 #ifdef AST_INCLUDE_GLOB
 #ifdef __Darwin__
@@ -538,6 +539,7 @@
 	int comment = 0, nest[MAX_NESTED_COMMENTS];
 	struct ast_category *cat = NULL;
 	int count = 0;
+	struct stat statbuf;
 	
 	cat = ast_config_get_current_category(cfg);
 
@@ -569,11 +571,26 @@
 			for (i=0; i<globbuf.gl_pathc; i++) {
 				ast_copy_string(fn, globbuf.gl_pathv[i], sizeof(fn));
 #endif
-	if ((option_verbose > 1) && !option_debug) {
-		ast_verbose(  VERBOSE_PREFIX_2 "Parsing '%s': ", fn);
-		fflush(stdout);
-	}
-	if ((f = fopen(fn, "r"))) {
+	do {
+		if (stat(fn, &statbuf)) {
+			ast_log(LOG_WARNING, "Cannot stat() '%s', ignoring\n", fn);
+			continue;
+		}
+		if (!S_ISREG(statbuf.st_mode)) {
+			ast_log(LOG_WARNING, "'%s' is not a regular file, ignoring\n", fn);
+			continue;
+		}
+		if ((option_verbose > 1) && !option_debug) {
+			ast_verbose(VERBOSE_PREFIX_2 "Parsing '%s': ", fn);
+			fflush(stdout);
+		}
+		if (!(f = fopen(fn, "r"))) {
+			if (option_debug)
+				ast_log(LOG_DEBUG, "No file to parse: %s\n", fn);
+			else if (option_verbose > 1)
+				ast_verbose( "Not found (%s)\n", strerror(errno));
+			continue;
+		}
 		count++;
 		if (option_debug)
 			ast_log(LOG_DEBUG, "Parsing %s\n", fn);
@@ -641,12 +658,7 @@
 			}
 		}
 		fclose(f);		
-	} else { /* can't open file */
-		if (option_debug)
-			ast_log(LOG_DEBUG, "No file to parse: %s\n", fn);
-		else if (option_verbose > 1)
-			ast_verbose( "Not found (%s)\n", strerror(errno));
-	}
+	} while(0);
 	if (comment) {
 		ast_log(LOG_WARNING,"Unterminated comment detected beginning on line %d\n", nest[comment]);
 	}




More information about the svn-commits mailing list