* fix some rare oom situation.
authorWilfried Goesgens <dothebart@citadel.org>
Fri, 22 Apr 2011 22:50:09 +0000 (22:50 +0000)
committerWilfried Goesgens <dothebart@citadel.org>
Sun, 4 Sep 2011 20:13:13 +0000 (20:13 +0000)
webcit/tcp_sockets.c

index 27fc0a92adb3b861d90f90503013b968e260285d..1adcafc32dcbc1319d5e13e2c072abb962158417 100644 (file)
@@ -651,19 +651,23 @@ int client_read_to(ParsedHttpHdrs *Hdr, StrBuf *Target, int bytes, int timeout)
 
 #ifdef HAVE_OPENSSL
        if (is_https) {
-               long bufremain;
+               long bufremain = 0;
                long baselen;
 
                baselen = StrLength(Target);
 
                if (Hdr->Pos == NULL)
                        Hdr->Pos = ChrPtr(Hdr->ReadBuf);
-               bufremain = StrLength(Hdr->ReadBuf) - (Hdr->Pos - ChrPtr(Hdr->ReadBuf));
 
-               if (bytes < bufremain)
-                       bufremain = bytes;
-               StrBufAppendBufPlain(Target, Hdr->Pos, bufremain, 0);
-               StrBufCutLeft(Hdr->ReadBuf, bufremain);
+               if (StrLength(Hdr->ReadBuf) > 0)
+               {
+                       bufremain = StrLength(Hdr->ReadBuf) - (Hdr->Pos - ChrPtr(Hdr->ReadBuf));
+                       
+                       if (bytes < bufremain)
+                               bufremain = bytes;
+                       StrBufAppendBufPlain(Target, Hdr->Pos, bufremain, 0);
+                       StrBufCutLeft(Hdr->ReadBuf, bufremain);
+               }
 
                if (bytes > bufremain) 
                {