Browse code

execute ditto with execv

git-svn: trunk@1503

Tomasz Kojm authored on 2005/04/29 07:58:31
Showing 2 changed files
... ...
@@ -1,3 +1,10 @@
1
+Fri Apr 29 00:42:45 CEST 2005 (tk)
2
+----------------------------------
3
+  * shared/misc.c: (Mac OS X only) execute ditto with execl to eliminate
4
+		   potential security problem on multi-user OS X versions
5
+		   (reported by Tim Morgan <tim*sentinelchicken.org> and
6
+		   Kevin Amorin <kamorin*ccs.neu.edu>)
7
+
1 8
 Thu Apr 28 15:50:01 BST 2005 (njh)
2 9
 ----------------------------------
3 10
   * libclamav/mbox.c:	Work around to handle long lines transmitted by
... ...
@@ -107,17 +107,22 @@ int filecopy(const char *src, const char *dest)
107 107
 {
108 108
 
109 109
 #ifdef C_DARWIN
110
-    /* On Mac OS X use ditto and copy resource fork, too. */
111
-    char *ditto = (char *) mcalloc(strlen(src) + strlen(dest) + 30, sizeof(char));
112
-    sprintf(ditto, "/usr/bin/ditto --rsrc %s %s", src, dest);
110
+	pid_t pid;
113 111
 
114
-    if(system(ditto)) {
115
-	free(ditto);
116
-	return -1;
112
+    /* On Mac OS X use ditto and copy resource fork, too. */
113
+    switch(pid = fork()) {
114
+	case -1:
115
+	    return -1;
116
+	case 0:
117
+	    execl("/usr/bin/ditto", "ditto", "--rsrc", src, dest, NULL);
118
+	    perror("execv(ditto)");
119
+	    break;
120
+	default:
121
+	    wait(NULL);
122
+	    return 0;
117 123
     }
118 124
 
119
-    free(ditto);
120
-    return 0;
125
+    return -1;
121 126
 
122 127
 #else
123 128
 	char buffer[FILEBUFF];