[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [cp-patches] Patch: avoid buffer overflow in socket read
From: |
Anthony Green |
Subject: |
Re: [cp-patches] Patch: avoid buffer overflow in socket read |
Date: |
Mon, 26 Dec 2005 18:27:20 -0800 |
On Mon, 2005-12-26 at 18:58 -0700, Tom Tromey wrote:
> >>>>> "Anthony" == Anthony Green <address@hidden> writes:
>
> Anthony> This next patch computes right amount of data to read from a
> Anthony> socket to stuff in a Buffer. When dst.limit < dst.capacity,
> Anthony> we're trying to put too much data into the buffer and we get
> Anthony> a buffer overflow exception.
>
> Anthony> Ok to apply?
>
> Yes, thanks. Could you look at the similar code in
> DatagramChannelImpl.java and, if needed, apply the same fix there?
Good thinking. Here's the final patch that I applied..
2005-12-26 Anthony Green <address@hidden>
* gnu/java/nio/SocketChannelImpl.java (read): Compute the right amount
of data to read (dst.remaining()).
* gnu/java/nio/DatagramChannelImpl.java (receive): Ditto.
--- gnu/java/nio/SocketChannelImpl.java.~1.28.~ 2005-11-11 04:04:03.000000000
-0800
+++ gnu/java/nio/SocketChannelImpl.java 2005-12-26 17:34:14.000000000 -0800
@@ -220,7 +220,7 @@
int offset = 0;
InputStream input = socket.getInputStream();
int available = input.available();
- int len = dst.capacity() - dst.position();
+ int len = dst.remaining();
if ((! isBlocking()) && available == 0)
return 0;
--- gnu/java/nio/DatagramChannelImpl.java.~1.14.~ 2005-07-02
13:32:13.000000000 -0700
+++ gnu/java/nio/DatagramChannelImpl.java 2005-12-26 18:21:47.000000000
-0800
@@ -201,7 +201,7 @@
try
{
DatagramPacket packet;
- int len = dst.capacity() - dst.position();
+ int len = dst.remaining();
if (dst.hasArray())
{