Re: [Lit.] Buffer overruns
From: David Wagner (daw_at_taverner.cs.berkeley.edu)
Date: 12/24/04
- Next message: David Wagner: "Re: [Lit.] Buffer overruns"
- Previous message: Douglas A. Gwyn: "Re: [Lit.] Buffer overruns"
- In reply to: Douglas A. Gwyn: "Re: [Lit.] Buffer overruns"
- Next in thread: David Wagner: "Re: [Lit.] Buffer overruns"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Fri, 24 Dec 2004 06:37:20 +0000 (UTC)
Douglas A. Gwyn wrote:
>> public Object get(int i) {
>> // NOTE: The array bounds check can be safely omitted.
>> // A malicious caller might pass in an out-of-bounds index,
>> // but then they are just going to get an ArrayBoundsException
>> // -- no big deal.
>> return contents[i];
>> }
>
>That is *not* "doing the right thing with buffers"; it is
>irresponsible programming. Whatever function was supposed
>to be performed is aborted as a consequence of lack of care
>in the surrounding app. It could very well be a "big deal".
I don't know why you think it is irresponsible. Suppose the documented
interface to get() says that it is the caller's responsibility to supply
an in-bounds index, and the interface specifies that the caller will
receive an exception if the index is out of bounds. Then the above code
implements exactly the promised interface. If you have a complaint, the
complaint is not with the code, but with the interface. However, I don't
see why such an interface would be necessarily irresponsible; whether that
is an appropriate interface will depend on context, and in some contexts,
it might be a reasonable and responsible choice.
You raised a concern that the caller might be "aborted". I think what
you mean is that calling get() might throw an exception if the argument
is out of bounds. I don't know why you think that is necessarily
irresponsible. If the documented interface says that get() might raise
an exception, then it is up to the caller to either catch the exception
(if the caller cares about it) and handle or re-throw the problem, or to
decide not to catch the exception (if the caller decides that the right
thing is that the exception should be propagated on).
I assert that there are contexts where the above code might well be
reasonable. I do not know why you call it irresponsible programming.
- Next message: David Wagner: "Re: [Lit.] Buffer overruns"
- Previous message: Douglas A. Gwyn: "Re: [Lit.] Buffer overruns"
- In reply to: Douglas A. Gwyn: "Re: [Lit.] Buffer overruns"
- Next in thread: David Wagner: "Re: [Lit.] Buffer overruns"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|