You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Stephen Ince <si...@opendemand.com> on 2004/09/16 08:26:20 UTC

memory analysis

Hi,
    I am trying to find memory errors in my application and I am having a
hard time. I tried setting APR_POOL_DEBUG=2 but it is catching the errors.

Here are the three types of errors I would like to catch.

/* according the apr docs it should about here, but it doesn't */
/* APR_POOL_DEBUG=2  */
    apr_file_printf(local_stderr, "buffer overflow for apr_pcalloc()\n");
    {
       char *buf = (char *) apr_pcalloc(local_pool, 5);
       memset(buf,0,6);
    }

    apr_file_printf(local_stderr, "buffer overflow for malloc()\n");
    {
       char *buf = (char *) malloc(5);
       memset(buf,0,6);
    }

    apr_file_printf(local_stderr, "stack overflow\n");
    {
       char buf[5];
       memset(buf,0,6);
    }

Steve


Re: memory analysis

Posted by Stephen Ince <si...@opendemand.com>.
Joe,
    Thanx for the insight. The stack overflow is probabely impossible to
catch. I guess that's why it is dangerous to use buffers off the stack.

Steve
----- Original Message ----- 
From: "Joe Orton" <jo...@redhat.com>
To: "APR Development" <de...@apr.apache.org>
Sent: Thursday, September 16, 2004 4:01 AM
Subject: Re: memory analysis


> On Thu, Sep 16, 2004 at 02:26:20AM -0400, Stephen Ince wrote:
> > Hi,
> >     I am trying to find memory errors in my application and I am having
a
> > hard time. I tried setting APR_POOL_DEBUG=2 but it is catching the
errors.
>
> Using --enable-pool-debug in conjunction with a malloc() checker like
> ElectricFence is a good bet; this will catch heap buffer overruns (and
> underruns if efence is configured appropriately).  To catch stack
> overflows you need a smarter compiler, APR can't help with that.
>
> ISTR someone once had a hack which enabled efence-like mprotect() stuff
> inside apr_pools.c... hmmmm, Google says it was Greg but is refusing to
> divulge actually patches.
>
> joe
>


Re: memory analysis

Posted by Joe Orton <jo...@redhat.com>.
On Thu, Sep 16, 2004 at 02:26:20AM -0400, Stephen Ince wrote:
> Hi,
>     I am trying to find memory errors in my application and I am having a
> hard time. I tried setting APR_POOL_DEBUG=2 but it is catching the errors.

Using --enable-pool-debug in conjunction with a malloc() checker like
ElectricFence is a good bet; this will catch heap buffer overruns (and
underruns if efence is configured appropriately).  To catch stack
overflows you need a smarter compiler, APR can't help with that.

ISTR someone once had a hack which enabled efence-like mprotect() stuff
inside apr_pools.c... hmmmm, Google says it was Greg but is refusing to
divulge actually patches.

joe