#346 malloc(0) can return NULL on success

build problems
closed-works-for-me
regexp (7)
5
2008-02-08
2006-06-13
Nirendra
No

CLISP: 2.38
OS : AIX 4.3.2.0 and 5.1.0.0
CC : GCC 3.4.6 and 3.4.2 respectively.

I had been getting test failures with the 'regexp'
module. After tracing through the function calls of one
of the offending REs, I discovered that malloc was
being passed 0, and returned NULL.

Some code in regcomp.c, regex.c, and regex_internal.c
assumes REG_ESPACE when malloc returns NULL. On AIX,
malloc(0) returns NULL and sets errno. I had to change
these files in a few places to check that errno ==
ENOMEM in addition to checking whether the assigned
pointer was NULL.

Also check the gnulib repository log for regex rev. 1.11:
http://cvs.savannah.gnu.org/viewcvs/gnulib/gnulib/modules/regex?rev=1.11&view=markup

Discussion

  • Nirendra

    Nirendra - 2006-06-14

    Logged In: YES
    user_id=1539062

    Sorry, there's an error in my problem description.

    On AIX, malloc returns NULL and sets errno on failure.

     
  • Sam Steingold

    Sam Steingold - 2006-07-20
    • assigned_to: haible --> sds
     
  • Sam Steingold

    Sam Steingold - 2006-07-20

    Logged In: YES
    user_id=5735

    you appear to suggest that merging in the latest gnulib regexp
    will fix this bug.
    is this right?

    ps. would you mind building a 2.39 binary distribution
    for the CLISP SF files section?
    thanks.

     
  • Nirendra

    Nirendra - 2006-07-21

    Logged In: YES
    user_id=1539062

    Hullo,

    Sorry if my description was vague. I wasn't suggesting that
    merging gnulib regex would solve the problem, merely that it
    was a recognised problem in gnulib regex.

    I don't know much about autoconf, etc. but I tried to see
    how one could come up with a general solution. While
    compiling libpng, I noticed that it checks for a malloc(0)
    that returns NULL, and so I looked to that package for
    inspiration.

    It seems like they declare 'AC_FUNC_MALLOC' in
    'configure.ac', and this checks for a GNU-compatible malloc
    when configure is generated. The only problem is that this
    ends up redefining 'malloc' to 'rpl_malloc', and there is no
    'rpl_malloc' included.

    The solution seems to be:
    1) Include 'malloc.c' from gnulib in the regexp module
    collection. This contains a definition for 'rpl_malloc'.
    2) Change 'configure' to check for a GNU-compatible
    'malloc'. Perhaps 'config.h' needs to change too.
    3) Change the Makefile to compile and link in 'malloc.o' if
    required.

    I reckon this would solve the problem, but as I am a
    complete novice at 'autoconf', it is still mostly guesswork
    on my part.

    With regards to the binary, I currently have a 2.38 binary
    compiled for AIX 4.3.2 (IBM F50) and 5.1 (IBM P615), but
    with only the base modules compiled in, as everything else
    gave me problems. I will try to compile a 2.39 binary as
    soon as I can. Is it possible to upload the file somewhere
    or can I e-mail it to some address?

     
  • Sam Steingold

    Sam Steingold - 2006-07-21

    Logged In: YES
    user_id=5735

    we will merge in gnulib anyway and see if it helps.
    (don't hold your breath though)

     
  • Sam Steingold

    Sam Steingold - 2006-07-21
    • assigned_to: sds --> haible
     
  • Sam Steingold

    Sam Steingold - 2008-01-24

    Logged In: YES
    user_id=5735
    Originator: NO

    This bug report is now marked as "pending"/"works for me".
    This means that we think that we cannot reproduce the problem
    and cannot do anything about it.
    Unless you - the reporter - act within 2 weeks
    (e.g., by submitting a self-contained test case),
    the bug will be permanently closed.
    Sorry about the inconvenience -
    we hope your silence means that
    you are no longer observing the problem either.

     
  • Sam Steingold

    Sam Steingold - 2008-01-24
    • assigned_to: haible --> sds
    • status: open --> pending-works-for-me
     
  • Sam Steingold

    Sam Steingold - 2008-01-24

    Logged In: YES
    user_id=5735
    Originator: NO

    we now use gnulib regex.
    if you still observe this bug, please report it to the gnulib people.

     
  • SourceForge Robot

    Logged In: YES
    user_id=1312539
    Originator: NO

    This Tracker item was closed automatically by the system. It was
    previously set to a Pending status, and the original submitter
    did not respond within 14 days (the time period specified by
    the administrator of this Tracker).

     
  • SourceForge Robot

    • status: pending-works-for-me --> closed-works-for-me
     

Log in to post a comment.