Re: bug in sslio

Gerrit Pape <[email protected]>
Newsgroups gmane.comp.misc.pape.general
Message-ID <[email protected]>
On Sun, Jul 22, 2007 at 11:25:57AM +0300, Nikola Vladov wrote:
> http://riemann.fmi.uni-sofia.bg/programs/ipsvd-0.12.1_matrixssl-1-8-open.tar.gz
> 
> There is a bug in sslio program.  Demo:
> Setup a server on 127.0.0.1:5443 using tcpserver and sslio.
> 
> Let the server have timeout 
> (like fnord.  or use simply sleep 20 as server).
> 
> Then try:
> mconnect 127.0.0.1 5443 &   # (or telnet)
> 
> On an other terminal wait more then 30 sec.
> The child (fnord exists) and sslio wait vor ever.
> 
> I introduced one new variavle "SSLIO_TIMEOUT".  If it is nonempty
> sslio stops and exit when the child (fnord) doesn't exists.
> 
> See my patch above.

Hi Nikola, thanks.  I suggest a slightly different patch though, what do
you think?:

---
 man/sslio.8  |   10 ++++++++++
 src/ssl_io.c |   24 ++++++++++++++++++++++--
 2 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/man/sslio.8 b/man/sslio.8
index 4a0ca7a..1e7cc6c 100644
--- a/man/sslio.8
+++ b/man/sslio.8
@@ -187,6 +187,16 @@ is set,
 accepts server ceritificates it would normally reject with
 .
  fatal: ssl decode error: bad certificate
+.TP
+SSLIO_HANDSHAKE_TIMOUT
+The environment variable
+.I SSLIO_HANDSHAKE_TIMEOUT
+overrides the default number of seconds
+.B sslio
+will try to complete the ssl handshake (300).
+If the handshake isn't completed after this number of seconds,
+.B sslio
+exits.
 .SH SEE ALSO
 sslsvd(8),
 tcpsvd(8),
diff --git a/src/ssl_io.c b/src/ssl_io.c
index 28f1d96..bc3d3e3 100644
--- a/src/ssl_io.c
+++ b/src/ssl_io.c
@@ -82,6 +82,7 @@ static int rc;
 static int handshake =1;
 static int getdec =1;
 static char *s;
+static unsigned long handshake_timeout =300;
 
 static sslBuf_t encin, encou;
 static stralloc encinbuf ={0};
@@ -267,6 +268,7 @@ void doio(void) {
   iopause_fd x[2];
   struct taia deadline;
   struct taia now;
+  struct taia timeout;
 
   if (! stralloc_ready(&encinbuf, bufsizein)) die_nomem();
   encin.buf =encin.start =encin.end =encinbuf.s; encin.size =bufsizein;
@@ -289,6 +291,10 @@ void doio(void) {
     decou.start =decou.end =decou.buf;
   }
 
+  taia_now(&now);
+  taia_uint(&timeout, handshake_timeout);
+  taia_add(&timeout, &now, &timeout);
+
   for (;;) {
     iopause_fd *xx =x;
     int l =2;
@@ -305,8 +311,19 @@ void doio(void) {
     if (! l) return;
 
     taia_now(&now);
-    taia_uint(&deadline, 30);
-    taia_add(&deadline, &now, &deadline);
+    if (handshake) {
+      if (taia_less(&timeout, &now)) {
+        if (verbose) info("ssl handshake timeout, exit.");
+        return;
+      }
+      deadline.sec =timeout.sec;
+      deadline.nano =timeout.nano;
+      deadline.atto =timeout.atto;
+    }
+    else {
+      taia_uint(&deadline, 30);
+      taia_add(&deadline, &now, &deadline);
+    }
     iopause(xx, l, &deadline, &now);
     
     if (x[0].revents) encode();
@@ -321,6 +338,9 @@ int ssl_io(unsigned int newsession, const char **prog) {
   if ((s =env_get("SSLIO_BUFOU"))) scan_ulong(s, &bufsizeou);
   if (bufsizein < 64) bufsizein =64;
   if (bufsizeou < 64) bufsizeou =64;
+  if ((s =env_get("SSLIO_HANDSHAKE_TIMEOUT")))
+    scan_ulong(s, &handshake_timeout);
+  if (handshake_timeout < 1) handshake_timeout =1;
 
   if (pipe(encpipe) == -1) fatalm("unable to create pipe for encoding");
   if (pipe(decpipe) == -1) fatalm("unable to create pipe for decoding");
-- 
debian.1.5.3_rc4.1-dirty
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.