]> code.citadel.org Git - citadel.git/blobdiff - webcit/tcp_sockets.c
* fix some rare oom situation.
[citadel.git] / webcit / tcp_sockets.c
index b7ab06ba7cdf9a6ef0edddac5ea40d2a93e1c9a2..1adcafc32dcbc1319d5e13e2c072abb962158417 100644 (file)
@@ -226,7 +226,7 @@ int StrBuf_ServGetBLOBBuffered(StrBuf *buf, long BlobSize)
        }
 #ifdef SERV_TRACE
         else
-                syslog(9, "%3d<<<BLOB: %ld bytes\n", WC->serv_sock, StrLength(buf));
+                syslog(9, "%3d<<<BLOB: %d bytes\n", WC->serv_sock, StrLength(buf));
 #endif
 
        return rc;
@@ -251,7 +251,7 @@ int StrBuf_ServGetBLOB(StrBuf *buf, long BlobSize)
        }
 #ifdef SERV_TRACE
         else
-                syslog(9, "%3d<<<BLOB: %ld bytes\n", WC->serv_sock, StrLength(buf));
+                syslog(9, "%3d<<<BLOB: %d bytes\n", WC->serv_sock, StrLength(buf));
 #endif
 
        return rc;
@@ -275,7 +275,7 @@ void FlushReadBuf (void)
                pche = pch + len;
                if (WCC->ReadPos != pche)
                {
-                       syslog(1, "ERROR: somebody didn't eat his soup! Remaing Chars: %d [%s]\n", 
+                       syslog(1, "ERROR: somebody didn't eat his soup! Remaing Chars: %ld [%s]\n", 
                                pche - WCC->ReadPos, pche);
                        syslog(1, 
                                "--------------------------------------------------------------------------------\n"
@@ -404,7 +404,10 @@ int serv_read_binary(StrBuf *Ret, size_t total_len, StrBuf *Buf)
                }
 
                serv_printf("READ %d|%d", bytes_read, total_len-bytes_read);
-               if ( (StrBuf_ServGetln(Buf) > 0) && (GetServerStatus(Buf, NULL) == 6) ) {
+               if ( (rc = StrBuf_ServGetln(Buf) > 0) && (GetServerStatus(Buf, NULL) == 6) ) 
+               {
+                       if (rc < 0)
+                               return rc;
                        StrBufCutLeft(Buf, 4);
                        this_block = StrTol(Buf);
                        rc = StrBuf_ServGetBLOBBuffered(Ret, this_block);
@@ -648,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) 
                {