[Pkg-clamav-commits] [SCM] Debian repository for ClamAV branch, debian/unstable, updated. debian/0.95+dfsg-1-6156-g094ec9b
aCaB
acab at clamav.net
Sun Apr 4 01:23:00 UTC 2010
The following commit has been merged in the debian/unstable branch:
commit 52671b83efbb55d9c010ab0f6bc3db6aab9c3e1e
Author: aCaB <acab at clamav.net>
Date: Thu Mar 18 01:43:53 2010 +0100
rework globbing
diff --git a/win32/clamav-config.h b/win32/clamav-config.h
index 21213c3..c458a4e 100644
--- a/win32/clamav-config.h
+++ b/win32/clamav-config.h
@@ -493,7 +493,7 @@
/* #undef USE_SYSLOG */
/* Version number of package */
-#define VERSION "devel-clamav-0.96rc1-8-g9a04560"
+#define VERSION "devel-clamav-0.96rc1-13-g99a2d96"
/* Version suffix for package */
#define VERSION_SUFFIX ""
diff --git a/win32/clamd.vcproj b/win32/clamd.vcproj
index 9486a17..30f76e1 100644
--- a/win32/clamd.vcproj
+++ b/win32/clamd.vcproj
@@ -220,18 +220,6 @@
>
</File>
</Filter>
- <Filter
- Name="compat"
- >
- <File
- RelativePath=".\compat\libgen.c"
- >
- </File>
- <File
- RelativePath=".\compat\setargv.c"
- >
- </File>
- </Filter>
</Filter>
<Filter
Filter="h;hpp;hxx;hm;inl;inc;xsd"
diff --git a/win32/clamdscan.vcproj b/win32/clamdscan.vcproj
index 28ccdc3..0b9126c 100644
--- a/win32/clamdscan.vcproj
+++ b/win32/clamdscan.vcproj
@@ -204,18 +204,6 @@
>
</File>
</Filter>
- <Filter
- Name="compat"
- >
- <File
- RelativePath=".\compat\libgen.c"
- >
- </File>
- <File
- RelativePath=".\compat\setargv.c"
- >
- </File>
- </Filter>
</Filter>
<Filter
Filter="h;hpp;hxx;hm;inl;inc;xsd"
diff --git a/win32/clamscan.vcproj b/win32/clamscan.vcproj
index c3fa133..03e7bbb 100644
--- a/win32/clamscan.vcproj
+++ b/win32/clamscan.vcproj
@@ -190,18 +190,6 @@
>
</File>
<Filter
- Name="compat"
- >
- <File
- RelativePath=".\compat\libgen.c"
- >
- </File>
- <File
- RelativePath=".\compat\setargv.c"
- >
- </File>
- </Filter>
- <Filter
Name="shared"
>
<File
diff --git a/win32/compat/setargv.c b/win32/compat/glob.c
similarity index 67%
rename from win32/compat/setargv.c
rename to win32/compat/glob.c
index 88c3fe4..b560e75 100644
--- a/win32/compat/setargv.c
+++ b/win32/compat/glob.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 Sourcefire, Inc.
+ * Copyright (C) 2010 Sourcefire, Inc.
*
* Authors: aCaB <acab at clamav.net>
*
@@ -18,141 +18,54 @@
* MA 02110-1301, USA.
*/
-#if HAVE_CONFIG_H
-#include "clamav-config.h"
-#endif
-
#include "dirent.h"
#include "libgen.h"
-#include <fcntl.h>
-
-/* THIS IS A HACK ! */
-/* _setargv is the designed way to customize command line parsing which we use here
- for globbing reasons (incidentally the globbing in setargv.obj is badly broken)
-
- The crt first calls OUR _setargv from pre_c_init but later, from within pre_cpp_init,
- it also calls ITS OWN BUILTIN NATIVE CRAP, which re-parses the command line and
- eventually overrides our override.
-
- So, we additionally replace the command line global pointer _acmdln with a
- crafted set of arguments in order to fool buggy CRT's.
-*/
-#define _MY_CRT_INSISTS_ON_PARSING_THE_COMMAND_LINE_TWICE_FOR_NO_REASONS_
-#ifdef _MY_CRT_INSISTS_ON_PARSING_THE_COMMAND_LINE_TWICE_FOR_NO_REASONS_
-extern char ** __p__acmdln(void);
-#endif
+/*
+ I GIVE UP! The CRT is b0rked and cannot be helped.
-int glob_add(const char *path, int *argc, char ***argv);
+ The documentation suggestes to handle globbing automagically via linking in
+ the msvc-provided setargv.obj. Unfortunately that thing has got any sort of bugs
+ and perverts filenames rather than expanding them.
-int _setargv() {
- char *cur = GetCommandLineA(), *begparm = NULL, *endparm = NULL;
- char **argv = NULL, c;
- int argc = 0, in_sq = 0, in_dq = 0, need_glob = 0, allarglen = 0;
- int *g_argc = __p___argc();
- char ***g_argv = __p___argv();
+ The other suggested approach is to override the crt-builtin "_setargv" with a
+ custom routine to manually process the command line args before they are fed to main.
+ Now this is even funnier: the hook is indeed called bedore main(), but then its work
+ is discarded and replaced with that of the default parser... how useful!
+ After some debugging the problem turned out to be in the design. The flow is like:
+ pre_c_init -> _setargv
+ then
+ pre_cpp_init -> _setargv
+ Looking at the code in there, it clearly shows that both _init functions are 99% the
+ same. In case you are wondering... yes, everything is done twice! Including the
+ command line parsing...
+ There is however a small difference: while pre_c_init correctly calls the custom
+ _setargv if present, pre_cpp_init always calls the crt-builtin!
+ If you want to double check this link the msvc-provided noarg.obj in, then break in main
+ and see how argv and argc are actually set... If you try with setargv.obj, instead, you
+ will see that it apparently works, but that's just a hack for which pre_cpp_init ends
+ up calling __setargv instead of _setargv based on the _dowildcard flag.
- _setmode(_fileno(stdin), _O_BINARY);
- do {
- c = *cur;
- switch(c) {
- case '\0':
- endparm = cur;
- break;
- case ' ':
- if(begparm && !(in_sq | in_dq))
- endparm = cur;
- break;
- case '\'':
- if(!in_dq) {
- in_sq = !in_sq;
- if(!in_sq)
- endparm = cur;
- }
- break;
- case '"':
- if(!in_sq) {
- in_dq = !in_dq;
- if(!in_dq)
- endparm = cur;
- }
- break;
- case '*':
- case '?':
- if(!in_sq)
- need_glob = 1;
- default:
- if(!begparm) {
- begparm = cur;
- endparm = NULL;
- }
- }
- if (begparm && endparm) {
- if(begparm < endparm) {
- char *path = malloc(endparm - begparm + 1), *quotes;
- int arglen = 0;
+ So the way to FIX this mess involves a small trick: in the _setargv override I
+ don't just parse the command line properly, but I also turn my arguments into a new
+ command line, which I use to replace the existing one. The replaced line will then be
+ processed by pre_cpp_init and everything is fine.
+ To replace the original line with the fixed one it's sufficient to replace the pointer
+ returned by the __p__acmdln() function. The proto it "extern char **__p__acmdln(void)".
- memcpy(path, begparm, endparm - begparm);
- path[endparm - begparm] = '\0';
- quotes = path;
- while((quotes = strchr(quotes, '"')))
- memmove(quotes, quotes + 1, (endparm - begparm) - (quotes - path));
- if(argc && need_glob) {
- arglen = glob_add(path, &argc, &argv);
- if(!arglen) {
- path = malloc(endparm - begparm + 1);
- memcpy(path, begparm, endparm - begparm);
- path[endparm - begparm] = '\0';
- }
- }
- if(!arglen) {
- argv = realloc(argv, sizeof(*argv) * (argc + 1));
- argv[argc] = path;
- argc++;
- arglen = endparm - begparm;
- }
- allarglen += arglen;
- }
- need_glob = 0;
- in_sq = 0;
- in_dq = 0;
- begparm = NULL;
- endparm = NULL;
- }
- cur++;
- } while (c);
+ Of course the trick only works if the line is crafted in a way that can be understood
+ and parsed by the _setargv builtin.
+ Apparently, however, the authors of this pile of crap which goes under the name of CRT,
+ are not even able to keep their bugs consistent. So, while in MSVC 2008 it was enough to
+ put each arg in "'s, in MSVC 2008 SP 1 you additionally need to take care of "escaped"
+ quotes. I.e.: \".
- if(argc) {
- int i, argvlen = sizeof(*argv) * (argc + 1), argclen = 0;
- argv = realloc(argv, argvlen + allarglen + argc);
- argv[argc] = NULL;
- for(i=0; i<argc; i++) {
- int curlen = strlen(argv[i]) + 1;
- char *curarg = (char *)argv + argvlen + argclen;
- memcpy(curarg, argv[i], curlen);
- argclen += curlen;
- free(argv[i]);
- argv[i] = curarg;
- }
-#ifdef _MY_CRT_INSISTS_ON_PARSING_THE_COMMAND_LINE_TWICE_FOR_NO_REASONS_
- {
- char *fake_cmdl = malloc(argclen + 1 + 2*argc);
- char *curarg = fake_cmdl;
- char **g_cmdl = __p__acmdln();
- for(i=0; i<argc; i++)
- curarg += sprintf(curarg, "\"%s\" ", argv[i]);
- curarg--;
- *curarg = '\0';
- *g_cmdl = fake_cmdl;
- }
-#endif
- *g_argc = argc;
- *g_argv = argv;
- }
- return 0;
-}
+ Whatever...
+ I've given up trying to fit globbing below main. It's now hooked into main via a
+ #define wrapper.
+*/
-int glob_add(const char *path, int *argc, char ***argv) {
+static int glob_add(const char *path, int *argc, char ***argv) {
char *tail = strchr(path, '*'), *tailqmark;
char *dup1, *dup2, *dir, *base, *taildirsep, *tailwldsep;
struct dirent *de;
@@ -267,3 +180,95 @@ int glob_add(const char *path, int *argc, char ***argv) {
free(path);
return outlen;
}
+
+void w32_glob(int *argc_ptr, char ***argv_ptr) {
+ char *cur = GetCommandLineA(), *begparm = NULL, *endparm = NULL;
+ char **argv = NULL, c;
+ int argc = 0, in_sq = 0, in_dq = 0, need_glob = 0, allarglen = 0;
+
+ do {
+ c = *cur;
+ switch(c) {
+ case '\0':
+ endparm = cur;
+ break;
+ case ' ':
+ if(begparm && !(in_sq | in_dq))
+ endparm = cur;
+ break;
+ case '\'':
+ if(!in_dq) {
+ in_sq = !in_sq;
+ if(!in_sq)
+ endparm = cur;
+ }
+ break;
+ case '"':
+ if(!in_sq) {
+ in_dq = !in_dq;
+ if(!in_dq)
+ endparm = cur;
+ }
+ break;
+ case '*':
+ case '?':
+ if(!in_sq)
+ need_glob = 1;
+ default:
+ if(!begparm) {
+ begparm = cur;
+ endparm = NULL;
+ }
+ }
+ if (begparm && endparm) {
+ if(begparm < endparm) {
+ char *path = malloc(endparm - begparm + 1), *quotes;
+ int arglen = 0;
+
+ memcpy(path, begparm, endparm - begparm);
+ path[endparm - begparm] = '\0';
+ quotes = path;
+ while((quotes = strchr(quotes, '"')))
+ memmove(quotes, quotes + 1, (endparm - begparm) - (quotes - path));
+ if(argc && need_glob) {
+ arglen = glob_add(path, &argc, &argv);
+ if(!arglen) {
+ path = malloc(endparm - begparm + 1);
+ memcpy(path, begparm, endparm - begparm);
+ path[endparm - begparm] = '\0';
+ }
+ }
+ if(!arglen) {
+ argv = realloc(argv, sizeof(*argv) * (argc + 1));
+ argv[argc] = path;
+ argc++;
+ arglen = endparm - begparm;
+ }
+ allarglen += arglen;
+ }
+ need_glob = 0;
+ in_sq = 0;
+ in_dq = 0;
+ begparm = NULL;
+ endparm = NULL;
+ }
+ cur++;
+ } while (c);
+
+ if(argc) {
+ int i, argvlen = sizeof(*argv) * (argc + 1), argclen = 0;
+ argv = realloc(argv, argvlen + allarglen + argc);
+ argv[argc] = NULL;
+ for(i=0; i<argc; i++) {
+ int curlen = strlen(argv[i]) + 1;
+ char *curarg = (char *)argv + argvlen + argclen;
+ memcpy(curarg, argv[i], curlen);
+ argclen += curlen;
+ free(argv[i]);
+ argv[i] = curarg;
+ }
+ }
+ *argc_ptr = argc;
+ *argv_ptr = argv;
+}
+
diff --git a/win32/compat/libclamav_main.c b/win32/compat/libclamav_main.c
index 844f7bb..3fb75d9 100644
--- a/win32/compat/libclamav_main.c
+++ b/win32/compat/libclamav_main.c
@@ -1,3 +1,23 @@
+/*
+ * Copyright (C) 2010 Sourcefire, Inc.
+ *
+ * Authors: aCaB <acab at clamav.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
/* just a draft for now */
#if HAVE_CONFIG_H
diff --git a/win32/libclamav.def b/win32/libclamav.def
index 94f0583..ae27163 100644
--- a/win32/libclamav.def
+++ b/win32/libclamav.def
@@ -132,61 +132,64 @@ EXPORTS sha256_final @44274 NONAME
EXPORTS optget @44275 NONAME
EXPORTS optparse @44276 NONAME
EXPORTS optfree @44277 NONAME
-EXPORTS clam_options @44278 NONAME DATA
+EXPORTS w32_glob @44278 NONAME
+EXPORTS dirname @44279 NONAME
+EXPORTS basename @44280 NONAME
+EXPORTS clam_options @44281 NONAME DATA
; zlib
-EXPORTS gzopen @44279 NONAME
-EXPORTS gzgets @44280 NONAME
-EXPORTS gzdopen @44281 NONAME
-EXPORTS gzclose @44282 NONAME
-EXPORTS gzwrite @44283 NONAME
+EXPORTS gzopen @44282 NONAME
+EXPORTS gzgets @44283 NONAME
+EXPORTS gzdopen @44284 NONAME
+EXPORTS gzclose @44285 NONAME
+EXPORTS gzwrite @44286 NONAME
; pthreads
-EXPORTS pthread_mutex_lock @44284 NONAME
-EXPORTS pthread_mutex_unlock @44285 NONAME
-EXPORTS pthread_mutex_destroy @44286 NONAME
-EXPORTS pthread_once @44287 NONAME
-EXPORTS pthread_getspecific @44288 NONAME
-EXPORTS pthread_setspecific @44289 NONAME
-EXPORTS pthread_create @44290 NONAME
-EXPORTS pthread_cond_timedwait @44291 NONAME
-EXPORTS pthread_cond_init @44292 NONAME
-EXPORTS pthread_cond_broadcast @44293 NONAME
-EXPORTS pthread_cond_signal @44294 NONAME
-EXPORTS pthread_cond_destroy @44295 NONAME
-EXPORTS pthread_join @44296 NONAME
-EXPORTS pthread_key_create @44297 NONAME
-EXPORTS pthread_cond_wait @44298 NONAME
-EXPORTS pthread_attr_init @44299 NONAME
-EXPORTS pthread_attr_setdetachstate @44300 NONAME
-EXPORTS pthread_attr_destroy @44301 NONAME
-EXPORTS pthread_mutex_init @44302 NONAME
+EXPORTS pthread_mutex_lock @44287 NONAME
+EXPORTS pthread_mutex_unlock @44288 NONAME
+EXPORTS pthread_mutex_destroy @44289 NONAME
+EXPORTS pthread_once @44290 NONAME
+EXPORTS pthread_getspecific @44291 NONAME
+EXPORTS pthread_setspecific @44292 NONAME
+EXPORTS pthread_create @44293 NONAME
+EXPORTS pthread_cond_timedwait @44294 NONAME
+EXPORTS pthread_cond_init @44295 NONAME
+EXPORTS pthread_cond_broadcast @44296 NONAME
+EXPORTS pthread_cond_signal @44297 NONAME
+EXPORTS pthread_cond_destroy @44298 NONAME
+EXPORTS pthread_join @44299 NONAME
+EXPORTS pthread_key_create @44300 NONAME
+EXPORTS pthread_cond_wait @44301 NONAME
+EXPORTS pthread_attr_init @44302 NONAME
+EXPORTS pthread_attr_setdetachstate @44303 NONAME
+EXPORTS pthread_attr_destroy @44304 NONAME
+EXPORTS pthread_mutex_init @44305 NONAME
; winsock bridge and compatibility functions
-EXPORTS htonl @44303 NONAME
-EXPORTS htons @44304 NONAME
-EXPORTS ntohl @44305 NONAME
-EXPORTS ntohs @44306 NONAME
-EXPORTS __WSAFDIsSet @44307 NONAME
-EXPORTS w32_socket @44308 NONAME
-EXPORTS w32_getsockopt @44309 NONAME
-EXPORTS w32_setsockopt @44310 NONAME
-EXPORTS w32_bind @44311 NONAME
-EXPORTS w32_listen @44312 NONAME
-EXPORTS w32_accept @44313 NONAME
-EXPORTS w32_connect @44314 NONAME
-EXPORTS w32_shutdown @44315 NONAME
-EXPORTS w32_send @44316 NONAME
-EXPORTS w32_recv @44317 NONAME
-EXPORTS w32_closesocket @44318 NONAME
-EXPORTS w32_getservbyname @44319 NONAME
-EXPORTS w32_getaddrinfo @44320 NONAME
-EXPORTS w32_freeaddrinfo @44321 NONAME
-EXPORTS w32_inet_ntop @44322 NONAME
-EXPORTS w32_gethostbyname @44323 NONAME
-EXPORTS w32_select @44324 NONAME
-EXPORTS poll_with_event @44325 NONAME
-EXPORTS w32_stat @44326 NONAME
-EXPORTS w32_strerror @44327 NONAME
-EXPORTS w32_strerror_r @44328 NONAME
-EXPORTS inet_addr @44329 NONAME
+EXPORTS htonl @44306 NONAME
+EXPORTS htons @44307 NONAME
+EXPORTS ntohl @44308 NONAME
+EXPORTS ntohs @44309 NONAME
+EXPORTS __WSAFDIsSet @44310 NONAME
+EXPORTS w32_socket @44311 NONAME
+EXPORTS w32_getsockopt @44312 NONAME
+EXPORTS w32_setsockopt @44313 NONAME
+EXPORTS w32_bind @44314 NONAME
+EXPORTS w32_listen @44315 NONAME
+EXPORTS w32_accept @44316 NONAME
+EXPORTS w32_connect @44317 NONAME
+EXPORTS w32_shutdown @44318 NONAME
+EXPORTS w32_send @44319 NONAME
+EXPORTS w32_recv @44320 NONAME
+EXPORTS w32_closesocket @44321 NONAME
+EXPORTS w32_getservbyname @44322 NONAME
+EXPORTS w32_getaddrinfo @44323 NONAME
+EXPORTS w32_freeaddrinfo @44324 NONAME
+EXPORTS w32_inet_ntop @44325 NONAME
+EXPORTS w32_gethostbyname @44326 NONAME
+EXPORTS w32_select @44327 NONAME
+EXPORTS poll_with_event @44328 NONAME
+EXPORTS w32_stat @44329 NONAME
+EXPORTS w32_strerror @44330 NONAME
+EXPORTS w32_strerror_r @44331 NONAME
+EXPORTS inet_addr @44332 NONAME
diff --git a/win32/libclamav.vcproj b/win32/libclamav.vcproj
index e844269..3932b71 100644
--- a/win32/libclamav.vcproj
+++ b/win32/libclamav.vcproj
@@ -6,7 +6,7 @@
ProjectType="Visual C++"
RootNamespace="libclamav"
TargetFrameworkVersion="196613"
- Version="9.00"
+ Version="9,00"
>
<Platforms>
<Platform
@@ -185,14 +185,6 @@
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
- RelativePath="..\libclamav\filtering.c"
- >
- </File>
- <File
- RelativePath="..\libclamav\perflogging.c"
- >
- </File>
- <File
RelativePath="..\libclamav\7z.c"
>
</File>
@@ -285,6 +277,10 @@
>
</File>
<File
+ RelativePath="..\libclamav\filtering.c"
+ >
+ </File>
+ <File
RelativePath="..\libclamav\fmap.c"
>
</File>
@@ -393,6 +389,10 @@
>
</File>
<File
+ RelativePath="..\libclamav\perflogging.c"
+ >
+ </File>
+ <File
RelativePath="..\libclamav\petite.c"
>
</File>
@@ -792,6 +792,10 @@
>
</File>
<File
+ RelativePath=".\compat\glob.c"
+ >
+ </File>
+ <File
RelativePath=".\compat\libclamav_main.c"
>
</File>
diff --git a/win32/platform.h b/win32/platform.h
index c3f9082..50bf386 100644
--- a/win32/platform.h
+++ b/win32/platform.h
@@ -6,6 +6,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <io.h>
+#include <fcntl.h>
#include <direct.h>
#include <Ws2tcpip.h>
#include <process.h>
@@ -73,6 +74,8 @@ typedef unsigned int in_addr_t;
#define PATHSEP "\\"
+void w32_glob(int *argc_ptr, char ***argv_ptr);
+
#undef DATADIR
#undef CONFDIR
#if !defined(THIS_IS_LIBCLAMAV) && defined(_MSC_VER)
@@ -91,5 +94,8 @@ LIBCLAMAV_EXPORT extern const char *CONFDIR_MILTER;
#undef OUT
#endif
+int real_main(int, char**);
+#define main main(int argc, char **argv) { _setmode(_fileno(stdin), _O_BINARY); w32_glob(&argc, &argv); return real_main(argc, argv); }; int real_main
+
#endif /* __PLATFORM_H */
diff --git a/win32/update-win32.pl b/win32/update-win32.pl
index 8b0297d..e48ca31 100755
--- a/win32/update-win32.pl
+++ b/win32/update-win32.pl
@@ -215,13 +215,13 @@ my @PROJECTS = (
{makefile => 'libclamav/c++', sections => ['libclamavcxx'], output => 'win32/libclamavcxx.vcproj'},
# CLAMSCAN #
- {makefile => 'clamscan', sections => ['clamscan'], output => 'win32/clamscan.vcproj', makefile_only => '(optparser\\.c|getopt\\.c)$', vcproj_only => 'compat\\\\'},
+ {makefile => 'clamscan', sections => ['clamscan'], output => 'win32/clamscan.vcproj', makefile_only => '(optparser\\.c|getopt\\.c)$'},
# CLAMDSCAN #
- {makefile => 'clamdscan', sections => ['clamdscan'], output => 'win32/clamdscan.vcproj', makefile_only => '(optparser\\.c|getopt\\.c)$', vcproj_only => 'compat\\\\'},
+ {makefile => 'clamdscan', sections => ['clamdscan'], output => 'win32/clamdscan.vcproj', makefile_only => '(optparser\\.c|getopt\\.c)$'},
# CLAMD #
- {makefile => 'clamd', sections => ['clamd'], output => 'win32/clamd.vcproj', makefile_only => '(optparser\\.c|getopt\\.c|(daz|clam)uko.*)$', vcproj_only => 'compat\\\\'},
+ {makefile => 'clamd', sections => ['clamd'], output => 'win32/clamd.vcproj', makefile_only => '(optparser\\.c|getopt\\.c|(daz|clam)uko.*)$'},
# FRESHCLAM #
{makefile => 'freshclam', sections => ['freshclam'], output => 'win32/freshclam.vcproj', makefile_only => '(optparser\\.c|getopt\\.c)$', vcproj_only => 'compat\\\\'},
--
Debian repository for ClamAV
More information about the Pkg-clamav-commits
mailing list