summaryrefslogtreecommitdiff
path: root/lib/pop3.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2017-12-01 00:45:46 +0100
committerDaniel Stenberg <daniel@haxx.se>2017-12-05 17:05:44 +0100
commit615edc1f73090f5f876f1491f9658f6429fdf481 (patch)
treeed060508a315f6ca306a6d1ab492b6687f8f3f40 /lib/pop3.c
parent4401409468f590520dd5d0f0a55607eefa5ff4c1 (diff)
downloadcurl-615edc1f73090f5f876f1491f9658f6429fdf481.tar.gz
sasl_getmesssage: make sure we have a long enough string to pass
For pop3/imap/smtp, added test 891 to somewhat verify the pop3 case. For this, I enhanced the pingpong test server to be able to send back responses with LF-only instead of always using CRLF. Closes #2150
Diffstat (limited to 'lib/pop3.c')
-rw-r--r--lib/pop3.c29
1 files changed, 17 insertions, 12 deletions
diff --git a/lib/pop3.c b/lib/pop3.c
index 5792a4a6f..40dde1052 100644
--- a/lib/pop3.c
+++ b/lib/pop3.c
@@ -243,23 +243,28 @@ static bool pop3_endofresp(struct connectdata *conn, char *line, size_t len,
*/
static void pop3_get_message(char *buffer, char **outptr)
{
- size_t len = 0;
+ size_t len = strlen(buffer);
char *message = NULL;
- /* Find the start of the message */
- for(message = buffer + 2; *message == ' ' || *message == '\t'; message++)
- ;
+ if(len > 2) {
+ /* Find the start of the message */
+ for(message = buffer + 2; *message == ' ' || *message == '\t'; message++)
+ ;
- /* Find the end of the message */
- for(len = strlen(message); len--;)
- if(message[len] != '\r' && message[len] != '\n' && message[len] != ' ' &&
- message[len] != '\t')
- break;
+ /* Find the end of the message */
+ for(len -= 2; len--;)
+ if(message[len] != '\r' && message[len] != '\n' && message[len] != ' ' &&
+ message[len] != '\t')
+ break;
- /* Terminate the message */
- if(++len) {
- message[len] = '\0';
+ /* Terminate the message */
+ if(++len) {
+ message[len] = '\0';
+ }
}
+ else
+ /* junk input => zero length output */
+ message = &buffer[len];
*outptr = message;
}