]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Check for rejected connections in system_recv_timeout().
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Fri, 18 Mar 2011 19:55:02 +0000 (20:55 +0100)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Fri, 18 Mar 2011 19:55:02 +0000 (20:55 +0100)
lib/gnutls_buffers.c
lib/system.c

index cbb054678acede41c072f301aeff3785b3c49f1d..31e56b5264cef70c0adc31ba5a39bf05c5afbdf0 100644 (file)
@@ -603,7 +603,7 @@ int
 _gnutls_io_check_recv (gnutls_session_t session, void* data, size_t data_size, unsigned int ms)
 {
   gnutls_transport_ptr_t fd = session->internals.transport_send_ptr;
-  int ret;
+  int ret = 0;
   
   if (session->internals.pull_timeout_func == system_recv_timeout && 
     session->internals.pull_func != system_read)
index 0aa569fae8bcc324b99659ccfd0a5e241991b130..dd2d74fc20e889922063861eba0bfb0f305e5e65 100644 (file)
@@ -108,12 +108,14 @@ system_read_peek (gnutls_transport_ptr_t ptr, void *data, size_t data_size)
 /* Wait for data to be received within a timeout period in milliseconds.
  * If data_size > 0 it will return the specified amount of data in
  * peek mode.
+ *
+ * Returns -1 on error, 0 on timeout.
  */
 int system_recv_timeout(gnutls_transport_ptr_t ptr, void* data, size_t data_size, unsigned int ms)
 {
 fd_set rfds;
 struct timeval tv;
-int ret;
+int ret, ret2;
 
   FD_ZERO(&rfds);
   FD_SET(GNUTLS_POINTER_TO_INT(ptr), &rfds);
@@ -122,10 +124,19 @@ int ret;
   tv.tv_usec = ms * 1000;
   
   ret = select(GNUTLS_POINTER_TO_INT(ptr)+1, &rfds, NULL, NULL, &tv);
-
-  if (ret <= 0 || data_size == 0)
+  if (ret <= 0)
     return ret;
 
+  
+  if (data_size == 0)
+    {
+      ret2 = recv(GNUTLS_POINTER_TO_INT(ptr), NULL, 0, MSG_PEEK);
+      if (ret2 == -1)
+        return ret2;
+      
+      return ret;
+    }
+
   /* only report ok if the next message is from the peer we expect
    * from 
    */