Hello!
I have an application that uses a connection check before an actual e-mail
send.
This used OverbyteICS components SVN revision 156 (yes, I've added sources
long time ago), everythind worked until I've updated OverbyteICS to r1273
(nowadays I need OpenSSL 1.0.2 support for HTTPS).
But unfortunately, this update have broken my SMTP sessions.

After some investigation I've found the breakage commit - r1259
(OverbyteIcsPop3Prot.pas Oct 05, 2015
V8.07 Angus changed to receive with LineMode for more reliable line
parsing, which fixes an endless loop if remote server returned nulls,
thanks to Max Terentiev for finding a bad server, 2015-10-19)
and the reason of that. I've made a fix commit to "my" Git-repository
("git-svn" copy of OverbyteICS SVN repository)  - see
https://github.com/ashumkin/OverbyteICS/commit/94f00a6303fe1b64055e8865173a53a5c6de5fb6

So, I propose this fix.

Here's the patch

---8<---
Subject: [PATCH] fixed: memory corruption on a second connection after the
 first connection abortion

If we use SMTP client component as a descendant of TSslSmtpCli that
checks the connection and authorization first (and calls Abort in
.OnCommand handler), then we've got a memory corruption on a second
connection and undefined behaviour while freeing
TCustomLineWSocket.FRcvdPtr pointer.

The reason is that FRcvdCnt (and, actually, FRcvdPtr) is not initialized
on a connection establishment, so it can have an undefined value on a
start of the second connection and thus can lead to a memory corruption.

The issue came out after 1f38418 (OverbyteIcsPop3Prot.pas Oct 05, 2015
V8.07 Angus changed to receive with LineMode for more reliable line
parsing, which fixes an endless loop if remote server returned nulls,
thanks to Max Terentiev for finding a bad server, 2015-10-19)

The fix is to initialize FRcvdPtr and FRcvdCnt on a connection
establishment.
---
 Source/OverbyteIcsWSocket.pas | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git Source/OverbyteIcsWSocket.pas Source/OverbyteIcsWSocket.pas
index f08d8ca..1279fac 100644
--- Source/OverbyteIcsWSocket.pas
+++ Source/OverbyteIcsWSocket.pas
@@ -3988,6 +3988,7 @@ type
       FTimeout             : LongInt;    { Given in milliseconds }
       FTimeStop            : LongInt;    { Milliseconds          }
       FOnLineLimitExceeded : TLineLimitEvent;
+      procedure Do_FD_CONNECT(var Msg : TMessage); override;
       procedure   InternalAbort(ErrCode : Word); override; { V7.49 }
       procedure   WndProc(var MsgRec: TMessage); override;
       procedure   WMTriggerDataAvailable(var msg: TMessage);
@@ -12405,6 +12406,13 @@ begin
 end;


+procedure TCustomLineWSocket.Do_FD_CONNECT(var Msg: TMessage);
+begin
+  FRcvdPtr := nil;
+  FRcvdCnt := 0;
+  inherited;
+end;
+
 {* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*}
 { Edit received data. Handle TAB and BACKSPACE characters.
 }
 { A data packet has been received into FRcvPtr buffer, starting from
 }
-- 
2.4.5.21.g9c7f10a
---8<---
-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Reply via email to