gnutls-cli: handle binary data from stdin

Vitaly Mayatskikh v.mayatskih at gmail.com
Mon Jan 25 16:00:23 CET 2010


Hello!

gnutls-cli is used as TLS wrapper in several MUAs (like Gnus and
Wanderlust) to access secured IMAP mail servers. IMAP proto has
extension RFC4978 for traffic compression with deflate
method. However, gnutls-cli is pure text-oriented client, so it can't
handle binary data from stdin correctly.

This trivial patch fixes the problem.

P.s.: Please, keep me in Cc, I'm not subscribed to the list.

--- src/cli.c.orig	2009-06-02 20:59:32.000000000 +0200
+++ src/cli.c	2010-01-25 15:52:59.504321067 +0100
@@ -558,6 +558,7 @@ main (int argc, char **argv)
   struct timeval tv;
   int user_term = 0, retval = 0;
   socket_st hd;
+  int bytes;
 
   set_program_name (argv[0]);
 
@@ -749,7 +750,7 @@ after_handshake:
 
       if (FD_ISSET (fileno (stdin), &rset))
 	{
-	  if (fgets (buffer, MAX_BUF, stdin) == NULL)
+	  if ((bytes = read (fileno(stdin), buffer, MAX_BUF)) < 0)
 	    {
 	      if (hd.secure == 0)
 		{
@@ -778,11 +779,13 @@ after_handshake:
 	  if (crlf != 0)
 	    {
 	      char *b = strchr (buffer, '\n');
-	      if (b != NULL)
+	      if (b != NULL) {
 		strcpy (b, "\r\n");
+		bytes++;
+	      }
 	    }
 
-	  ret = socket_send (&hd, buffer, strlen (buffer));
+	  ret = socket_send (&hd, buffer, bytes);
 
 	  if (ret > 0)
 	    {

-- 
wbr, Vitaly





More information about the Gnutls-devel mailing list