git-svn: trunk@4852
Török Edvin authored on 2009/02/24 22:21:27... | ... |
@@ -1,3 +1,9 @@ |
1 |
+Tue Feb 24 15:54:17 EET 2009 (edwin) |
|
2 |
+------------------------------------ |
|
3 |
+ * clamdscan/client.c, clamdscan/proto.c, clamdscan/proto.h, |
|
4 |
+ libclamav/others.h, libclamav/others_common.c: trim extra leading |
|
5 |
+ and trailing slashes (bb #1423). |
|
6 |
+ |
|
1 | 7 |
Tue Feb 24 12:32:03 EET 2009 (edwin) |
2 | 8 |
------------------------------------ |
3 | 9 |
* unit_tests/efence_tests.sh: fix electric-fence return code |
... | ... |
@@ -242,6 +242,7 @@ int client(const struct optstruct *opts, int *infected) |
242 | 242 |
flags |= CLI_FTW_FOLLOW_DIR_SYMLINK; |
243 | 243 |
if (optget(clamdopts, "FollowFileSymlinks")->enabled) |
244 | 244 |
flags |= CLI_FTW_FOLLOW_FILE_SYMLINK; |
245 |
+ flags |= CLI_FTW_TRIM_SLASHES; |
|
245 | 246 |
optfree(clamdopts); |
246 | 247 |
|
247 | 248 |
if(!mainsa) { |
... | ... |
@@ -370,7 +370,7 @@ static int serial_callback(struct stat *sb, char *filename, const char *path, en |
370 | 370 |
|
371 | 371 |
/* Non-IDSESSION handler |
372 | 372 |
* Returns non zero for serious errors, zero otherwise */ |
373 |
-int serial_client_scan(const char *file, int scantype, int *infected, int *errors, int maxlevel, int flags) { |
|
373 |
+int serial_client_scan(char *file, int scantype, int *infected, int *errors, int maxlevel, int flags) { |
|
374 | 374 |
struct cli_ftw_cbdata data; |
375 | 375 |
struct client_serial_data cdata; |
376 | 376 |
int ftw; |
... | ... |
@@ -547,7 +547,7 @@ static int parallel_callback(struct stat *sb, char *filename, const char *path, |
547 | 547 |
|
548 | 548 |
/* IDSESSION handler |
549 | 549 |
* Returns non zero for serious errors, zero otherwise */ |
550 |
-int parallel_client_scan(const char *file, int scantype, int *infected, int *errors, int maxlevel, int flags) { |
|
550 |
+int parallel_client_scan(char *file, int scantype, int *infected, int *errors, int maxlevel, int flags) { |
|
551 | 551 |
struct cli_ftw_cbdata data; |
552 | 552 |
struct client_parallel_data cdata; |
553 | 553 |
int ftw; |
... | ... |
@@ -34,7 +34,7 @@ int dconnect(void); |
34 | 34 |
int sendln(int sockd, const char *line, unsigned int len); |
35 | 35 |
void recvlninit(struct RCVLN *s, int sockd); |
36 | 36 |
int recvln(struct RCVLN *s, char **rbol, char **reol); |
37 |
-int serial_client_scan(const char *file, int scantype, int *infected, int *errors, int maxlevel, int flags); |
|
38 |
-int parallel_client_scan(const char *file, int scantype, int *infected, int *errors, int maxlevel, int flags); |
|
37 |
+int serial_client_scan(char *file, int scantype, int *infected, int *errors, int maxlevel, int flags); |
|
38 |
+int parallel_client_scan(char *file, int scantype, int *infected, int *errors, int maxlevel, int flags); |
|
39 | 39 |
int dsresult(int sockd, int scantype, const char *filename); |
40 | 40 |
#endif |
... | ... |
@@ -372,7 +372,9 @@ int cli_matchregex(const char *str, const char *regex); |
372 | 372 |
/* if the callback needs the stat */ |
373 | 373 |
#define CLI_FTW_NEED_STAT 0x04 |
374 | 374 |
|
375 |
-#define CLI_FTW_STD (CLI_FTW_NEED_STAT) |
|
375 |
+/* remove leading/trailing slashes */ |
|
376 |
+#define CLI_FTW_TRIM_SLASHES 0x08 |
|
377 |
+#define CLI_FTW_STD (CLI_FTW_NEED_STAT | CLI_FTW_TRIM_SLASHES) |
|
376 | 378 |
|
377 | 379 |
enum cli_ftw_reason { |
378 | 380 |
visit_file, |
... | ... |
@@ -414,6 +416,6 @@ typedef int (*cli_ftw_cb)(struct stat *stat_buf, char *filename, const char *pat |
414 | 414 |
* which one it is. |
415 | 415 |
* If it is a file, it simply calls the callback once, otherwise recurses. |
416 | 416 |
*/ |
417 |
-int cli_ftw(const char *base, int flags, int maxdepth, cli_ftw_cb callback, struct cli_ftw_cbdata *data); |
|
417 |
+int cli_ftw(char *base, int flags, int maxdepth, cli_ftw_cb callback, struct cli_ftw_cbdata *data); |
|
418 | 418 |
|
419 | 419 |
#endif |
... | ... |
@@ -496,14 +496,25 @@ static int handle_entry(struct dirent_data *entry, int flags, int maxdepth, cli_ |
496 | 496 |
} |
497 | 497 |
} |
498 | 498 |
|
499 |
-int cli_ftw(const char *path, int flags, int maxdepth, cli_ftw_cb callback, struct cli_ftw_cbdata *data) |
|
499 |
+int cli_ftw(char *path, int flags, int maxdepth, cli_ftw_cb callback, struct cli_ftw_cbdata *data) |
|
500 | 500 |
{ |
501 | 501 |
struct stat statbuf; |
502 | 502 |
enum filetype ft = ft_unknown; |
503 | 503 |
struct dirent_data entry; |
504 | 504 |
int stated = 0; |
505 | 505 |
|
506 |
- int ret = handle_filetype(path, flags, &statbuf, &stated, &ft, callback, data); |
|
506 |
+ int ret; |
|
507 |
+ |
|
508 |
+ if (flags & CLI_FTW_TRIM_SLASHES) { |
|
509 |
+ /* trim slashes so that dir and dir/ behave the same when |
|
510 |
+ * they are symlinks, and we are not following symlinks */ |
|
511 |
+ char *pathend; |
|
512 |
+ while (path[0] == '/' && path[1] == '/') path++; |
|
513 |
+ pathend = path + strlen(path); |
|
514 |
+ while (pathend > path && pathend[-1] == '/') --pathend; |
|
515 |
+ *pathend = '\0'; |
|
516 |
+ } |
|
517 |
+ ret = handle_filetype(path, flags, &statbuf, &stated, &ft, callback, data); |
|
507 | 518 |
if (ret != CL_SUCCESS) |
508 | 519 |
return ret; |
509 | 520 |
if (ft_skipped(ft)) |