]> code.citadel.org Git - citadel.git/blobdiff - libcitadel/lib/stringbuf.c
* more testcoverage
[citadel.git] / libcitadel / lib / stringbuf.c
index c07c412d42478c73a4ed0a5938d262050eded111..c41be76fcdd2d4482827ac8da341b89168019001 100644 (file)
@@ -521,7 +521,7 @@ char *SmashStrBuf (StrBuf **SmashMe)
 {
        char *Ret;
 
-       if (*SmashMe == NULL)
+       if ((SmashMe == NULL) || (*SmashMe == NULL))
                return NULL;
 #ifdef SIZE_DEBUG
        if (hFreeDbglog == -1){
@@ -2044,6 +2044,7 @@ int StrBufTCP_read_buffered_line(StrBuf *Line,
 
 }
 
+static const char *ErrRBLF_PreConditionFailed="StrBufTCP_read_buffered_line_fast: Wrong arguments or invalid Filedescriptor";
 static const char *ErrRBLF_SelectFailed="StrBufTCP_read_buffered_line_fast: Select failed without reason";
 static const char *ErrRBLF_NotEnoughSentFromServer="StrBufTCP_read_buffered_line_fast: No complete line was sent from peer";
 /**
@@ -2077,6 +2078,17 @@ int StrBufTCP_read_buffered_line_fast(StrBuf *Line,
        int IsNonBlock;
        struct timeval tv;
        
+       if ((Line == NULL) ||
+           (Pos == NULL) ||
+           (IOBuf == NULL) ||
+           (*fd == -1))
+       {
+               if (Pos != NULL)
+                       *Pos = NULL;
+               *Error = ErrRBLF_PreConditionFailed;
+               return -1;
+       }
+
        pos = *Pos;
        if ((IOBuf->BufUsed > 0) && 
            (pos != NULL) && 
@@ -2111,6 +2123,7 @@ int StrBufTCP_read_buffered_line_fast(StrBuf *Line,
        
        if (IOBuf->BufSize - IOBuf->BufUsed < 10) {
                IncreaseBuf(IOBuf, 1, -1);
+               *Pos = NULL;
        }
 
        fdflags = fcntl(*fd, F_GETFL);
@@ -2182,6 +2195,7 @@ int StrBufTCP_read_buffered_line_fast(StrBuf *Line,
 
 }
 
+static const char *ErrRBLF_BLOBPreConditionFailed="StrBufReadBLOB: Wrong arguments or invalid Filedescriptor";
 /**
  * @ingroup StrBuf_IO
  * @brief Input binary data from socket
@@ -2203,8 +2217,12 @@ int StrBufReadBLOB(StrBuf *Buf, int *fd, int append, long nBytes, const char **E
        int IsNonBlock;
        struct timeval tv;
        fd_set rfds;
+
        if ((Buf == NULL) || (*fd == -1))
+       {
+               *Error = ErrRBLF_BLOBPreConditionFailed;
                return -1;
+       }
        if (!append)
                FlushStrBuf(Buf);
        if (Buf->BufUsed + nBytes >= Buf->BufSize)
@@ -2257,6 +2275,7 @@ int StrBufReadBLOB(StrBuf *Buf, int *fd, int append, long nBytes, const char **E
        return nRead;
 }
 
+const char *ErrRBB_BLOBFPreConditionFailed = "StrBufReadBLOBBuffered: to many selects; aborting.";
 const char *ErrRBB_too_many_selects = "StrBufReadBLOBBuffered: to many selects; aborting.";
 /**
  * @ingroup StrBuf_BufferedIO
@@ -2298,7 +2317,13 @@ int StrBufReadBLOBBuffered(StrBuf *Blob,
        int nSuccessLess;
 
        if ((Blob == NULL) || (*fd == -1) || (IOBuf == NULL) || (Pos == NULL))
+       {
+               if (*Pos != NULL)
+                       *Pos = NULL;
+               *Error = ErrRBB_BLOBFPreConditionFailed;
                return -1;
+       }
+
        if (!append)
                FlushStrBuf(Blob);
        if (Blob->BufUsed + nBytes >= Blob->BufSize) 
@@ -2340,6 +2365,7 @@ int StrBufReadBLOBBuffered(StrBuf *Blob,
        }
 
        FlushStrBuf(IOBuf);
+       *Pos = NULL;
        if (IOBuf->BufSize < nBytes - nRead)
                IncreaseBuf(IOBuf, 0, nBytes - nRead);
        ptr = IOBuf->buf;