Browse code

fix bad path completion when using options for external

git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@1271 77e5149b-7576-45b1-b177-96237e5ba77b

Tomasz Kojm authored on 2005/01/25 13:18:24
Showing 2 changed files
... ...
@@ -1,3 +1,9 @@
1
+Tue Jan 25 05:09:42 CET 2005 (tk)
2
+---------------------------------
3
+  * clamscan/manager.c: fix bad path completion when using options for external
4
+			compressors (reported by Robert Allerstorfer
5
+			<roal*anet.at>)
6
+
1 7
 Mon Jan 24 20:12:06 CET 2005 (tk)
2 8
 ---------------------------------
3 9
   * freshclam: improve error messages (patch by Luca Gibelli <luca*clamav.net>)
... ...
@@ -64,7 +64,7 @@ dev_t procdev;
64 64
 int scanmanager(const struct optstruct *opt)
65 65
 {
66 66
 	mode_t fmode;
67
-	int ret = 0, compression = 0, fmodeint, options = 0;
67
+	int ret = 0, compression = 0, fmodeint, options = 0, i;
68 68
 	struct cl_node *trie = NULL;
69 69
 	struct cl_limits *limits = NULL;
70 70
 	struct passwd *user = NULL;
... ...
@@ -118,7 +118,6 @@ int scanmanager(const struct optstruct *opt)
118 118
 
119 119
     }
120 120
 
121
-
122 121
     if(!trie) {
123 122
 	mprintf("@Can't initialize the virus database.\n");
124 123
 	return 50;
... ...
@@ -221,17 +220,24 @@ int scanmanager(const struct optstruct *opt)
221 221
 	ret = checkstdin(trie, limits, options);
222 222
 
223 223
     } else {
224
-	int x;
225 224
 	char *thefilename;
226
-	for (x=0; (thefilename = cli_strtok(opt->filename, x, "\t")) != NULL; x++) {
225
+	for (i = 0; (thefilename = cli_strtok(opt->filename, i, "\t")) != NULL; i++) {
227 226
 	    if((fmodeint = fileinfo(thefilename, 2)) == -1) {
228 227
 		mprintf("@Can't access file %s\n", thefilename);
229 228
 		perror(thefilename);
230 229
 		ret = 56;
231 230
 	    } else {
231
+		int slash = 1;
232
+		for(i = strlen(thefilename) - 1; i > 0 && slash; i--) {
233
+		    if(thefilename[i] == '/')
234
+			thefilename[i] = 0;
235
+		    else
236
+			slash = 0;
237
+		}
238
+
232 239
 		fmode = (mode_t) fmodeint;
233 240
 
234
-		if(compression && (strlen(thefilename) < 2 || (thefilename[0] != '/' && thefilename[0] != '\\' && thefilename[1] != ':'))) {
241
+		if(compression && (thefilename[0] != '/' && thefilename[0] != '\\' && thefilename[1] != ':')) {
235 242
 		    /* we need to complete the path */
236 243
 		    if(!getcwd(cwd, sizeof(cwd))) {
237 244
 			mprintf("@Can't get absolute pathname of current working directory.\n");
... ...
@@ -247,7 +253,7 @@ int scanmanager(const struct optstruct *opt)
247 247
 			mprintf("*Full path: %s\n", fullpath);
248 248
 		    }
249 249
 		} else
250
-		    fullpath = (char *) thefilename;
250
+		    fullpath = thefilename;
251 251
 
252 252
 		switch(fmode & S_IFMT) {
253 253
 		    case S_IFREG:
... ...
@@ -263,7 +269,7 @@ int scanmanager(const struct optstruct *opt)
263 263
 			ret = 52;
264 264
 		}
265 265
 
266
-		if(compression && (strlen(thefilename) < 2 || (thefilename[0] != '/' && thefilename[0] != '\\' && thefilename[1] != ':'))) {
266
+		if(compression && (thefilename[0] != '/' && thefilename[0] != '\\' && thefilename[1] != ':')) {
267 267
 		    free(fullpath);
268 268
 		    fullpath = NULL;
269 269
 		}