From 43f5258489643f42346c27d440f6353cda2838d2 Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Sun, 30 Oct 2011 16:20:12 +0000 Subject: [PATCH] Add a configure check for strtok() and add locks around its use If strtok() and locks aren't available, let get_last_url() fall back to the old check-decoded-url code. Compiling with the old cold will cause some not-yet-committed regression tests to fail. --- configure.in | 6 +++--- filters.c | 25 ++++++++++++++++++++++++- jcc.c | 10 +++++++++- jcc.h | 6 +++++- 4 files changed, 41 insertions(+), 6 deletions(-) diff --git a/configure.in b/configure.in index d072ec2d..8845863e 100644 --- a/configure.in +++ b/configure.in @@ -1,6 +1,6 @@ dnl Process this file with autoconf to produce a configure script. dnl -dnl $Id: configure.in,v 1.159 2011/07/03 17:53:00 fabiankeil Exp $ +dnl $Id: configure.in,v 1.160 2011/09/04 11:11:17 fabiankeil Exp $ dnl dnl Written by and Copyright (C) 2001-2010 the dnl Privoxy team. http://www.privoxy.org/ @@ -32,7 +32,7 @@ dnl ================================================================= dnl AutoConf Initialization dnl ================================================================= -AC_REVISION($Revision: 1.159 $) +AC_REVISION($Revision: 1.160 $) AC_INIT(jcc.c) if test ! -f config.h.in; then @@ -704,7 +704,7 @@ dnl bcopy is for PCRE AC_CHECK_FUNCS([bcopy]) AC_PROG_GCC_TRADITIONAL AC_TYPE_SIGNAL -AC_CHECK_FUNCS([access atexit getcwd gethostbyaddr gethostbyaddr_r gethostbyname gethostbyname_r gettimeofday inet_ntoa localtime_r memchr memmove memset poll putenv random regcomp select setlocale snprintf socket strchr strdup strerror strftime strlcat strlcpy strptime strstr strtoul timegm tzset]) +AC_CHECK_FUNCS([access atexit getcwd gethostbyaddr gethostbyaddr_r gethostbyname gethostbyname_r gettimeofday inet_ntoa localtime_r memchr memmove memset poll putenv random regcomp select setlocale snprintf socket strchr strdup strerror strtok strftime strlcat strlcpy strptime strstr strtoul timegm tzset]) dnl Checks for RFC 2553 resolver and socket functions AC_ARG_ENABLE(ipv6-support, diff --git a/filters.c b/filters.c index 865c6d80..4de7c900 100644 --- a/filters.c +++ b/filters.c @@ -1,4 +1,4 @@ -const char filters_rcs[] = "$Id: filters.c,v 1.151 2011/10/30 16:17:57 fabiankeil Exp $"; +const char filters_rcs[] = "$Id: filters.c,v 1.152 2011/10/30 16:18:12 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/filters.c,v $ @@ -78,6 +78,11 @@ const char filters_rcs[] = "$Id: filters.c,v 1.151 2011/10/30 16:17:57 fabiankei #include "urlmatch.h" #include "loaders.h" +#ifdef HAVE_STRTOK +/* Only used for locks */ +#include "jcc.h" +#endif /* def HAVE_STRTOK */ + #ifdef _WIN32 #include "win32.h" #endif @@ -1109,6 +1114,8 @@ char *get_last_url(char *subject, const char *redirect_mode) { log_error(LOG_LEVEL_REDIRECTS, "Checking \"%s\" for encoded redirects.", subject); + +#if defined(MUTEX_LOCKS_AVAILABLE) && defined(HAVE_STRTOK) /* * Check each parameter in the URL separately. * Sectionize the URL at "?" and "&", @@ -1117,6 +1124,8 @@ char *get_last_url(char *subject, const char *redirect_mode) * Keep the last one we spot. */ char *found = NULL; + + privoxy_mutex_lock(&strtok_mutex); char *token = strtok(subject, "?&"); while (token) { @@ -1139,15 +1148,29 @@ char *get_last_url(char *subject, const char *redirect_mode) { log_error(LOG_LEVEL_ERROR, "Out of memory while searching for redirects."); + privoxy_mutex_unlock(&strtok_mutex); return NULL; } } freez(dtoken); token = strtok(NULL, "?&"); } + privoxy_mutex_unlock(&strtok_mutex); freez(subject); return found; +#else + new_url = url_decode(subject); + if (new_url != NULL) + { + freez(subject); + subject = new_url; + } + else + { + log_error(LOG_LEVEL_ERROR, "Unable to decode \"%s\".", subject); + } +#endif /* defined(MUTEX_LOCKS_AVAILABLE) && defined(HAVE_STRTOK) */ } /* Else, just look for a URL inside this one, without decoding anything. */ diff --git a/jcc.c b/jcc.c index 1457206b..3efa3900 100644 --- a/jcc.c +++ b/jcc.c @@ -1,4 +1,4 @@ -const char jcc_rcs[] = "$Id: jcc.c,v 1.370 2011/10/23 11:23:35 fabiankeil Exp $"; +const char jcc_rcs[] = "$Id: jcc.c,v 1.371 2011/10/23 11:24:33 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/jcc.c,v $ @@ -198,6 +198,10 @@ privoxy_mutex_t localtime_mutex; privoxy_mutex_t rand_mutex; #endif /* ndef HAVE_RANDOM */ +#ifdef HAVE_STRTOK +privoxy_mutex_t strtok_mutex; +#endif /* def HAVE_STRTOK */ + #endif /* def MUTEX_LOCKS_AVAILABLE */ #if defined(unix) @@ -2847,6 +2851,10 @@ static void initialize_mutexes(void) #ifndef HAVE_RANDOM privoxy_mutex_init(&rand_mutex); #endif /* ndef HAVE_RANDOM */ + +#ifdef HAVE_STRTOK + privoxy_mutex_init(&strtok_mutex); +#endif /* def HAVE_STRTOK */ #endif /* def MUTEX_LOCKS_AVAILABLE */ } diff --git a/jcc.h b/jcc.h index 14185097..e871f5df 100644 --- a/jcc.h +++ b/jcc.h @@ -1,6 +1,6 @@ #ifndef JCC_H_INCLUDED #define JCC_H_INCLUDED -#define JCC_H_VERSION "$Id: jcc.h,v 1.29 2010/07/21 14:35:09 fabiankeil Exp $" +#define JCC_H_VERSION "$Id: jcc.h,v 1.30 2011/09/04 11:10:56 fabiankeil Exp $" /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/jcc.h,v $ @@ -99,6 +99,10 @@ extern privoxy_mutex_t resolver_mutex; extern privoxy_mutex_t rand_mutex; #endif /* ndef HAVE_RANDOM */ +#ifdef HAVE_STRTOK +extern privoxy_mutex_t strtok_mutex; +#endif /* ndef HAVE_STRTOK */ + #endif /* FEATURE_PTHREAD */ /* Functions */ -- 2.39.2