Browse code

fix possible infinite loop

git-svn: trunk@1661

Tomasz Kojm authored on 2005/07/21 10:51:59
Showing 3 changed files
... ...
@@ -1,3 +1,8 @@
1
+Thu Jul 21 03:47:03 CEST 2005 (tk)
2
+----------------------------------
3
+  * libclamav/others.c: cli_rmdirs: fix possible infinite loop. Patch by Mark
4
+			Pizzolato.
5
+
1 6
 Wed Jul 20 03:41:00 CEST 2005 (tk)
2 7
 ----------------------------------
3 8
   * libclamav/mspack: some cab archives were not properly decompressed (problem
... ...
@@ -144,6 +144,11 @@ int rmdirs(const char *dirname)
144 144
     if((dd = opendir(dirname)) != NULL) {
145 145
 	while(stat(dirname, &maind) != -1) {
146 146
 	    if(!rmdir(dirname)) break;
147
+	    if(errno != ENOTEMPTY) {
148
+		logg("^Can't remove temporary directory %s: %s\n", dirname, strerror(errno));
149
+		closedir(dd);
150
+		return 0;
151
+	    }
147 152
 
148 153
 	    while((dent = readdir(dd))) {
149 154
 #ifndef C_INTERIX
... ...
@@ -515,6 +515,11 @@ int cli_rmdirs(const char *dirname)
515 515
     if((dd = opendir(dirname)) != NULL) {
516 516
 	while(stat(dirname, &maind) != -1) {
517 517
 	    if(!rmdir(dirname)) break;
518
+	    if(errno != ENOTEMPTY) {
519
+		cli_errmsg("Can't remove temporary directory %s: %s\n", dirname, strerror(errno));
520
+		closedir(dd);
521
+		return 0;
522
+	    }
518 523
 
519 524
 #ifdef HAVE_READDIR_R_3
520 525
 	    while(!readdir_r(dd, &result.d, &dent) && dent) {