-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
net_imap: Fix duplicated/malformed RFC822.HEADER FETCH response.
The handling for RFC822.HEADER previously resulted in output being flushed immediately, before the response for that message even began. Move it to afterwards, and also eliminate duplicate handling of this FETCH item. Additionally, send_message did not correctly handle the HEADERS_ONLY case, as it would have the length of the headers but the offset of the body start, rather than the headers start. This would result in a request to bbs_sendfile to send past the end of the file if the message's body was short enough, resulting in an infinite loop since sendfile would return 0. To address this, bbs_sendfile now handles a return of 0 by waiting for the file descriptor to become writable, and also checks if the offset exceeds the file size. send_message is also fixed to correctly handle HEADERS_ONLY. A test has been added to verify both of the above. LBBS-85 #close
- Loading branch information
1 parent
b04c88c
commit 1789ec3
Showing
6 changed files
with
141 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,7 +89,7 @@ static int write_file_to_socket(int client, const char *filename) | |
return 0; | ||
} | ||
|
||
static int send_count = 0; | ||
static int send_count; | ||
|
||
static int send_message(int client1, const char *filename) | ||
{ | ||
|
@@ -125,11 +125,48 @@ static int send_message(int client1, const char *filename) | |
return -1; | ||
} | ||
|
||
static int send_short_message(int client1) | ||
{ | ||
if (!send_count++) { | ||
CLIENT_EXPECT_EVENTUALLY(client1, "220 "); | ||
SWRITE(client1, "EHLO " TEST_EXTERNAL_DOMAIN ENDL); | ||
CLIENT_EXPECT_EVENTUALLY(client1, "250 "); /* "250 " since there may be multiple "250-" responses preceding it */ | ||
} else { | ||
SWRITE(client1, "RSET" ENDL); | ||
CLIENT_EXPECT(client1, "250"); | ||
} | ||
|
||
SWRITE(client1, "MAIL FROM:<" TEST_EMAIL_EXTERNAL ">\r\n"); | ||
CLIENT_EXPECT(client1, "250"); | ||
SWRITE(client1, "RCPT TO:<" TEST_EMAIL ">\r\n"); | ||
CLIENT_EXPECT(client1, "250"); | ||
SWRITE(client1, "DATA\r\n"); | ||
CLIENT_EXPECT(client1, "354"); | ||
|
||
/* Lengths include CR LF */ | ||
SWRITE(client1, "Content-Type: text/plain" ENDL); /* 26 bytes */ | ||
SWRITE(client1, "To: [email protected]" ENDL); /* 22 bytes */ | ||
SWRITE(client1, "From: [email protected]" ENDL); /* 24 bytes */ | ||
SWRITE(client1, "Subject: Test message" ENDL); /* 23 bytes */ | ||
SWRITE(client1, "Sun, 10 Nov 2024 19:58:17 -0500" ENDL); /* 33 bytes */ | ||
SWRITE(client1, ENDL); /* 2 bytes */ | ||
SWRITE(client1, "Test" ENDL); /* 6 bytes */ | ||
|
||
/* Messages end in CR LF, so only send . CR LF here */ | ||
SWRITE(client1, "." ENDL); /* EOM */ | ||
CLIENT_EXPECT(client1, "250"); | ||
return 0; | ||
|
||
cleanup: | ||
return -1; | ||
} | ||
|
||
static int make_messages(void) | ||
{ | ||
int clientfd; | ||
int res = 0; | ||
|
||
send_count = 0; | ||
clientfd = test_make_socket(25); | ||
if (clientfd < 0) { | ||
return -1; | ||
|
@@ -138,6 +175,7 @@ static int make_messages(void) | |
res |= send_message(clientfd, "multipart.eml"); | ||
res |= send_message(clientfd, "multipart2.eml"); | ||
res |= send_message(clientfd, "alternative.eml"); | ||
res |= send_short_message(clientfd); | ||
|
||
close(clientfd); /* Close SMTP connection */ | ||
return res; | ||
|
@@ -344,6 +382,18 @@ static int run(void) | |
SWRITE(client1, "g13 FETCH 2 (BODY.PEEK[3.HEADER.FIELDS (Content-Type)]<1.12>)" ENDL); | ||
CLIENT_EXPECT_EVENTUALLY(client1, "ontent-Type:"); | ||
|
||
/* Request RFC822.HEADER ([LBBS-85] bug fix) */ | ||
CLIENT_DRAIN(client1); | ||
SWRITE(client1, "h1 FETCH 4 (UID RFC822.HEADER)" ENDL); | ||
CLIENT_EXPECT(client1, "* 4 FETCH (UID 4 RFC822.HEADER {130}"); | ||
|
||
/* Ideally, we would be able to confirm that 130 bytes are actually received here... | ||
* Since we can't, repeat, and ensure it's the headers, not the body. */ | ||
|
||
CLIENT_DRAIN(client1); | ||
SWRITE(client1, "h2 FETCH 4 (UID RFC822.HEADER)" ENDL); | ||
CLIENT_EXPECT_EVENTUALLY(client1, "Content-Type"); | ||
|
||
SWRITE(client1, "z999 LOGOUT" ENDL); | ||
CLIENT_EXPECT_EVENTUALLY(client1, "* BYE"); | ||
res = 0; | ||
|