libfreerdp-core: workaround for fragmentation in HTTP header
authorMarc-André Moreau <marcandre.moreau@gmail.com>
Tue, 13 Nov 2012 23:57:46 +0000 (18:57 -0500)
committerMarc-André Moreau <marcandre.moreau@gmail.com>
Tue, 13 Nov 2012 23:57:46 +0000 (18:57 -0500)
libfreerdp/core/http.c

index 1785e4c..1e7a1a6 100644 (file)
@@ -22,6 +22,7 @@
 #endif
 
 #include <winpr/crt.h>
+#include <winpr/print.h>
 
 #include <freerdp/utils/memory.h>
 
@@ -405,28 +406,39 @@ HttpResponse* http_response_recv(rdpTls* tls)
 
        while (TRUE)
        {
-               status = tls_read(tls, p, length - nbytes);
-
-               if (status > 0)
-               {
-                       nbytes += status;
-                       p = (BYTE*) &buffer[nbytes];
-               }
-               else if (status == 0)
-               {
-                       continue;
-               }
-               else
-               {
-                       http_response_free(http_response);
-                       return NULL;
-                       break;
-               }
+        while (nbytes < 5)
+        {
+            status = tls_read(tls, p, length - nbytes);
+            
+            if (status > 0)
+            {
+                nbytes += status;
+                p = (BYTE*) &buffer[nbytes];
+            }
+            else if (status == 0)
+            {
+                continue;
+            }
+            else
+            {
+                http_response_free(http_response);
+                return NULL;
+            }
+        }
 
                header_end = strstr((char*) buffer, "\r\n\r\n");
         
         if (header_end)
+        {
             header_end += 2;
+        }
+        else
+        {
+            printf("http_response_recv: invalid response:\n");
+            winpr_HexDump(buffer, status);
+                       http_response_free(http_response);
+                       return NULL;
+        }
 
                if (header_end != NULL)
                {