Skip to content

Commit 416f7be

Browse files
committed
Ensure write buffer is initialized before attempting to use it.
1 parent 5dda8f5 commit 416f7be

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/Renci.SshNet/Sftp/SftpFileStream.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -700,19 +700,21 @@ public override void WriteByte(byte value)
700700
// Setup the object for writing.
701701
SetupWrite();
702702

703+
var writeBuffer = GetOrCreateWriteBuffer();
704+
703705
// Flush the current buffer if it is full.
704706
if (_bufferPosition >= _writeBufferSize)
705707
{
706708
using (var wait = new AutoResetEvent(false))
707709
{
708-
_session.RequestWrite(_handle, (ulong) (_position - _bufferPosition), _writeBuffer, 0, _bufferPosition, wait);
710+
_session.RequestWrite(_handle, (ulong) (_position - _bufferPosition), writeBuffer, 0, _bufferPosition, wait);
709711
}
710712

711713
_bufferPosition = 0;
712714
}
713715

714716
// Write the byte into the buffer and advance the posn.
715-
_writeBuffer[_bufferPosition++] = value;
717+
writeBuffer[_bufferPosition++] = value;
716718
++_position;
717719
}
718720
}

0 commit comments

Comments
 (0)