Menu

#272 sox_formats_quit does not properly clean things up

closed-fixed
nobody
None
5
2020-08-04
2016-01-10
No

The following simple program (attachment test.c) crashes when libsox is compiled dynamically ( i.e. --with_dyn_default ), e.g. in most Linux distros like Debian/Ubuntu or Fedora and derivatives.

The reason is that the end condition for the for cycle in "sox_find_format" ( from src/formats.c ) is "s_sox_format_fns[f].fn == NULL", a condition which does not occur if "s_sox_format_fns[f].fn" points to an in invalid address. Unfortunately, that's exactly what happens when libsox is compiled dynamically, the searched format is compiled in a plugin and the progam calls libsox more than once: the last ( f = NSTATIC_FORMATS ) "s_sox_format_fns[f].fn" is not NULL and points to the address of the first plugin function, when it was allocated the first time ( which of course is no more a valid address the second time it is allocated ).

A possible solution is in the attached patch: "sox_format_quit" ( from src/formats.c ) set "s_sox_format_fns[NSTATIC_FORMATS].fn" to NULL, so that the for cycle correctly ends if it doesn't find the format, that it was looking for, among those statically compiled. When libsox calls "sox_format_init" again, the addresses in "s_sox_format_fns[f].fn" are all valid again beyond NSTATIC_FORMATS and the function can work properly.

1 Attachments

Discussion

  • Stefano Guidoni

    Stefano Guidoni - 2016-01-10

    A working patch:

    --- old/src/formats.c   2015-02-27 04:48:40.000000000 +0100
    +++ new/src/formats.c   2016-01-10 22:14:58.203847117 +0100
    @@ -1247,6 +1247,8 @@
         lsx_fail("lt_dlexit failed with %d error(s): %s", ret, lt_dlerror());
       plugins_initted = sox_false;
       nformats = NSTATIC_FORMATS;
    
    +  s_sox_format_fns[NSTATIC_FORMATS].name = NULL;
    +  s_sox_format_fns[NSTATIC_FORMATS].fn = NULL;
     #endif
     }
    
     
  • Mans Rullgard

    Mans Rullgard - 2020-08-04
    • status: open --> closed-fixed
     
  • Mans Rullgard

    Mans Rullgard - 2020-08-04

    Fixed.

     

Log in to post a comment.