* some more input condition sanitizing
authorWilfried Göesgens <willi@citadel.org>
Sun, 3 Jan 2010 23:44:40 +0000 (23:44 +0000)
committerWilfried Göesgens <willi@citadel.org>
Sun, 3 Jan 2010 23:44:40 +0000 (23:44 +0000)
libcitadel/lib/stringbuf.c

index 400fddbfc0f5b6b7a1512e6d4932c63e6e4de711..6c068c580d84a936019f45ea82f0b1c16d5cc639 100644 (file)
@@ -293,7 +293,7 @@ static int IncreaseBuf(StrBuf *Buf, int KeepOriginal, int DestSize)
  */
 void ReAdjustEmptyBuf(StrBuf *Buf, long ThreshHold, long NewSize)
 {
-       if (Buf->BufUsed > ThreshHold) {
+       if ((Buf != NULL) && (Buf->BufUsed > ThreshHold)) {
                free(Buf->buf);
                Buf->buf = (char*) malloc(NewSize);
                Buf->BufUsed = 0;
@@ -310,6 +310,8 @@ void ReAdjustEmptyBuf(StrBuf *Buf, long ThreshHold, long NewSize)
  */
 long StrBufShrinkToFit(StrBuf *Buf, int Force)
 {
+       if (Buf == NULL)
+               return -1;
        if (Force || 
            (Buf->BufUsed + (Buf->BufUsed / 3) > Buf->BufSize))
        {
@@ -2174,6 +2176,9 @@ long StrBufUnescape(StrBuf *Buf, int StripBlanks)
        char hex[3];
        long len;
 
+       if (Buf == NULL)
+               return -1;
+
        while ((Buf->BufUsed > 0) && (isspace(Buf->buf[Buf->BufUsed - 1]))){
                Buf->buf[Buf->BufUsed - 1] = '\0';
                Buf->BufUsed --;