Skip to content

Commit 2144cae

Browse files
committed
POP3 LIST request never terminates if there are zero messages.
Curl_pop3_write() expects the response to end in "\r\n.\r\n" but an empty LIST reply consists of the string ".\r\n" only.
1 parent 93290f6 commit 2144cae

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

‎lib/pop3.c‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,16 @@ static CURLcode pop3_state_list_resp(struct connectdata *conn,
414414
return CURLE_RECV_ERROR;
415415
}
416416

417+
if(pp->linestart_resp &&
418+
strncmp(pp->linestart_resp, "+OK 0", sizeof("+OK 0") - 1) == 0) {
419+
/*
420+
* Curl_pop3_write() expects the response to end in "\r\n.\r\n"
421+
* but an empty LIST reply consists of the string ".\r\n" only,
422+
* so pretend we've already seen the first "\r\n".
423+
*/
424+
pop3c->eob = 2;
425+
}
426+
417427
/* POP3 download */
418428
Curl_setup_transfer(conn, FIRSTSOCKET, -1, FALSE, pop3->bytecountp,
419429
-1, NULL); /* no upload here */
@@ -456,7 +466,11 @@ static CURLcode pop3_list(struct connectdata *conn)
456466
CURLcode result = CURLE_OK;
457467
struct pop3_conn *pop3c = &conn->proto.pop3c;
458468

459-
result = Curl_pp_sendf(&conn->proto.pop3c.pp, "LIST %s", pop3c->mailbox);
469+
if(pop3c->mailbox && *pop3c->mailbox != '\0')
470+
result = Curl_pp_sendf(&conn->proto.pop3c.pp, "LIST %s", pop3c->mailbox);
471+
else
472+
result = Curl_pp_sendf(&conn->proto.pop3c.pp, "LIST");
473+
460474
if(result)
461475
return result;
462476

@@ -1002,11 +1016,12 @@ CURLcode Curl_pop3_write(struct connectdata *conn,
10021016
0d 0a 2e 0d 0a. This marker can of course be spread out
10031017
over up to 5 different data chunks. Deal with it! */
10041018
struct pop3_conn *pop3c = &conn->proto.pop3c;
1005-
size_t checkmax = (nread >= POP3_EOB_LEN?POP3_EOB_LEN:nread);
1006-
size_t checkleft = POP3_EOB_LEN-pop3c->eob;
1007-
size_t check = (checkmax >= checkleft?checkleft:checkmax);
1019+
size_t check = POP3_EOB_LEN - pop3c->eob;
1020+
1021+
if(check > nread)
1022+
check = nread;
10081023

1009-
if(!memcmp(POP3_EOB, &str[nread - check], check)) {
1024+
if(!memcmp(&POP3_EOB[pop3c->eob], &str[nread - check], check)) {
10101025
/* substring match */
10111026
pop3c->eob += check;
10121027
if(pop3c->eob == POP3_EOB_LEN) {

0 commit comments

Comments
 (0)