From a3754a0427dfd1d6494b1ae1a89b414668ec5f54 Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Sun, 21 Oct 2012 19:47:40 +0200 Subject: [PATCH] STRBUF: evaluate fails to increase the buffer --- libcitadel/lib/stringbuf.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/libcitadel/lib/stringbuf.c b/libcitadel/lib/stringbuf.c index ba88a2f43..968fe9793 100644 --- a/libcitadel/lib/stringbuf.c +++ b/libcitadel/lib/stringbuf.c @@ -1023,16 +1023,18 @@ int StrBufSub(StrBuf *dest, const StrBuf *Source, unsigned long Offset, size_t n } if (Offset + nChars < Source->BufUsed) { - if (nChars >= dest->BufSize) - IncreaseBuf(dest, 0, nChars + 1); + if ((nChars >= dest->BufSize) && + (IncreaseBuf(dest, 0, nChars + 1) == -1)) + return 0; memcpy(dest->buf, Source->buf + Offset, nChars); dest->BufUsed = nChars; dest->buf[dest->BufUsed] = '\0'; return nChars; } NCharsRemain = Source->BufUsed - Offset; - if (NCharsRemain >= dest->BufSize) - IncreaseBuf(dest, 0, NCharsRemain + 1); + if ((NCharsRemain >= dest->BufSize) && + (IncreaseBuf(dest, 0, NCharsRemain + 1) == -1)) + return 0; memcpy(dest->buf, Source->buf + Offset, NCharsRemain); dest->BufUsed = NCharsRemain; dest->buf[dest->BufUsed] = '\0'; @@ -4316,10 +4318,11 @@ int StrBufTCP_read_buffered_line(StrBuf *Line, nSuccessLess = 0; buf->BufUsed += rlen; buf->buf[buf->BufUsed] = '\0'; - if (buf->BufUsed + 10 > buf->BufSize) { - IncreaseBuf(buf, 1, -1); - } pch = strchr(buf->buf, '\n'); + if ((pch == NULL) && + (buf->BufUsed + 10 > buf->BufSize) && + (IncreaseBuf(buf, 1, -1) == -1)) + return -1; continue; } -- 2.30.2