[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:08:08 UTC 2010


The following commit has been merged in the debian/unstable branch:
commit 6e246c11eea11f2007f359eec26bcf975a988bea
Author: aCaB <acab at clamav.net>
Date:   Wed Oct 21 17:51:33 2009 +0200

    win32 safe_open() wrappage

diff --git a/ChangeLog b/ChangeLog
index 40e5343..c9ef7da 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Wed Oct 21 17:50:05 CEST 2009 (acab)
+------------------------------------
+ * win32: introduce safe_open() (sic!)
+
 Tue Oct 20 17:48:59 CEST 2009 (acab)
 ------------------------------------
  * shared, win32: make hardcoded paths relocable in win32 builds
diff --git a/clamscan/manager.c b/clamscan/manager.c
index 612b008..08ecca2 100644
--- a/clamscan/manager.c
+++ b/clamscan/manager.c
@@ -127,7 +127,7 @@ static int scanfile(const char *filename, struct cl_engine *engine, const struct
 
     logg("*Scanning %s\n", filename);
 
-    if((fd = open(filename, O_RDONLY|O_BINARY)) == -1) {
+    if((fd = safe_open(filename, O_RDONLY|O_BINARY)) == -1) {
 	logg("^Can't open file %s: %s\n", filename, strerror(errno));
 	return 54;
     }
diff --git a/libclamav/scanners.c b/libclamav/scanners.c
index 6051081..aba235a 100644
--- a/libclamav/scanners.c
+++ b/libclamav/scanners.c
@@ -2221,7 +2221,7 @@ static int cli_scanfile(const char *filename, cli_ctx *ctx)
 	int fd, ret;
 
     /* internal version of cl_scanfile with arec/mrec preserved */
-    if((fd = open(filename, O_RDONLY|O_BINARY)) == -1)
+    if((fd = safe_open(filename, O_RDONLY|O_BINARY)) == -1)
 	return CL_EOPEN;
 
     ret = cli_magic_scandesc(fd, ctx);
diff --git a/platform.h.in b/platform.h.in
index 627c34b..c30f2d5 100644
--- a/platform.h.in
+++ b/platform.h.in
@@ -38,3 +38,6 @@ typedef	unsigned	int	in_addr_t;
 #define CONFDIR_FRESHCLAM CONFDIR PATHSEP "freshclam.conf"
 #define CONFDIR_MILTER CONFDIR PATHSEP "clamav-milter.conf"
 
+/* Nothing is safe in windows, not even open */
+#define safe_open open
+
diff --git a/win32/compat/w32_stat.c b/win32/compat/w32_stat.c
index 19afec6..0eb7465 100644
--- a/win32/compat/w32_stat.c
+++ b/win32/compat/w32_stat.c
@@ -19,11 +19,14 @@
  */
 
 #include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <io.h>
 
 #include "others.h"
 #include "shared/misc.h"
 
-
 wchar_t *uncpath(const char *path) {
     DWORD len = 0;
     wchar_t *dest = cli_malloc((PATH_MAX + 1) * sizeof(wchar_t));
@@ -69,6 +72,26 @@ wchar_t *uncpath(const char *path) {
     return dest;
 }
 
+int safe_open(const char *path, int flags, ... ) {
+    wchar_t *wpath = uncpath(path);
+    int ret;
+
+    if(!wpath)
+	return -1;
+
+    if(flags & O_CREAT) {
+	int mode;
+	va_list ap;
+	va_start(ap, flags);
+	mode = va_arg(ap, int);
+	va_end(ap);
+	ret = _wopen(wpath, flags, mode);
+    } else
+	ret = _wopen(wpath, flags);
+    free(wpath);
+    return ret;
+}
+
 
 w32_stat(const char *path, struct stat *buf) {
     int len;
diff --git a/win32/compat/w32_stat.h b/win32/compat/w32_stat.h
index 943cc8e..4cda3fe 100644
--- a/win32/compat/w32_stat.h
+++ b/win32/compat/w32_stat.h
@@ -40,6 +40,7 @@ int w32_stat(const char *path, struct stat *buf);
 #define stat(path, buf) w32_stat(path, buf)
 
 wchar_t *uncpath(const char *path);
+int safe_open(const char *path, int flags, ... );
 
 #endif
 
diff --git a/win32/freshclam.vcproj b/win32/freshclam.vcproj
index f0601cb..050d3ba 100644
--- a/win32/freshclam.vcproj
+++ b/win32/freshclam.vcproj
@@ -239,10 +239,6 @@
 					>
 				</File>
 				<File
-					RelativePath=".\compat\resolv.h"
-					>
-				</File>
-				<File
 					RelativePath=".\compat\strptime.c"
 					>
 				</File>
diff --git a/win32/libclamav.def b/win32/libclamav.def
index df1a9ac..fb62f66 100644
--- a/win32/libclamav.def
+++ b/win32/libclamav.def
@@ -39,6 +39,7 @@ EXPORTS have_rar
 EXPORTS opendir
 EXPORTS readdir
 EXPORTS closedir
+EXPORTS safe_open
 EXPORTS snprintf
 EXPORTS mp_init
 EXPORTS mp_read_radix
diff --git a/win32/libclamav.vcproj b/win32/libclamav.vcproj
index 3322924..a3536cb 100644
--- a/win32/libclamav.vcproj
+++ b/win32/libclamav.vcproj
@@ -799,10 +799,6 @@
 					RelativePath=".\compat\w32_stat.c"
 					>
 				</File>
-				<File
-					RelativePath=".\compat\w32_stat.h"
-					>
-				</File>
 			</Filter>
 		</Filter>
 		<Filter

-- 
Debian repository for ClamAV



More information about the Pkg-clamav-commits mailing list