[go: up one dir, main page]

Menu

#63 Possible memory corruption in ow_cache.c, ow_connect.c and ow_tree.c

v0.9x
open
nobody
1
2014-09-11
2014-09-03
Tiger
No

Building the 2.9p5 version causes warnings due to missing 'tdestroy' declarations.

~~~~~~
ow_cache.c: In function 'Cache_Close':
ow_cache.c:285:2: warning: implicit declaration of function 'tdestroy' [-Wimplicit-function-declaration]
SAFETDESTROY( cache.persistent_tree, owfree_func);
^
ow_connect.c: In function 'RemoveIn':
ow_connect.c:243:2: warning: implicit declaration of function 'tdestroy' [-Wimplicit-function-declaration]
SAFETDESTROY( conn->dev_db, owfree_func);
^
ow_tree.c: In function 'DeviceDestroy':
ow_tree.c:85:2: warning: implicit declaration of function 'tdestroy' [-Wimplicit-function-declaration]
tdestroy( sensor_tree, owfree_func ) ;
^
~~~~~

This may cause memory leaks or memory corruption whenever objects are destroyed. Please, check if there are any includes missing or explicitly declare the function tdestroy.

Discussion

  • Paul Alfille

    Paul Alfille - 2014-09-04

    This is a gnu extension. What platform are you building on?

    An implementation is in module/owlib/src/c/compat.c

    Should be activated by HAVE_TDESTROY

     
  • Tiger

    Tiger - 2014-09-09

    I'm using gcc 4.8.2 with musl libc 1.1.4.

    Thanks for the hint regarding HAVE_TDESTROY! The following patches made it work for me, though I'm not sure if they'd break glibc builds.

    --- owfs-2.9p5/module/ownet/c/src/include/compat.h
    +++ owfs-2.9p5/module/ownet/c/src/include/compat.h
    @@ -75 +75 @@
    -
    +#undef HAVE_TDESTROY
    
    --- owfs-2.9p5/module/owlib/src/include/compat.h
    +++ owfs-2.9p5/module/owlib/src/include/compat.h
    @@ -75 +75 @@
    -
    +#undef HAVE_TDESTROY
    
     
  • Paul Alfille

    Paul Alfille - 2014-09-09

    Thanks but that's a rather heavy-handed way of fixing it. Is there a way to set the value only for mucl libc?

     
  • Paul Alfille

    Paul Alfille - 2014-09-09

    I posted your question to the mucl discussion list:

    Szabolcs Nagy nsz@port70.net via lists.openwall.com
    2:37 PM (2 hours ago)

    to musl
    * Paul Alfille paul.alfille@gmail.com [2014-09-09 14:29:36 -0400]:

    I have an alternative implementation to tdestroy that is triggered by
    HAVE_TDESTROY created by autoconf / automake.

    Apparently the macro
    AC_CHECK_FUNCS([twalk tsearch tfind tdelete tdestroy])

    doesn't find tdestroy is missing in mucl.

    So my questions are:
    1. Is there a fix to the configuration -- either a recommended way to add
    special cases for mucl of a fix for the detection?
    2. Any chance you could add tdestroy?

    musl does have tdestroy

    but you need -D_GNU_SOURCE to have it visible in search.h

     
  • Tiger

    Tiger - 2014-09-11

    Paul, thank you very much for your dedicated support! I'm new to musl myself and really appreciate your help.

    '-D_GNU_SOURCE' works nicely, though four source files seem to overwrite the setting and therefore require modification.

    --- owfs-2.9p5/module/owlib/src/c/ow_alias.c
    +++ owfs-2.9p5/module/owlib/src/c/ow_alias.c
    @@ -13,0 +14,3 @@
    +#ifdef _GNU_SOURCE
    +#define IS_GNU_SOURCE
    +#else
    @@ -14,0 +18 @@
    +#endif
    @@ -15,0 +20 @@
    +#ifndef IS_GNU_SOURCE
    @@ -16,0 +22 @@
    +#endif
    
    --- owfs-2.9p5/module/owlib/src/c/ow_opt.c
    +++ owfs-2.9p5/module/owlib/src/c/ow_opt.c
    @@ -13,0 +14,3 @@
    +#ifdef _GNU_SOURCE
    +#define IS_GNU_SOURCE
    +#else
    @@ -14,0 +18 @@
    +#endif
    @@ -15,0 +20 @@
    +#ifndef IS_GNU_SOURCE
    @@ -16,0 +22 @@
    +#endif
    
    --- owfs-2.9p5/module/owhttpd/src/c/owhttpd_handler.c
    +++ owfs-2.9p5/module/owhttpd/src/c/owhttpd_handler.c
    @@ -11,0 +12,3 @@
    +#ifdef _GNU_SOURCE
    +#define IS_GNU_SOURCE
    +#else
    @@ -12,0 +16 @@
    +#endif
    @@ -13,0 +18 @@
    +#ifndef IS_GNU_SOURCE
    @@ -14,0 +20 @@
    +#endif
    
    --- owfs-2.9p5/module/owtcl/ow.c
    +++ owfs-2.9p5/module/owtcl/ow.c
    @@ -31,0 +32 @@
    +#ifndef _GNU_SOURCE
    @@ -32,0 +34 @@
    +#endif
    

    The files

    • owfs-2.9p5/module/owshell/src/c/getaddrinfo.c
    • owfs-2.9p5/module/owlib/src/c/getaddrinfo.c

    do set _GNU_SOURCE as well, but this doesn't cause conflicts as long as _GNU_SOURCE isn't undef'ed.

     

    Last edit: Tiger 2014-09-11