gnutls-cli: handle binary data from stdin

Simon Josefsson simon at josefsson.org
Wed Jan 27 10:31:04 CET 2010


Vitaly Mayatskikh <v.mayatskih at gmail.com> writes:

> 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.

Thanks.  How well have you tested it?  I'm surprised there aren't more
text-oriented assumptions in the code.  However I believe we should use
getline instead of fgets/read to avoid the fixed size buffer.  It should
handle binary data transparent.

/Simon

> 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)
>  	    {





More information about the Gnutls-devel mailing list