You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Yann Ylavic <yl...@gmail.com> on 2024/02/01 12:56:25 UTC

Re: APR_POOL_DEBUG usage question

On Wed, Jan 31, 2024 at 7:44 PM Simon Walter <si...@gikaku.com> wrote:
>
> Should I use '--enable-pool-debug=yes' or '--enable-pool-debug=verbose'?

I'd suggest using simple --enable-pool-debug[=yes] and ASan (Address
Sanitizer, i.e. "-fsanitize=address -fno-sanitize-recover=address" in
$CFLAGS).


Regards,
Yann.

Re: APR_POOL_DEBUG usage question

Posted by Yann Ylavic <yl...@gmail.com>.
On Thu, Feb 1, 2024 at 2:38 PM Simon Walter <si...@gikaku.com> wrote:
>
> I had partial success with '--enable-pool-debug=yes' and
> '--enable-pool-debug=verbose'. Then I ran into something else regarding
> apr-util. I see there are pre-processor conditions based on APR_POOL_DEBUG.

Yes, you need to both apr and apr-util consistently with or without
--enable-pool-debug.

Regards;
Yann.

Re: APR_POOL_DEBUG in apr-util (was: APR_POOL_DEBUG usage question)

Posted by Joe Orton <jo...@redhat.com>.
On Thu, Feb 01, 2024 at 04:50:31PM +0100, Yann Ylavic wrote:
> dev@ team,
> 
> I'm wondering if we could/should remove APR_POOL_DEBUG specifics in
> apr-util 1.6.x and 1.7.x, otherwise it's not possible run
> non-pool-debug apr-util with pool-debug apr.
> 
> Fortunately the only dependency on APR_POOL_DEBUG for apr-util seems
> to be the apr_bucket code below.

+1 makes sense to me.

Regards, Joe


APR_POOL_DEBUG in apr-util (was: APR_POOL_DEBUG usage question)

Posted by Yann Ylavic <yl...@gmail.com>.
dev@ team,

I'm wondering if we could/should remove APR_POOL_DEBUG specifics in
apr-util 1.6.x and 1.7.x, otherwise it's not possible run
non-pool-debug apr-util with pool-debug apr.

Fortunately the only dependency on APR_POOL_DEBUG for apr-util seems
to be the apr_bucket code below.

On Thu, Feb 1, 2024 at 2:38 PM Simon Walter wrote:
>
> I had partial success with '--enable-pool-debug=yes' and
> '--enable-pool-debug=verbose'. Then I ran into something else regarding
> apr-util. I see there are pre-processor conditions based on APR_POOL_DEBUG.
>
> In apr_bucket_alloc_create():
>
> #if APR_POOL_DEBUG
>     /* may be NULL for debug mode. */
>     if (allocator == NULL) {
>         if (apr_allocator_create(&allocator) != APR_SUCCESS) {
>             apr_abortfunc_t fn = apr_pool_abort_get(p);
>             if (fn)
>                 (fn)(APR_ENOMEM);
>             abort();
>         }
>     }
> #endif
>
> Indeed it segfaults in allocator_alloc() because the allocator is null.

Here, if apr was compiled with APR_POOL_DEBUG but apr-util without, it
crashes because the allocator is/remains NULL.

I think this code works without the compile time "#if APR_POOL_DEBUG"
checks because there is no way for apr_pool_allocator_get() to return
NULL besides APR_POOL_DEBUG mode, and of course both apr_pool_t and
apr_bucket_alloc_t are opaque which prevents anyone from playing with
their ->allocator.
It shouldn't either cause too much overhead if running this code for
!APR_POOL_DEBUG.

So don't you think we could/should just remove the "#if
APR_POOL_DEBUG" in buckets/apr_buckets_alloc.c?


Regards;
Yann.

Re: APR_POOL_DEBUG usage question

Posted by Simon Walter <si...@gikaku.com>.

On 2024-02-01 14:21, Yann Ylavic wrote:
> On Thu, Feb 1, 2024 at 1:56 PM Yann Ylavic <yl...@gmail.com> wrote:
>>
>> On Wed, Jan 31, 2024 at 7:44 PM Simon Walter <si...@gikaku.com> wrote:
>>>
>>> Should I use '--enable-pool-debug=yes' or '--enable-pool-debug=verbose'?
>>
>> I'd suggest using simple --enable-pool-debug[=yes] and ASan (Address
>> Sanitizer, i.e. "-fsanitize=address -fno-sanitize-recover=address" in
>> $CFLAGS).
> 
> I mean, ASan for compiling the APR eventually, but it should be used
> to compile your program too for a full leaks/use-after-free coverage.

Thanks Yann!

I had partial success with '--enable-pool-debug=yes' and
'--enable-pool-debug=verbose'. Then I ran into something else regarding
apr-util. I see there are pre-processor conditions based on APR_POOL_DEBUG.

In apr_bucket_alloc_create():

#if APR_POOL_DEBUG
    /* may be NULL for debug mode. */
    if (allocator == NULL) {
        if (apr_allocator_create(&allocator) != APR_SUCCESS) {
            apr_abortfunc_t fn = apr_pool_abort_get(p);
            if (fn)
                (fn)(APR_ENOMEM);
            abort();
        }
    }
#endif

Indeed it segfaults in allocator_alloc() because the allocator is null.

I'll try with just the $CFLAGS you suggested, Yann, and see if I can
find the double free without APR_POOL_DEBUG code. Because building
apr-utils will not be as easy apr. I've been using debian libs and -dev
pkgs, which up until now have been all I needed. Time to dive deeper I
suppose.

Thanks again,

Simon

Re: APR_POOL_DEBUG usage question

Posted by Yann Ylavic <yl...@gmail.com>.
On Thu, Feb 1, 2024 at 1:56 PM Yann Ylavic <yl...@gmail.com> wrote:
>
> On Wed, Jan 31, 2024 at 7:44 PM Simon Walter <si...@gikaku.com> wrote:
> >
> > Should I use '--enable-pool-debug=yes' or '--enable-pool-debug=verbose'?
>
> I'd suggest using simple --enable-pool-debug[=yes] and ASan (Address
> Sanitizer, i.e. "-fsanitize=address -fno-sanitize-recover=address" in
> $CFLAGS).

I mean, ASan for compiling the APR eventually, but it should be used
to compile your program too for a full leaks/use-after-free coverage.

>
> Regards,
> Yann.