Browse code

Handle segfaults in libcurl

git-svn: trunk@2297

Nigel Horne authored on 2006/09/21 18:37:47
Showing 2 changed files
... ...
@@ -1,3 +1,7 @@
1
+Thu Sep 21 10:36:32 BST 2006 (njh)
2
+----------------------------------
3
+  * libclamav/mbox.c:	Handle segfaults in libcurl
4
+
1 5
 Thu Sep 21 08:46:43 BST 2006 (njh)
2 6
 ----------------------------------
3 7
   * clamav-milter:	Be more specific about the format of the whitelist file
... ...
@@ -16,7 +16,7 @@
16 16
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 17
  *  MA 02110-1301, USA.
18 18
  */
19
-static	char	const	rcsid[] = "$Id: mbox.c,v 1.337 2006/09/20 10:22:07 njh Exp $";
19
+static	char	const	rcsid[] = "$Id: mbox.c,v 1.338 2006/09/21 09:33:31 njh Exp $";
20 20
 
21 21
 #if HAVE_CONFIG_H
22 22
 #include "clamav-config.h"
... ...
@@ -51,6 +51,7 @@ static	char	const	rcsid[] = "$Id: mbox.c,v 1.337 2006/09/20 10:22:07 njh Exp $";
51 51
 #include <dirent.h>
52 52
 #endif
53 53
 #include <limits.h>
54
+#include <signal.h>
54 55
 
55 56
 #if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2)
56 57
 #include <stddef.h>
... ...
@@ -67,6 +68,9 @@ static	char	const	rcsid[] = "$Id: mbox.c,v 1.337 2006/09/20 10:22:07 njh Exp $";
67 67
 #include "mbox.h"
68 68
 
69 69
 #ifdef	CL_DEBUG
70
+
71
+#include <features.h>
72
+
70 73
 #if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 1
71 74
 #define HAVE_BACKTRACE
72 75
 #endif
... ...
@@ -74,7 +78,6 @@ static	char	const	rcsid[] = "$Id: mbox.c,v 1.337 2006/09/20 10:22:07 njh Exp $";
74 74
 
75 75
 #ifdef HAVE_BACKTRACE
76 76
 #include <execinfo.h>
77
-#include <signal.h>
78 77
 #include <syslog.h>
79 78
 
80 79
 static	void	sigsegv(int sig);
... ...
@@ -3806,10 +3809,10 @@ checkURLs(message *mainMessage, mbox_ctx *mctx, int *rc, int is_html)
3806 3806
 
3807 3807
 #if    (!defined(FOLLOWURLS)) || (FOLLOWURLS <= 0)
3808 3808
        if(!hrefs.scanContents)
3809
-	       /*
3810
-		* Don't waste time extracting hrefs (parsing html), nobody
3811
-		* will need it
3812
-		*/
3809
+		/*
3810
+		 * Don't waste time extracting hrefs (parsing html), nobody
3811
+		 * will need it
3812
+		 */
3813 3813
 		return;
3814 3814
 #endif
3815 3815
 
... ...
@@ -4153,6 +4156,21 @@ checkURLs(message *m, mbox_ctx *mctx, int* rc, int is_html)
4153 4153
  *	an issue here.
4154 4154
  */
4155 4155
 #ifdef	WITH_CURL
4156
+
4157
+#if	(LIBCURL_VERSION_NUM >= 0x070C00)
4158
+static	int	curl_has_segfaulted;
4159
+/*
4160
+ * Inspite of numerious bug reports, curl is still buggy :-(
4161
+ *	For a fuller explanation, read the long comment at the top, including
4162
+ *	the valgrind evidence
4163
+ */
4164
+static void
4165
+curlsegv(int sig)
4166
+{
4167
+	curl_has_segfaulted = 1;
4168
+}
4169
+
4170
+#endif
4156 4171
 static void *
4157 4172
 #ifdef	CL_THREAD_SAFE
4158 4173
 getURL(void *a)
... ...
@@ -4175,6 +4193,7 @@ getURL(struct arg *arg)
4175 4175
 #ifdef	CURLOPT_ERRORBUFFER
4176 4176
 	char errorbuffer[CURL_ERROR_SIZE + 1];
4177 4177
 #elif	(LIBCURL_VERSION_NUM >= 0x070C00)
4178
+	void (*oldsegv)(int);
4178 4179
 	CURLcode res = CURLE_OK;
4179 4180
 #endif
4180 4181
 
... ...
@@ -4281,9 +4300,14 @@ getURL(struct arg *arg)
4281 4281
 	if(curl_easy_perform(curl) != CURLE_OK)
4282 4282
 		cli_warnmsg("URL %s failed to download: %s\n", url, errorbuffer);
4283 4283
 #elif	(LIBCURL_VERSION_NUM >= 0x070C00)
4284
+	oldsegv = signal(SIGSEGV, curlsegv);
4285
+	curl_has_segfaulted = 0;
4284 4286
 	if((res = curl_easy_perform(curl)) != CURLE_OK)
4285 4287
 		cli_warnmsg("URL %s failed to download: %s\n", url,
4286 4288
 			curl_easy_strerror(res));
4289
+	if(curl_has_segfaulted)
4290
+		cli_warnmsg("Libcurl has segfaulted on '%s'\n", url);
4291
+	signal(SIGSEGV, oldsegv);
4287 4292
 #else
4288 4293
 	if(curl_easy_perform(curl) != CURLE_OK)
4289 4294
 		cli_warnmsg("URL %s failed to download\n", url);
... ...
@@ -4295,6 +4319,7 @@ getURL(struct arg *arg)
4295 4295
 
4296 4296
 	return NULL;
4297 4297
 }
4298
+
4298 4299
 #endif
4299 4300
 #endif
4300 4301
 #ifdef HAVE_BACKTRACE