7141450 Problem with library/curl
authorRich Burridge <rich.burridge@oracle.com>
Thu, 02 Feb 2012 10:53:40 -0800
changeset 677 07b064828047
parent 676 3837a817e8a8
child 678 ecd6b850f3d3
7141450 Problem with library/curl 7141699 Problem with library/curl
components/curl/Makefile
components/curl/patches/007-curl-dont-insert-empty-fragments.patch
components/curl/patches/008-curl-url-sanitize.patch
--- a/components/curl/Makefile	Thu Feb 02 08:24:42 2012 -0800
+++ b/components/curl/Makefile	Thu Feb 02 10:53:40 2012 -0800
@@ -41,8 +41,11 @@
 GSSAPI_LIBDIR_64 = /usr/lib/$(MACH64)
 
 CFLAGS += $(CPP_LARGEFILES)
+CFLAGS += `pkg-config --cflags libidn`
+CPPFLAGS += `pkg-config --cflags libidn`
 
 CONFIGURE_ENV += CFLAGS="$(CFLAGS)"
+CONFIGURE_ENV += CPPFLAGS="$(CPPFLAGS)"
 CONFIGURE_ENV += PKG_CONFIG_PATH="$(PKG_CONFIG_PATH)"
 
 CONFIGURE_OPTIONS += --localstatedir=/var --enable-shared --disable-static
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/components/curl/patches/007-curl-dont-insert-empty-fragments.patch	Thu Feb 02 10:53:40 2012 -0800
@@ -0,0 +1,42 @@
+--- lib/ssluse.c	2010-09-18 14:00:21.000000000 -0700
++++ lib/ssluse.c	2012-01-24 07:43:28.989624080 -0800
+@@ -1428,6 +1428,7 @@
+   X509_LOOKUP *lookup=NULL;
+   curl_socket_t sockfd = conn->sock[sockindex];
+   struct ssl_connect_data *connssl = &conn->ssl[sockindex];
++  long ctx_options;
+ #ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME
+   bool sni;
+ #ifdef ENABLE_IPV6
+@@ -1507,16 +1508,27 @@
+      If someone writes an application with libcurl and openssl who wants to
+      enable the feature, one can do this in the SSL callback.
+ 
++     OpenSSL added a work-around for a SSL 3.0/TLS 1.0 CBC vulnerability
++     (http://www.openssl.org/~bodo/tls-cbc.txt). In 0.9.6e they added a bit to
++     SSL_OP_ALL that _disables_ that work-around despite the fact that
++     SSL_OP_ALL is documented to do "rather harmless" workarounds. In order to
++     keep the secure work-around, the SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS bit
++     must not be set.
++
+   */
++
++  ctx_options = SSL_OP_ALL;
++
+ #ifdef SSL_OP_NO_TICKET
+   /* expect older openssl releases to not have this define so only use it if
+      present */
+-#define CURL_CTX_OPTIONS SSL_OP_ALL|SSL_OP_NO_TICKET
+-#else
+-#define CURL_CTX_OPTIONS SSL_OP_ALL
++  ctx_options |= SSL_OP_NO_TICKET;
++#endif
++#ifdef SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS
++  ctx_options &= ~SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS;
+ #endif
+ 
+-  SSL_CTX_set_options(connssl->ctx, CURL_CTX_OPTIONS);
++  SSL_CTX_set_options(connssl->ctx, ctx_options);
+ 
+   /* disable SSLv2 in the default case (i.e. allow SSLv3 and TLSv1) */
+   if(data->set.ssl.version == CURL_SSLVERSION_DEFAULT)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/components/curl/patches/008-curl-url-sanitize.patch	Thu Feb 02 10:53:40 2012 -0800
@@ -0,0 +1,199 @@
+--- lib/escape.c	2010-10-01 13:48:39.000000000 -0700
++++ lib/escape.c	2012-01-26 10:54:22.962290288 -0800
+@@ -88,7 +88,7 @@
+   char *testing_ptr = NULL;
+   unsigned char in; /* we need to treat the characters unsigned */
+   size_t newlen = alloc;
+-  int strindex=0;
++  size_t strindex=0;
+   size_t length;
+ 
+ #ifndef CURL_DOES_CONVERSIONS
+@@ -143,26 +143,25 @@
+ }
+ 
+ /*
+- * Unescapes the given URL escaped string of given length. Returns a
+- * pointer to a malloced string with length given in *olen.
+- * If length == 0, the length is assumed to be strlen(string).
+- * If olen == NULL, no output length is stored.
++ * Curl_urldecode() URL decodes the given string.
++ *
++ * Optionally detects control characters (byte codes lower than 32) in the
++ * *olen. If length == 0, the length is assumed to be strlen(string).
+  */
+-char *curl_easy_unescape(CURL *handle, const char *string, int length,
+-                         int *olen)
++CURLcode Curl_urldecode(struct SessionHandle *data,
++                        const char *string, size_t length,
++			char **ostring, size_t *olen,
++			bool reject_ctrl)
+ {
+-  int alloc = (length?length:(int)strlen(string))+1;
++  size_t alloc = (length?length:strlen(string))+1;
+   char *ns = malloc(alloc);
+   unsigned char in;
+-  int strindex=0;
++  size_t strindex=0;
+   unsigned long hex;
++  CURLcode res;
+ 
+-#ifndef CURL_DOES_CONVERSIONS
+-  /* avoid compiler warnings */
+-  (void)handle;
+-#endif
+   if( !ns )
+-    return NULL;
++      return CURLE_OUT_OF_MEMORY;
+ 
+   while(--alloc > 0) {
+     in = *string;
+@@ -180,17 +179,21 @@
+ 
+ #ifdef CURL_DOES_CONVERSIONS
+ /* escape sequences are always in ASCII so convert them on non-ASCII hosts */
+-      if(!handle ||
+-          (Curl_convert_from_network(handle, &in, 1) != CURLE_OK)) {
++	  res = Curl_convert_from_network(data, &in, 1);
++	  if(res) {
+         /* Curl_convert_from_network calls failf if unsuccessful */
+         free(ns);
+-        return NULL;
++	      return res;
+       }
+ #endif /* CURL_DOES_CONVERSIONS */
+ 
+       string+=2;
+       alloc-=2;
+     }
++      if(reject_ctrl && (in < 0x20)) {
++	  free(ns);
++	  return CURLE_URL_MALFORMAT;
++      }
+ 
+     ns[strindex++] = in;
+     string++;
+@@ -200,7 +203,34 @@
+   if(olen)
+     /* store output size */
+     *olen = strindex;
+-  return ns;
++
++  if(ostring)
++      /* store output string */
++      *ostring = ns;
++
++  return CURLE_OK;
++}
++
++
++/*
++ * Unescapes the given URL escaped string of given length. Returns a
++ * pointer to a malloced string with length given in *olen.
++ * If length == 0, the length is assumed to be strlen(string).
++ * If olen == NULL, no output length is stored.
++ */
++char *curl_easy_unescape(CURL *handle, const char *string, int length,
++                         int *olen)
++{
++  char *str = NULL;
++  size_t inputlen = length;
++  size_t outputlen;
++  CURLcode res = Curl_urldecode(handle, string, inputlen, &str, &outputlen,
++	  FALSE);
++  if(res)
++      return NULL;
++  if(olen)
++      *olen = curlx_uztosi(outputlen);
++  return str;
+ }
+ 
+ /* For operating systems/environments that use different malloc/free
+--- lib/escape.h	2010-09-18 14:00:21.000000000 -0700
++++ lib/escape.h	2012-01-26 09:42:20.936213952 -0800
+@@ -1,5 +1,5 @@
+-#ifndef __ESCAPE_H
+-#define __ESCAPE_H
++#ifndef HEADER_CURL_ESCAPE_H
++#define HEADER_CURL_ESCAPE_H
+ 
+ /***************************************************************************
+  *                                  _   _ ____  _
+@@ -8,7 +8,7 @@
+  *                            | (__| |_| |  _ <| |___
+  *                             \___|\___/|_| \_\_____|
+  *
+- * Copyright (C) 1998 - 2006, Daniel Stenberg, <[email protected]>, et al.
++ * Copyright (C) 1998 - 2011, Daniel Stenberg, <[email protected]>, et al.
+  *
+  * This software is licensed as described in the file COPYING, which
+  * you should have received as part of this distribution. The terms
+@@ -25,5 +25,9 @@
+ /* Escape and unescape URL encoding in strings. The functions return a new
+  * allocated string or NULL if an error occurred.  */
+ 
++CURLcode Curl_urldecode(struct SessionHandle *data,
++                        const char *string, size_t length,
++			char **ostring, size_t *olen,
++			bool reject_crlf);
+ 
+ #endif
+--- lib/imap.c	2010-09-18 14:00:21.000000000 -0700
++++ lib/imap.c	2012-01-26 09:35:07.180464878 -0800
+@@ -906,17 +906,12 @@
+   struct imap_conn *imapc = &conn->proto.imapc;
+   struct SessionHandle *data = conn->data;
+   const char *path = data->state.path;
+-  int len;
+ 
+   if(!*path)
+     path = "INBOX";
+ 
+   /* url decode the path and use this mailbox */
+-  imapc->mailbox = curl_easy_unescape(data, path, 0, &len);
+-  if(!imapc->mailbox)
+-    return CURLE_OUT_OF_MEMORY;
+-
+-  return CURLE_OK;
++  return Curl_urldecode(data, path, 0, &imapc->mailbox, NULL, TRUE);
+ }
+ 
+ /* call this when the DO phase has completed */
+--- lib/pop3.c	2010-09-18 14:00:21.000000000 -0700
++++ lib/pop3.c	2012-01-26 09:35:47.059691860 -0800
+@@ -852,11 +852,7 @@
+   const char *path = data->state.path;
+ 
+   /* url decode the path and use this mailbox */
+-  pop3c->mailbox = curl_easy_unescape(data, path, 0, NULL);
+-  if (!pop3c->mailbox)
+-    return CURLE_OUT_OF_MEMORY;
+-
+-  return CURLE_OK;
++  return Curl_urldecode(data, path, 0, &pop3c->mailbox, NULL, TRUE);
+ }
+ 
+ /* call this when the DO phase has completed */
+--- lib/smtp.c	2010-10-12 13:56:21.000000000 -0700
++++ lib/smtp.c	2012-01-26 09:38:03.856720962 -0800
+@@ -1045,7 +1045,6 @@
+   struct SessionHandle *data=conn->data;
+   struct pingpong *pp=&smtpc->pp;
+   const char *path = conn->data->state.path;
+-  int len;
+   char localhost[1024 + 1];
+ 
+   *done = FALSE; /* default to not done yet */
+@@ -1119,9 +1118,9 @@
+   }
+ 
+   /* url decode the path and use it as domain with EHLO */
+-  smtpc->domain = curl_easy_unescape(conn->data, path, 0, &len);
+-  if(!smtpc->domain)
+-    return CURLE_OUT_OF_MEMORY;
++  result = Curl_urldecode(conn->data, path, 0, &smtpc->domain, NULL, TRUE);
++  if(result)
++    return result;
+ 
+   /* When we connect, we start in the state where we await the server greeting
+    */