From c6bdb87ca2b619506be079cb47dbd2c8cff0f707 Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Fri, 1 Jun 2012 00:35:39 +0200 Subject: [PATCH] add some more NULL-pointer-checks; free allocated mem in case of OOM. --- libcitadel/lib/stringbuf.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/libcitadel/lib/stringbuf.c b/libcitadel/lib/stringbuf.c index 33701c634..7eac317a9 100644 --- a/libcitadel/lib/stringbuf.c +++ b/libcitadel/lib/stringbuf.c @@ -511,6 +511,7 @@ StrBuf* NewStrBufPlain(const char* ptr, int nChars) if (Siz == 0) { + free(NewBuf); return NULL; } @@ -815,7 +816,8 @@ long StrBufPook(StrBuf *Buf, const char* ptr, long nThChar, long nChars, char Po */ void StrBufAppendBuf(StrBuf *Buf, const StrBuf *AppendBuf, unsigned long Offset) { - if ((AppendBuf == NULL) || (Buf == NULL) || (AppendBuf->buf == NULL)) + if ((AppendBuf == NULL) || (AppendBuf->buf == NULL) || + (Buf == NULL) || (Buf->buf == NULL)) return; if (Buf->BufSize - Offset < AppendBuf->BufUsed + Buf->BufUsed + 1) @@ -1062,7 +1064,9 @@ void StrBufCutLeft(StrBuf *Buf, int nChars) */ void StrBufCutRight(StrBuf *Buf, int nChars) { - if ((Buf == NULL) || (Buf->BufUsed == 0)) return; + if ((Buf == NULL) || (Buf->BufUsed == 0) || (Buf->buf == NULL)) + return; + if (nChars >= Buf->BufUsed) { FlushStrBuf(Buf); return; @@ -2500,14 +2504,14 @@ void StrBufEUid_unescapize(StrBuf *target, const StrBuf *source) int a, b, len; char hex[3]; - if (target != NULL) - FlushStrBuf(target); - - if (source == NULL ||target == NULL) + if ((source == NULL) || (target == NULL) || (target->buf == NULL)) { return; } + if (target != NULL) + FlushStrBuf(target); + len = source->BufUsed; for (a = 0; a < len; ++a) { if (target->BufUsed >= target->BufSize) @@ -2544,7 +2548,7 @@ void StrBufEUid_escapize(StrBuf *target, const StrBuf *source) if (target != NULL) FlushStrBuf(target); - if (source == NULL ||target == NULL) + if ((source == NULL) || (target == NULL) || (target->buf == NULL)) { return; } @@ -3760,7 +3764,7 @@ eReadState StrBufChunkSipLine(StrBuf *LineBuf, IOBuffer *FB) const char *aptr, *ptr, *eptr; char *optr, *xptr; - if ((FB == NULL) || (LineBuf == NULL)) + if ((FB == NULL) || (LineBuf == NULL) || (LineBuf->buf == NULL)) return eReadFail; @@ -4068,7 +4072,7 @@ int StrBufTCP_read_line(StrBuf *buf, int *fd, int append, const char **Error) { int len, rlen, slen; - if (buf == NULL) { + if ((buf == NULL) || (buf->buf == NULL)) { *Error = strerror(EINVAL); return -1; } @@ -4416,7 +4420,7 @@ int StrBufReadBLOB(StrBuf *Buf, int *fd, int append, long nBytes, const char **E struct timeval tv; fd_set rfds; - if ((Buf == NULL) || (*fd == -1)) + if ((Buf == NULL) || (Buf->buf == NULL) || (*fd == -1)) { *Error = ErrRBLF_BLOBPreConditionFailed; return -1; -- 2.30.2