Skip to content

Commit

Permalink
2007-08-16 Sebastien Pouliot <sebastien@ximian.com>
Browse files Browse the repository at this point in the history
	* RecordProtocol.cs, SslStreamBase.cs: Ensure nothing (even the same
	thread) can confuse the record decoding code. Fix bug #82145 (LDAP) 
	which uses several thread over a single SslClientStream instance.


svn path=/branches/mono-1-2-5/mcs/; revision=84194
  • Loading branch information
Sebastien Pouliot committed Aug 16, 2007
1 parent 130c046 commit 922d8fa
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
6 changes: 6 additions & 0 deletions mcs/class/Mono.Security/Mono.Security.Protocol.Tls/ChangeLog
@@ -1,3 +1,9 @@
2007-08-16 Sebastien Pouliot <sebastien@ximian.com>

* RecordProtocol.cs, SslStreamBase.cs: Ensure nothing (even the same
thread) can confuse the record decoding code. Fix bug #82145 (LDAP)
which uses several thread over a single SslClientStream instance.

2007-05-23 Gonzalo Paniagua Javier <gonzalo.mono@gmail.com>

* Context.cs: fix the calculation of the unix time.
Expand Down
@@ -1,6 +1,6 @@
// Transport Security Layer (TLS)
// Copyright (c) 2003-2004 Carlos Guzman Alvarez
// Copyright (C) 2006 Novell, Inc (http://www.novell.com)
// Copyright (C) 2006-2007 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
Expand Down Expand Up @@ -35,6 +35,8 @@ internal abstract class RecordProtocol
{
#region Fields

private static ManualResetEvent record_processing = new ManualResetEvent (true);

protected Stream innerStream;
protected Context context;

Expand Down Expand Up @@ -316,6 +318,7 @@ public IAsyncResult BeginReceiveRecord(Stream record, AsyncCallback callback, ob
"The session is finished and it's no longer valid.");
}

record_processing.Reset ();
byte[] recordTypeBuffer = new byte[1];

ReceiveRecordAsyncResult internalResult = new ReceiveRecordAsyncResult(callback, state, recordTypeBuffer, record);
Expand Down Expand Up @@ -426,8 +429,10 @@ public byte[] EndReceiveRecord(IAsyncResult asyncResult)

if (internalResult.CompletedWithError)
throw internalResult.AsyncException;
else
return internalResult.ResultingBuffer;

byte[] result = internalResult.ResultingBuffer;
record_processing.Set ();
return result;
}

public byte[] ReceiveRecord(Stream record)
Expand Down
@@ -1,6 +1,6 @@
// Transport Security Layer (TLS)
// Copyright (c) 2003-2004 Carlos Guzman Alvarez
// Copyright (C) 2006 Novell, Inc (http://www.novell.com)
// Copyright (C) 2006-2007 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
Expand Down Expand Up @@ -39,6 +39,8 @@ public abstract class SslStreamBase: Stream, IDisposable

#region Fields

static ManualResetEvent record_processing = new ManualResetEvent (true);

private const int WaitTimeOut = 5 * 60 * 1000;

internal Stream innerStream;
Expand Down Expand Up @@ -950,15 +952,18 @@ public override int Read(byte[] buffer, int offset, int count)

lock (this.read) {
try {
record_processing.Reset ();
// do we already have some decrypted data ?
if (this.inputBuffer.Position > 0) {
// or maybe we used all the buffer before ?
if (this.inputBuffer.Position == this.inputBuffer.Length) {
this.inputBuffer.SetLength (0);
} else {
int n = this.inputBuffer.Read (buffer, offset, count);
if (n > 0)
if (n > 0) {
record_processing.Set ();
return n;
}
}
}

Expand All @@ -969,14 +974,24 @@ public override int Read(byte[] buffer, int offset, int count)
needMoreData = false;
// if we loop, then it either means we need more data
byte[] recbuf = new byte[16384];
int n = innerStream.Read (recbuf, 0, recbuf.Length);
int n = 0;
if (count == 1) {
int value = innerStream.ReadByte ();
if (value >= 0) {
recbuf[0] = (byte) value;
n = 1;
}
} else {
n = innerStream.Read (recbuf, 0, recbuf.Length);
}
if (n > 0) {
// Add the new received data to the waiting data
if ((recordStream.Length > 0) && (recordStream.Position != recordStream.Length))
recordStream.Seek (0, SeekOrigin.End);
recordStream.Write (recbuf, 0, n);
} else {
// or that the read operation is done (lost connection in the case of a network stream).
record_processing.Set ();
return 0;
}
}
Expand Down Expand Up @@ -1025,7 +1040,9 @@ record = null;
if (dataToReturn) {
// we have record(s) to return -or- no more available to read from network
// reset position for further reading
return this.inputBuffer.Read (buffer, offset, count);
int i = inputBuffer.Read (buffer, offset, count);
record_processing.Set ();
return i;
}
}
}
Expand Down

0 comments on commit 922d8fa

Please sign in to comment.