c260e0
From e0a1f91d29349d2ce45960f14ebe8e0fa043364e Mon Sep 17 00:00:00 2001
c260e0
From: Jared Jennings <jjenning@fastmail.fm>
c260e0
Date: Fri, 5 Apr 2013 16:01:31 +0200
c260e0
Subject: [PATCH 01/10] curl -E: allow to escape ':' in cert nickname
c260e0
c260e0
Upstream-commit: 865d4138a08daff460f116c2494adb9c889f5304
c260e0
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
c260e0
---
c260e0
 src/tool_getparam.c | 123 ++++++++++++++++++++++++++++++++++++++++++----------
c260e0
 1 file changed, 100 insertions(+), 23 deletions(-)
c260e0
c260e0
diff --git a/src/tool_getparam.c b/src/tool_getparam.c
c260e0
index 57cf97d..db29c0d 100644
c260e0
--- a/src/tool_getparam.c
c260e0
+++ b/src/tool_getparam.c
c260e0
@@ -290,6 +290,99 @@ static const struct feat feats[] = {
c260e0
   {"unix-sockets",   CURL_VERSION_UNIX_SOCKETS}
c260e0
 };
c260e0
 
c260e0
+/* https://sourceforge.net/p/curl/bugs/1196/ */
c260e0
+static void parse_cert_parameter(const char *cert_parameter,
c260e0
+                                 char **certname,
c260e0
+                                 char **passphrase)
c260e0
+{
c260e0
+  size_t param_length = strlen(cert_parameter);
c260e0
+  size_t parsed_chars = 0;
c260e0
+  size_t span;
c260e0
+  const char *param_place = NULL;
c260e0
+  char *certname_place = NULL;
c260e0
+  /* most trivial assumption: cert_parameter is empty */
c260e0
+  if(param_length == 0) {
c260e0
+    *certname = NULL;
c260e0
+    *passphrase = NULL;
c260e0
+    return;
c260e0
+  }
c260e0
+  /* next less trivial: cert_parameter contains no colon nor backslash; this
c260e0
+   * means no passphrase was given and no characters escaped */
c260e0
+  if(!strpbrk(cert_parameter, ":\\")) {
c260e0
+    *certname = strdup(cert_parameter);
c260e0
+    *passphrase = NULL;
c260e0
+    return;
c260e0
+  }
c260e0
+  /* deal with escaped chars; find unescaped colon if it exists */
c260e0
+  *certname = (char *) malloc(param_length + 1);
c260e0
+  *passphrase = NULL;
c260e0
+  param_place = cert_parameter;
c260e0
+  certname_place = *certname;
c260e0
+  param_place = cert_parameter;
c260e0
+  while(*param_place) {
c260e0
+    span = strcspn(param_place, ":\\");
c260e0
+    strncpy(certname_place, param_place, span);
c260e0
+    param_place += span;
c260e0
+    certname_place += span;
c260e0
+    *certname_place = '\0';
c260e0
+    /* we just ate all the non-special chars. now we're on either a special
c260e0
+     * char or the end of the string. */
c260e0
+    switch(*param_place) {
c260e0
+    case '\0':
c260e0
+      break;
c260e0
+    case '\\':
c260e0
+      param_place++;
c260e0
+      switch(*param_place) {
c260e0
+        case '\0':
c260e0
+          *certname_place++ = '\\';
c260e0
+          break;
c260e0
+        case '\\':
c260e0
+          *certname_place++ = '\\';
c260e0
+          param_place++;
c260e0
+          break;
c260e0
+        case ':':
c260e0
+          *certname_place++ = ':';
c260e0
+          param_place++;
c260e0
+          break;
c260e0
+        default:
c260e0
+          *certname_place++ = '\\';
c260e0
+          *certname_place++ = *param_place;
c260e0
+          param_place++;
c260e0
+          break;
c260e0
+      }
c260e0
+      break;
c260e0
+    case ':':
c260e0
+      /* Since we live in a world of weirdness and confusion, the win32
c260e0
+         dudes can use : when using drive letters and thus c:\file:password
c260e0
+         needs to work. In order not to break compatibility, we still use : as
c260e0
+         separator, but we try to detect when it is used for a file name! On
c260e0
+         windows. */
c260e0
+#ifdef WIN32
c260e0
+      if(param_place &&
c260e0
+          (param_place == &cert_parameter[1]) &&
c260e0
+          (cert_parameter[2] == '\\' || cert_parameter[2] == '/') &&
c260e0
+          (ISALPHA(cert_parameter[0])) ) {
c260e0
+        /* colon in the second column, followed by a backslash, and the
c260e0
+           first character is an alphabetic letter:
c260e0
+
c260e0
+           this is a drive letter colon */
c260e0
+        *certname_place++ = ':';
c260e0
+        param_place++;
c260e0
+        break;
c260e0
+      }
c260e0
+#endif
c260e0
+      /* escaped colons and Windows drive letter colons were handled
c260e0
+       * above; if we're still here, this is a separating colon */
c260e0
+      param_place++;
c260e0
+      if(strlen(param_place) > 0) {
c260e0
+        *passphrase = strdup(param_place);
c260e0
+      }
c260e0
+      return;
c260e0
+      break;
c260e0
+    }
c260e0
+  }
c260e0
+}
c260e0
+
c260e0
 ParameterError getparameter(char *flag,    /* f or -long-flag */
c260e0
                             char *nextarg, /* NULL if unset */
c260e0
                             bool *usedarg, /* set to TRUE if the arg
c260e0
@@ -1227,30 +1320,14 @@ ParameterError getparameter(char *flag,    /* f or -long-flag */
c260e0
         break;
c260e0
       default: /* certificate file */
c260e0
       {
c260e0
-        char *ptr = strchr(nextarg, ':');
c260e0
-        /* Since we live in a world of weirdness and confusion, the win32
c260e0
-           dudes can use : when using drive letters and thus
c260e0
-           c:\file:password needs to work. In order not to break
c260e0
-           compatibility, we still use : as separator, but we try to detect
c260e0
-           when it is used for a file name! On windows. */
c260e0
-#ifdef WIN32
c260e0
-        if(ptr &&
c260e0
-           (ptr == &nextarg[1]) &&
c260e0
-           (nextarg[2] == '\\' || nextarg[2] == '/') &&
c260e0
-           (ISALPHA(nextarg[0])) )
c260e0
-          /* colon in the second column, followed by a backslash, and the
c260e0
-             first character is an alphabetic letter:
c260e0
-
c260e0
-             this is a drive letter colon */
c260e0
-          ptr = strchr(&nextarg[3], ':'); /* find the next one instead */
c260e0
-#endif
c260e0
-        if(ptr) {
c260e0
-          /* we have a password too */
c260e0
-          *ptr = '\0';
c260e0
-          ptr++;
c260e0
-          GetStr(&config->key_passwd, ptr);
c260e0
+        char *certname, *passphrase;
c260e0
+        parse_cert_parameter(nextarg, &certname, &passphrase);
c260e0
+        if(certname) {
c260e0
+          GetStr(&config->cert, certname);
c260e0
+        }
c260e0
+        if(passphrase) {
c260e0
+          GetStr(&config->key_passwd, passphrase);
c260e0
         }
c260e0
-        GetStr(&config->cert, nextarg);
c260e0
         cleanarg(nextarg);
c260e0
       }
c260e0
       }
c260e0
-- 
c260e0
2.7.4
c260e0
c260e0
c260e0
From 9a5f8a20402e549211d9df1d9ef0cb0b00e5ed8f Mon Sep 17 00:00:00 2001
c260e0
From: Kamil Dudka <kdudka@redhat.com>
c260e0
Date: Fri, 3 May 2013 23:12:00 +0200
c260e0
Subject: [PATCH 02/10] curl.1: document escape sequences recognized by -E
c260e0
c260e0
Upstream-commit: 42e01cff9af12441eb60694af9c0c86817e8f7e0
c260e0
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
c260e0
---
c260e0
 docs/curl.1 | 5 ++++-
c260e0
 1 file changed, 4 insertions(+), 1 deletion(-)
c260e0
c260e0
diff --git a/docs/curl.1 b/docs/curl.1
c260e0
index ad26007..c9bb336 100644
c260e0
--- a/docs/curl.1
c260e0
+++ b/docs/curl.1
c260e0
@@ -397,7 +397,10 @@ curl the nickname of the certificate to use within the NSS database defined
c260e0
 by the environment variable SSL_DIR (or by default /etc/pki/nssdb). If the
c260e0
 NSS PEM PKCS#11 module (libnsspem.so) is available then PEM files may be
c260e0
 loaded. If you want to use a file from the current directory, please precede
c260e0
-it with "./" prefix, in order to avoid confusion with a nickname.
c260e0
+it with "./" prefix, in order to avoid confusion with a nickname.  If the
c260e0
+nickname contains ":", it needs to be preceded by "\\" so that it is not
c260e0
+recognized as password delimiter.  If the nickname contains "\\", it needs to
c260e0
+be escaped as "\\\\" so that it is not recognized as an escape character.
c260e0
 
c260e0
 If this option is used several times, the last one will be used.
c260e0
 .IP "--engine <name>"
c260e0
-- 
c260e0
2.7.4
c260e0
c260e0
c260e0
From fcfd1f85946ed0784365c55cf6c7a196c328308a Mon Sep 17 00:00:00 2001
c260e0
From: Kamil Dudka <kdudka@redhat.com>
c260e0
Date: Fri, 5 Apr 2013 16:10:46 +0200
c260e0
Subject: [PATCH 03/10] tool_getparam: describe what parse_cert_parameter()
c260e0
 does
c260e0
c260e0
... and de-duplicate the code initializing *passphrase
c260e0
c260e0
Upstream-commit: a15b2b6c6204766ef391c1831fb4506635bab0a6
c260e0
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
c260e0
---
c260e0
 src/tool_getparam.c | 12 ++++++------
c260e0
 1 file changed, 6 insertions(+), 6 deletions(-)
c260e0
c260e0
diff --git a/src/tool_getparam.c b/src/tool_getparam.c
c260e0
index db29c0d..77d44c4 100644
c260e0
--- a/src/tool_getparam.c
c260e0
+++ b/src/tool_getparam.c
c260e0
@@ -290,32 +290,33 @@ static const struct feat feats[] = {
c260e0
   {"unix-sockets",   CURL_VERSION_UNIX_SOCKETS}
c260e0
 };
c260e0
 
c260e0
-/* https://sourceforge.net/p/curl/bugs/1196/ */
c260e0
+/* Split the argument of -E to 'certname' and 'passphrase' separated by colon.
c260e0
+ * We allow ':' and '\' to be escaped by '\' so that we can use certificate
c260e0
+ * nicknames containing ':'.  See <https://sourceforge.net/p/curl/bugs/1196/>
c260e0
+ * for details. */
c260e0
 static void parse_cert_parameter(const char *cert_parameter,
c260e0
                                  char **certname,
c260e0
                                  char **passphrase)
c260e0
 {
c260e0
   size_t param_length = strlen(cert_parameter);
c260e0
-  size_t parsed_chars = 0;
c260e0
   size_t span;
c260e0
   const char *param_place = NULL;
c260e0
   char *certname_place = NULL;
c260e0
+  *passphrase = NULL;
c260e0
+
c260e0
   /* most trivial assumption: cert_parameter is empty */
c260e0
   if(param_length == 0) {
c260e0
     *certname = NULL;
c260e0
-    *passphrase = NULL;
c260e0
     return;
c260e0
   }
c260e0
   /* next less trivial: cert_parameter contains no colon nor backslash; this
c260e0
    * means no passphrase was given and no characters escaped */
c260e0
   if(!strpbrk(cert_parameter, ":\\")) {
c260e0
     *certname = strdup(cert_parameter);
c260e0
-    *passphrase = NULL;
c260e0
     return;
c260e0
   }
c260e0
   /* deal with escaped chars; find unescaped colon if it exists */
c260e0
   *certname = (char *) malloc(param_length + 1);
c260e0
-  *passphrase = NULL;
c260e0
   param_place = cert_parameter;
c260e0
   certname_place = *certname;
c260e0
   param_place = cert_parameter;
c260e0
@@ -378,7 +379,6 @@ static void parse_cert_parameter(const char *cert_parameter,
c260e0
         *passphrase = strdup(param_place);
c260e0
       }
c260e0
       return;
c260e0
-      break;
c260e0
     }
c260e0
   }
c260e0
 }
c260e0
-- 
c260e0
2.7.4
c260e0
c260e0
c260e0
From d9bbc65a4624ba78576e2a7d98dbbeccd4b8a3b3 Mon Sep 17 00:00:00 2001
c260e0
From: Kamil Dudka <kdudka@redhat.com>
c260e0
Date: Fri, 3 May 2013 22:16:46 +0200
c260e0
Subject: [PATCH 04/10] tool_getparam: fix memleak in handling the -E option
c260e0
c260e0
Upstream-commit: b47cf4f688297d9cf87a39c8aa328d9d07540e66
c260e0
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
c260e0
---
c260e0
 src/tool_getparam.c | 8 ++++----
c260e0
 1 file changed, 4 insertions(+), 4 deletions(-)
c260e0
c260e0
diff --git a/src/tool_getparam.c b/src/tool_getparam.c
c260e0
index 77d44c4..02d95a7 100644
c260e0
--- a/src/tool_getparam.c
c260e0
+++ b/src/tool_getparam.c
c260e0
@@ -1322,11 +1322,11 @@ ParameterError getparameter(char *flag,    /* f or -long-flag */
c260e0
       {
c260e0
         char *certname, *passphrase;
c260e0
         parse_cert_parameter(nextarg, &certname, &passphrase);
c260e0
-        if(certname) {
c260e0
-          GetStr(&config->cert, certname);
c260e0
-        }
c260e0
+        Curl_safefree(config->cert);
c260e0
+        config->cert = certname;
c260e0
         if(passphrase) {
c260e0
-          GetStr(&config->key_passwd, passphrase);
c260e0
+          Curl_safefree(config->key_passwd);
c260e0
+          config->key_passwd = passphrase;
c260e0
         }
c260e0
         cleanarg(nextarg);
c260e0
       }
c260e0
-- 
c260e0
2.7.4
c260e0
c260e0
c260e0
From 0cadf08557da47b826e8f3b3973be2fc80e50068 Mon Sep 17 00:00:00 2001
c260e0
From: Kamil Dudka <kdudka@redhat.com>
c260e0
Date: Fri, 3 May 2013 22:57:18 +0200
c260e0
Subject: [PATCH 05/10] tool_getparam: ensure string termination in
c260e0
 parse_cert_parameter()
c260e0
c260e0
Upstream-commit: 2de20dd9a1c6ad4d576c60ab704c30abfc826b1a
c260e0
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
c260e0
---
c260e0
 src/tool_getparam.c | 19 +++++++++++--------
c260e0
 1 file changed, 11 insertions(+), 8 deletions(-)
c260e0
c260e0
diff --git a/src/tool_getparam.c b/src/tool_getparam.c
c260e0
index 02d95a7..dd04f5f 100644
c260e0
--- a/src/tool_getparam.c
c260e0
+++ b/src/tool_getparam.c
c260e0
@@ -302,13 +302,13 @@ static void parse_cert_parameter(const char *cert_parameter,
c260e0
   size_t span;
c260e0
   const char *param_place = NULL;
c260e0
   char *certname_place = NULL;
c260e0
+  *certname = NULL;
c260e0
   *passphrase = NULL;
c260e0
 
c260e0
   /* most trivial assumption: cert_parameter is empty */
c260e0
-  if(param_length == 0) {
c260e0
-    *certname = NULL;
c260e0
+  if(param_length == 0)
c260e0
     return;
c260e0
-  }
c260e0
+
c260e0
   /* next less trivial: cert_parameter contains no colon nor backslash; this
c260e0
    * means no passphrase was given and no characters escaped */
c260e0
   if(!strpbrk(cert_parameter, ":\\")) {
c260e0
@@ -316,16 +316,17 @@ static void parse_cert_parameter(const char *cert_parameter,
c260e0
     return;
c260e0
   }
c260e0
   /* deal with escaped chars; find unescaped colon if it exists */
c260e0
-  *certname = (char *) malloc(param_length + 1);
c260e0
-  param_place = cert_parameter;
c260e0
-  certname_place = *certname;
c260e0
+  certname_place = malloc(param_length + 1);
c260e0
+  if(!certname_place)
c260e0
+    return;
c260e0
+
c260e0
+  *certname = certname_place;
c260e0
   param_place = cert_parameter;
c260e0
   while(*param_place) {
c260e0
     span = strcspn(param_place, ":\\");
c260e0
     strncpy(certname_place, param_place, span);
c260e0
     param_place += span;
c260e0
     certname_place += span;
c260e0
-    *certname_place = '\0';
c260e0
     /* we just ate all the non-special chars. now we're on either a special
c260e0
      * char or the end of the string. */
c260e0
     switch(*param_place) {
c260e0
@@ -378,9 +379,11 @@ static void parse_cert_parameter(const char *cert_parameter,
c260e0
       if(strlen(param_place) > 0) {
c260e0
         *passphrase = strdup(param_place);
c260e0
       }
c260e0
-      return;
c260e0
+      goto done;
c260e0
     }
c260e0
   }
c260e0
+done:
c260e0
+  *certname_place = '\0';
c260e0
 }
c260e0
 
c260e0
 ParameterError getparameter(char *flag,    /* f or -long-flag */
c260e0
-- 
c260e0
2.7.4
c260e0
c260e0
c260e0
From 47447c9e89e7f9b5acd60ca565996428d90b9e0e Mon Sep 17 00:00:00 2001
c260e0
From: Kamil Dudka <kdudka@redhat.com>
c260e0
Date: Fri, 3 May 2013 23:03:58 +0200
c260e0
Subject: [PATCH 06/10] src/Makefile.am: build static lib for unit tests if
c260e0
 enabled
c260e0
c260e0
Upstream-commit: 683f2b832388d08999620ee45cb619a7afd42aaf
c260e0
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
c260e0
---
c260e0
 src/Makefile.am        |  8 ++++++++
c260e0
 src/tool_main.c        |  4 ++++
c260e0
 tests/unit/Makefile.am | 11 +++++++++--
c260e0
 3 files changed, 21 insertions(+), 2 deletions(-)
c260e0
c260e0
diff --git a/src/Makefile.am b/src/Makefile.am
c260e0
index 6863078..751beda 100644
c260e0
--- a/src/Makefile.am
c260e0
+++ b/src/Makefile.am
c260e0
@@ -67,6 +67,14 @@ curl_LDFLAGS = @LIBMETALINK_LDFLAGS@
c260e0
 curl_CPPFLAGS = $(AM_CPPFLAGS) $(LIBMETALINK_CPPFLAGS)
c260e0
 curl_DEPENDENCIES = $(top_builddir)/lib/libcurl.la
c260e0
 
c260e0
+# if unit tests are enabled, build a static library to link them with
c260e0
+if BUILD_UNITTESTS
c260e0
+noinst_LTLIBRARIES = libcurltool.la
c260e0
+libcurltool_la_CFLAGS = -DUNITTESTS
c260e0
+libcurltool_la_LDFLAGS = -static $(LINKFLAGS)
c260e0
+libcurltool_la_SOURCES = $(curl_SOURCES)
c260e0
+endif
c260e0
+
c260e0
 BUILT_SOURCES = tool_hugehelp.c
c260e0
 CLEANFILES = tool_hugehelp.c
c260e0
 # Use the C locale to ensure that only ASCII characters appear in the
c260e0
diff --git a/src/tool_main.c b/src/tool_main.c
c260e0
index 6a1ed6c..00d8411 100644
c260e0
--- a/src/tool_main.c
c260e0
+++ b/src/tool_main.c
c260e0
@@ -59,6 +59,9 @@
c260e0
 static int vms_show = 0;
c260e0
 #endif
c260e0
 
c260e0
+/* if we build a static library for unit tests, there is no main() function */
c260e0
+#ifndef UNITTESTS
c260e0
+
c260e0
 /*
c260e0
  * Ensure that file descriptors 0, 1 and 2 (stdin, stdout, stderr) are
c260e0
  * open before starting to run.  Otherwise, the first three network
c260e0
@@ -128,3 +131,4 @@ int main(int argc, char *argv[])
c260e0
 #endif
c260e0
 }
c260e0
 
c260e0
+#endif /* ndef UNITTESTS */
c260e0
diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am
c260e0
index 12d5fe3..ce6af6f 100644
c260e0
--- a/tests/unit/Makefile.am
c260e0
+++ b/tests/unit/Makefile.am
c260e0
@@ -40,6 +40,7 @@ AM_CPPFLAGS = -I$(top_builddir)/include/curl \
c260e0
               -I$(top_srcdir)/include        \
c260e0
               -I$(top_builddir)/lib          \
c260e0
               -I$(top_srcdir)/lib            \
c260e0
+              -I$(top_srcdir)/src            \
c260e0
               -I$(top_srcdir)/tests/libtest  \
c260e0
               -I$(top_builddir)/ares         \
c260e0
               -I$(top_srcdir)/ares
c260e0
@@ -49,6 +50,7 @@ AM_CPPFLAGS = -I$(top_builddir)/include/curl \
c260e0
               -I$(top_srcdir)/include        \
c260e0
               -I$(top_builddir)/lib          \
c260e0
               -I$(top_srcdir)/lib            \
c260e0
+              -I$(top_srcdir)/src            \
c260e0
               -I$(top_srcdir)/tests/libtest
c260e0
 endif
c260e0
 
c260e0
@@ -57,8 +59,13 @@ EXTRA_DIST = Makefile.inc
c260e0
 # Prevent LIBS from being used for all link targets
c260e0
 LIBS = $(BLANK_AT_MAKETIME)
c260e0
 
c260e0
-LDADD = $(top_builddir)/lib/libcurlu.la @LDFLAGS@ @LIBCURL_LIBS@
c260e0
-DEPENDENCIES = $(top_builddir)/lib/libcurlu.la
c260e0
+LDADD = $(top_builddir)/src/libcurltool.la   \
c260e0
+        $(top_builddir)/lib/libcurlu.la      \
c260e0
+        @LDFLAGS@ @LIBCURL_LIBS@
c260e0
+
c260e0
+DEPENDENCIES = $(top_builddir)/src/libcurltool.la \
c260e0
+               $(top_builddir)/lib/libcurlu.la
c260e0
+
c260e0
 AM_CPPFLAGS += -DUNITTESTS
c260e0
 
c260e0
 # Mostly for Windows build targets, when using static libcurl
c260e0
-- 
c260e0
2.7.4
c260e0
c260e0
c260e0
From fb3618a22db456813a3064118e80a55ac2abb8c1 Mon Sep 17 00:00:00 2001
c260e0
From: Jared Jennings <jjenning@fastmail.fm>
c260e0
Date: Fri, 5 Apr 2013 16:01:31 +0200
c260e0
Subject: [PATCH 07/10] unit1394.c: basis of a unit test for
c260e0
 parse_cert_parameter()
c260e0
c260e0
Upstream-commit: b045d079f8bf9e85b2aef94bc94928f444b3a711
c260e0
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
c260e0
---
c260e0
 tests/unit/unit1394.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++
c260e0
 1 file changed, 75 insertions(+)
c260e0
 create mode 100644 tests/unit/unit1394.c
c260e0
c260e0
diff --git a/tests/unit/unit1394.c b/tests/unit/unit1394.c
c260e0
new file mode 100644
c260e0
index 0000000..11a47b9
c260e0
--- /dev/null
c260e0
+++ b/tests/unit/unit1394.c
c260e0
@@ -0,0 +1,75 @@
c260e0
+#include <stdio.h>
c260e0
+#include <stdlib.h>
c260e0
+#include <string.h>
c260e0
+
c260e0
+int main(int argc, char **argv) {
c260e0
+  char *values[] = {
c260e0
+    /* -E parameter */        /* exp. cert name */  /* exp. passphrase */
c260e0
+    "foo:bar:baz",            "foo",                "bar:baz",
c260e0
+    "foo\\:bar:baz",          "foo:bar",            "baz",
c260e0
+    "foo\\\\:bar:baz",        "foo\\",              "bar:baz",
c260e0
+    "foo:bar\\:baz",          "foo",                "bar\\:baz",
c260e0
+    "foo:bar\\\\:baz",        "foo",                "bar\\\\:baz",
c260e0
+    "foo\\bar\\baz",          "foo\\bar\\baz",      NULL,
c260e0
+    "foo\\\\bar\\\\baz",      "foo\\bar\\baz",      NULL,
c260e0
+    "foo\\",                  "foo\\",              NULL,
c260e0
+    "foo\\\\",                "foo\\",              NULL,
c260e0
+    "foo:bar\\",              "foo",                "bar\\",
c260e0
+    "foo:bar\\\\",            "foo",                "bar\\\\",
c260e0
+    "foo:bar:",               "foo",                "bar:",
c260e0
+    "foo\\::bar\\:",          "foo:",               "bar\\:",
c260e0
+    "c:\\foo:bar:baz",        "c:\\foo",            "bar:baz",
c260e0
+    "c:\\foo\\:bar:baz",      "c:\\foo:bar",        "baz",
c260e0
+    "c:\\foo\\\\:bar:baz",    "c:\\foo\\",          "bar:baz",
c260e0
+    "c:\\foo:bar\\:baz",      "c:\\foo",            "bar\\:baz",
c260e0
+    "c:\\foo:bar\\\\:baz",    "c:\\foo",            "bar\\\\:baz",
c260e0
+    "c:\\foo\\bar\\baz",      "c:\\foo\\bar\\baz",  NULL,
c260e0
+    "c:\\foo\\\\bar\\\\baz",  "c:\\foo\\bar\\baz",  NULL,
c260e0
+    "c:\\foo\\",              "c:\\foo\\",          NULL,
c260e0
+    "c:\\foo\\\\",            "c:\\foo\\",          NULL,
c260e0
+    "c:\\foo:bar\\",          "c:\\foo",            "bar\\",
c260e0
+    "c:\\foo:bar\\\\",        "c:\\foo",            "bar\\\\",
c260e0
+    "c:\\foo:bar:",           "c:\\foo",            "bar:",
c260e0
+    "c:\\foo\\::bar\\:",      "c:\\foo:",           "bar\\:",
c260e0
+    NULL,                     NULL,                 NULL,
c260e0
+  };
c260e0
+  char **p;
c260e0
+  char *certname, *passphrase;
c260e0
+  for(p = values; *p; p += 3) {
c260e0
+    parse_cert_parameter(p[0], &certname, &passphrase);
c260e0
+    if(p[1]) {
c260e0
+      if(certname) {
c260e0
+        if(strcmp(p[1], certname)) {
c260e0
+          printf("expected certname '%s' but got '%s' "
c260e0
+              "for -E param '%s'\n", p[1], certname, p[0]);
c260e0
+        }
c260e0
+      } else {
c260e0
+        printf("expected certname '%s' but got NULL "
c260e0
+            "for -E param '%s'\n", p[1], p[0]);
c260e0
+      }
c260e0
+    } else {
c260e0
+      if(certname) {
c260e0
+        printf("expected certname NULL but got '%s' "
c260e0
+            "for -E param '%s'\n", certname, p[0]);
c260e0
+      }
c260e0
+    }
c260e0
+    if(p[2]) {
c260e0
+      if(passphrase) {
c260e0
+        if(strcmp(p[2], passphrase)) {
c260e0
+          printf("expected passphrase '%s' but got '%s'"
c260e0
+              "for -E param '%s'\n", p[2], passphrase, p[0]);
c260e0
+        }
c260e0
+      } else {
c260e0
+        printf("expected passphrase '%s' but got NULL "
c260e0
+            "for -E param '%s'\n", p[2], p[0]);
c260e0
+      }
c260e0
+    } else {
c260e0
+      if(passphrase) {
c260e0
+        printf("expected passphrase NULL but got '%s' "
c260e0
+            "for -E param '%s'\n", passphrase, p[0]);
c260e0
+      }
c260e0
+    }
c260e0
+    if(certname) free(certname);
c260e0
+    if(passphrase) free(passphrase);
c260e0
+  }
c260e0
+}
c260e0
-- 
c260e0
2.7.4
c260e0
c260e0
c260e0
From 2af1560a4b38c33089916cadfe7d8a8e8f44b7d3 Mon Sep 17 00:00:00 2001
c260e0
From: Kamil Dudka <kdudka@redhat.com>
c260e0
Date: Fri, 3 May 2013 13:26:25 +0200
c260e0
Subject: [PATCH 08/10] unit1394.c: plug the curl tool unit test in
c260e0
c260e0
Upstream-commit: bcf1b9dec13badd073518e1d63aab40a958d9245
c260e0
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
c260e0
---
c260e0
 src/tool_getparam.c     |  9 +++++---
c260e0
 src/tool_getparam.h     |  6 ++++++
c260e0
 tests/data/test1394     | 30 ++++++++++++++++++++++++++
c260e0
 tests/unit/Makefile.inc |  4 +++-
c260e0
 tests/unit/unit1394.c   | 56 +++++++++++++++++++++++++++++++++++++++++++++----
c260e0
 5 files changed, 97 insertions(+), 8 deletions(-)
c260e0
 create mode 100644 tests/data/test1394
c260e0
c260e0
diff --git a/src/tool_getparam.c b/src/tool_getparam.c
c260e0
index dd04f5f..33db742 100644
c260e0
--- a/src/tool_getparam.c
c260e0
+++ b/src/tool_getparam.c
c260e0
@@ -294,9 +294,12 @@ static const struct feat feats[] = {
c260e0
  * We allow ':' and '\' to be escaped by '\' so that we can use certificate
c260e0
  * nicknames containing ':'.  See <https://sourceforge.net/p/curl/bugs/1196/>
c260e0
  * for details. */
c260e0
-static void parse_cert_parameter(const char *cert_parameter,
c260e0
-                                 char **certname,
c260e0
-                                 char **passphrase)
c260e0
+#ifndef UNITTESTS
c260e0
+static
c260e0
+#endif
c260e0
+void parse_cert_parameter(const char *cert_parameter,
c260e0
+                          char **certname,
c260e0
+                          char **passphrase)
c260e0
 {
c260e0
   size_t param_length = strlen(cert_parameter);
c260e0
   size_t span;
c260e0
diff --git a/src/tool_getparam.h b/src/tool_getparam.h
c260e0
index 38f0674..a86bfce 100644
c260e0
--- a/src/tool_getparam.h
c260e0
+++ b/src/tool_getparam.h
c260e0
@@ -45,5 +45,11 @@ ParameterError getparameter(char *flag,
c260e0
                             bool *usedarg,
c260e0
                             struct Configurable *config);
c260e0
 
c260e0
+#ifdef UNITTESTS
c260e0
+void parse_cert_parameter(const char *cert_parameter,
c260e0
+                          char **certname,
c260e0
+                          char **passphrase);
c260e0
+#endif
c260e0
+
c260e0
 #endif /* HEADER_CURL_TOOL_GETPARAM_H */
c260e0
 
c260e0
diff --git a/tests/data/test1394 b/tests/data/test1394
c260e0
new file mode 100644
c260e0
index 0000000..34d4a0e
c260e0
--- /dev/null
c260e0
+++ b/tests/data/test1394
c260e0
@@ -0,0 +1,30 @@
c260e0
+<testcase>
c260e0
+<info>
c260e0
+<keywords>
c260e0
+unittest
c260e0
+</keywords>
c260e0
+</info>
c260e0
+
c260e0
+#
c260e0
+# Client-side
c260e0
+<client>
c260e0
+<server>
c260e0
+none
c260e0
+</server>
c260e0
+<features>
c260e0
+unittest
c260e0
+</features>
c260e0
+ <name>
c260e0
+unit test for parse_cert_parameter()
c260e0
+ </name>
c260e0
+<tool>
c260e0
+unit1394
c260e0
+</tool>
c260e0
+</client>
c260e0
+
c260e0
+<verify>
c260e0
+<stdout mode="text">
c260e0
+</stdout>
c260e0
+</verify>
c260e0
+
c260e0
+</testcase>
c260e0
diff --git a/tests/unit/Makefile.inc b/tests/unit/Makefile.inc
c260e0
index 20835d7..4490095 100644
c260e0
--- a/tests/unit/Makefile.inc
c260e0
+++ b/tests/unit/Makefile.inc
c260e0
@@ -6,7 +6,7 @@ UNITFILES = curlcheck.h \
c260e0
 
c260e0
 # These are all unit test programs
c260e0
 UNITPROGS = unit1300 unit1301 unit1302 unit1303 unit1304 unit1305 unit1307 \
c260e0
- unit1308 unit1309
c260e0
+ unit1308 unit1309 unit1394
c260e0
 
c260e0
 unit1300_SOURCES = unit1300.c $(UNITFILES)
c260e0
 unit1300_CPPFLAGS = $(AM_CPPFLAGS)
c260e0
@@ -35,3 +35,5 @@ unit1308_CPPFLAGS = $(AM_CPPFLAGS)
c260e0
 unit1309_SOURCES = unit1309.c $(UNITFILES)
c260e0
 unit1309_CPPFLAGS = $(AM_CPPFLAGS)
c260e0
 
c260e0
+unit1394_SOURCES = unit1394.c $(UNITFILES)
c260e0
+unit1394_CPPFLAGS = $(AM_CPPFLAGS)
c260e0
diff --git a/tests/unit/unit1394.c b/tests/unit/unit1394.c
c260e0
index 11a47b9..d25e4f5 100644
c260e0
--- a/tests/unit/unit1394.c
c260e0
+++ b/tests/unit/unit1394.c
c260e0
@@ -1,9 +1,48 @@
c260e0
+/***************************************************************************
c260e0
+ *                                  _   _ ____  _
c260e0
+ *  Project                     ___| | | |  _ \| |
c260e0
+ *                             / __| | | | |_) | |
c260e0
+ *                            | (__| |_| |  _ <| |___
c260e0
+ *                             \___|\___/|_| \_\_____|
c260e0
+ *
c260e0
+ * Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
c260e0
+ *
c260e0
+ * This software is licensed as described in the file COPYING, which
c260e0
+ * you should have received as part of this distribution. The terms
c260e0
+ * are also available at http://curl.haxx.se/docs/copyright.html.
c260e0
+ *
c260e0
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
c260e0
+ * copies of the Software, and permit persons to whom the Software is
c260e0
+ * furnished to do so, under the terms of the COPYING file.
c260e0
+ *
c260e0
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
c260e0
+ * KIND, either express or implied.
c260e0
+ *
c260e0
+ ***************************************************************************/
c260e0
+#include "curlcheck.h"
c260e0
+
c260e0
+#include "tool_getparam.h"
c260e0
+
c260e0
 #include <stdio.h>
c260e0
 #include <stdlib.h>
c260e0
 #include <string.h>
c260e0
 
c260e0
-int main(int argc, char **argv) {
c260e0
-  char *values[] = {
c260e0
+#include "curl_memory.h"
c260e0
+#include "memdebug.h" /* LAST include file */
c260e0
+
c260e0
+static CURLcode unit_setup(void)
c260e0
+{
c260e0
+  return CURLE_OK;
c260e0
+}
c260e0
+
c260e0
+static void unit_stop(void)
c260e0
+{
c260e0
+
c260e0
+}
c260e0
+
c260e0
+UNITTEST_START
c260e0
+
c260e0
+  const char *values[] = {
c260e0
     /* -E parameter */        /* exp. cert name */  /* exp. passphrase */
c260e0
     "foo:bar:baz",            "foo",                "bar:baz",
c260e0
     "foo\\:bar:baz",          "foo:bar",            "baz",
c260e0
@@ -18,6 +57,7 @@ int main(int argc, char **argv) {
c260e0
     "foo:bar\\\\",            "foo",                "bar\\\\",
c260e0
     "foo:bar:",               "foo",                "bar:",
c260e0
     "foo\\::bar\\:",          "foo:",               "bar\\:",
c260e0
+#ifdef WIN32
c260e0
     "c:\\foo:bar:baz",        "c:\\foo",            "bar:baz",
c260e0
     "c:\\foo\\:bar:baz",      "c:\\foo:bar",        "baz",
c260e0
     "c:\\foo\\\\:bar:baz",    "c:\\foo\\",          "bar:baz",
c260e0
@@ -31,9 +71,10 @@ int main(int argc, char **argv) {
c260e0
     "c:\\foo:bar\\\\",        "c:\\foo",            "bar\\\\",
c260e0
     "c:\\foo:bar:",           "c:\\foo",            "bar:",
c260e0
     "c:\\foo\\::bar\\:",      "c:\\foo:",           "bar\\:",
c260e0
+#endif
c260e0
     NULL,                     NULL,                 NULL,
c260e0
   };
c260e0
-  char **p;
c260e0
+  const char **p;
c260e0
   char *certname, *passphrase;
c260e0
   for(p = values; *p; p += 3) {
c260e0
     parse_cert_parameter(p[0], &certname, &passphrase);
c260e0
@@ -42,15 +83,18 @@ int main(int argc, char **argv) {
c260e0
         if(strcmp(p[1], certname)) {
c260e0
           printf("expected certname '%s' but got '%s' "
c260e0
               "for -E param '%s'\n", p[1], certname, p[0]);
c260e0
+          fail("assertion failure");
c260e0
         }
c260e0
       } else {
c260e0
         printf("expected certname '%s' but got NULL "
c260e0
             "for -E param '%s'\n", p[1], p[0]);
c260e0
+        fail("assertion failure");
c260e0
       }
c260e0
     } else {
c260e0
       if(certname) {
c260e0
         printf("expected certname NULL but got '%s' "
c260e0
             "for -E param '%s'\n", certname, p[0]);
c260e0
+        fail("assertion failure");
c260e0
       }
c260e0
     }
c260e0
     if(p[2]) {
c260e0
@@ -58,18 +102,22 @@ int main(int argc, char **argv) {
c260e0
         if(strcmp(p[2], passphrase)) {
c260e0
           printf("expected passphrase '%s' but got '%s'"
c260e0
               "for -E param '%s'\n", p[2], passphrase, p[0]);
c260e0
+          fail("assertion failure");
c260e0
         }
c260e0
       } else {
c260e0
         printf("expected passphrase '%s' but got NULL "
c260e0
             "for -E param '%s'\n", p[2], p[0]);
c260e0
+        fail("assertion failure");
c260e0
       }
c260e0
     } else {
c260e0
       if(passphrase) {
c260e0
         printf("expected passphrase NULL but got '%s' "
c260e0
             "for -E param '%s'\n", passphrase, p[0]);
c260e0
+        fail("assertion failure");
c260e0
       }
c260e0
     }
c260e0
     if(certname) free(certname);
c260e0
     if(passphrase) free(passphrase);
c260e0
   }
c260e0
-}
c260e0
+
c260e0
+UNITTEST_STOP
c260e0
-- 
c260e0
2.7.4
c260e0
c260e0
c260e0
From fc2acbf743634f400efb8ec84748eed7267ead15 Mon Sep 17 00:00:00 2001
c260e0
From: Daniel Stenberg <daniel@haxx.se>
c260e0
Date: Sun, 19 May 2013 12:44:44 +0200
c260e0
Subject: [PATCH 09/10] tests: add test1394 file to the tarball
c260e0
c260e0
Upstream-commit: fc4759af9d9cbc7635af0da68c28672a4bbf35ff
c260e0
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
c260e0
---
c260e0
 tests/data/Makefile.am | 2 +-
c260e0
 1 file changed, 1 insertion(+), 1 deletion(-)
c260e0
c260e0
diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am
c260e0
index 35bc6eb..3b31581 100644
c260e0
--- a/tests/data/Makefile.am
c260e0
+++ b/tests/data/Makefile.am
c260e0
@@ -90,7 +90,7 @@ test1355 test1356 test1357 test1358 test1359 test1360 test1361 test1362 \
c260e0
 test1363 test1364 test1365 test1366 test1367 test1368 test1369 test1370 \
c260e0
 test1371 test1372 test1373 test1374 test1375 test1376 test1377 test1378 \
c260e0
 test1379 test1380 test1381 test1382 test1383 test1384 test1385 test1386 \
c260e0
-test1387 test1388 test1389 test1390 test1391 test1392 test1393 \
c260e0
+test1387 test1388 test1389 test1390 test1391 test1392 test1393 test1394 \
c260e0
 test1400 test1401 test1402 test1403 test1404 test1405 test1406 test1407 \
c260e0
 test1408 test1409 test1410 test1411 test1412 test1413 test1415 \
c260e0
 test1435 test1436 \
c260e0
-- 
c260e0
2.7.4
c260e0
c260e0
c260e0
From c4fe8629b69e4d5d642d3833a0208b2f65258d31 Mon Sep 17 00:00:00 2001
c260e0
From: Daniel Stenberg <daniel@haxx.se>
c260e0
Date: Thu, 29 Aug 2013 12:50:15 +0200
c260e0
Subject: [PATCH 10/10] unit1304: include memdebug and free everything
c260e0
 correctly
c260e0
c260e0
Upstream-commit: d737aa19c89f12c1415637a60afc79a6ea9c649f
c260e0
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
c260e0
---
c260e0
 tests/unit/unit1304.c | 7 +++++--
c260e0
 1 file changed, 5 insertions(+), 2 deletions(-)
c260e0
c260e0
diff --git a/tests/unit/unit1304.c b/tests/unit/unit1304.c
c260e0
index 9242e80..dcd8fa7 100644
c260e0
--- a/tests/unit/unit1304.c
c260e0
+++ b/tests/unit/unit1304.c
c260e0
@@ -5,7 +5,7 @@
c260e0
  *                            | (__| |_| |  _ <| |___
c260e0
  *                             \___|\___/|_| \_\_____|
c260e0
  *
c260e0
- * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
c260e0
+ * Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
c260e0
  *
c260e0
  * This software is licensed as described in the file COPYING, which
c260e0
  * you should have received as part of this distribution. The terms
c260e0
@@ -20,8 +20,8 @@
c260e0
  *
c260e0
  ***************************************************************************/
c260e0
 #include "curlcheck.h"
c260e0
-
c260e0
 #include "netrc.h"
c260e0
+#include "memdebug.h" /* LAST include file */
c260e0
 
c260e0
 static char *login;
c260e0
 static char *password;
c260e0
@@ -144,6 +144,9 @@ UNITTEST_START
c260e0
               "password should be 'none'");
c260e0
   fail_unless(strncmp(login, "none", 4) == 0, "login should be 'none'");
c260e0
 
c260e0
+  free(login);
c260e0
+  free(password);
c260e0
+
c260e0
   /* TODO:
c260e0
    * Test over the size limit password / login!
c260e0
    * Test files with a bad format
c260e0
-- 
c260e0
2.7.4
c260e0