Re: [Lit.] Buffer overruns
From: David Wagner (daw_at_taverner.cs.berkeley.edu)
Date: 02/03/05
- Next message: John A. Malley: "Re: [Lit.] Buffer overruns - LONG"
- Previous message: Michael Jørgensen: "Re: Encryption Detection"
- In reply to: newstome_at_comcast.net: "Re: [Lit.] Buffer overruns"
- Next in thread: Trevor L. Jackson, III: "Re: [Lit.] Buffer overruns"
- Reply: Trevor L. Jackson, III: "Re: [Lit.] Buffer overruns"
- Reply: Douglas A. Gwyn: "Re: [Lit.] Buffer overruns"
- Reply: newstome_at_comcast.net: "Re: [Lit.] Buffer overruns"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Thu, 3 Feb 2005 07:55:50 +0000 (UTC)
>Here's a reduction from the halting problem to checking for buffer
>overflows: Say you've got a function f(x) and you want to see if it
>halts. Now add the following function:
>
> void g(whatever x) {
> int b[2];
> f(x);
> b[2] = 0;
> }
>
>You get a buffer overflow on b[] iff f(x) returns (halts).
>
>Maybe that's a silly example, but it shows the undecidability of
>determining whether a program has a buffer overflow.
Solution: You build a conservative tool. In case of doubt (i.e., if
you cannot prove the program/construct safe), you output a warning.
You might get false positives -- indeed, for buffer overrun analysis
of large C programs, you will surely get false positives, and lots of
them -- but you don't have the undecidability problem any further.
For instance, a conservative tool would output a warning about a possible
buffer overrun in the code you gave, unless it could prove that f(x)
never returns.
It turns out that there is a general theorem, called Rice's theorem,
which roughly speaking says that checking any non-trivial property
is undecidable. (The definition of non-trivial is pretty broad, and
primarily serves to exclude properties that are either true for all
programs or false for all programs.) This is sometimes jokingly known
as the "full-employment theorem for programming language folks". The way
you get around undecidability is almost always the same; you allow to err
in one direction or the other. For instance, almost any kind of program
optimization is undecidable; nonetheless, a good optimizer will only apply
the optimization if it can prove that the optimization won't alter program
behavior, and otherwise won't apply the optimization in case of doubt.
- Next message: John A. Malley: "Re: [Lit.] Buffer overruns - LONG"
- Previous message: Michael Jørgensen: "Re: Encryption Detection"
- In reply to: newstome_at_comcast.net: "Re: [Lit.] Buffer overruns"
- Next in thread: Trevor L. Jackson, III: "Re: [Lit.] Buffer overruns"
- Reply: Trevor L. Jackson, III: "Re: [Lit.] Buffer overruns"
- Reply: Douglas A. Gwyn: "Re: [Lit.] Buffer overruns"
- Reply: newstome_at_comcast.net: "Re: [Lit.] Buffer overruns"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|