shithub: sox

Download patch

ref: 20a644501fcae2d1d1655deb952abf3eca74dab5
parent: a090595a4d498f1f2eb68b63f07c514b6ae26a95
author: Mans Rullgard <mans@mansr.com>
date: Tue Aug 4 17:50:55 EDT 2020

formats: fix crash in sox_find_format() after sox_format_quit() [bug #272]

After sox_format_quit() has been called, the format list may contain
stale entries from any plugins that were previously loaded.  The
search loop in sox_find_format() will then choke on these.  Fix it
by limiting the search to 'nformats' which reflects the number of
currently valid entries.

--- a/src/formats.c
+++ b/src/formats.c
@@ -1237,8 +1237,9 @@
     return s_sox_format_fns;
 }
 
+static unsigned nformats = NSTATIC_FORMATS;
+
 #ifdef HAVE_LIBLTDL /* Plugin format handlers */
-  static unsigned nformats = NSTATIC_FORMATS;
 
   static int init_format(const char *file, lt_ptr data)
   {
@@ -1321,7 +1322,7 @@
     char * pos = strchr(name, ';');
     if (pos) /* Use only the 1st clause of a mime string */
       *pos = '\0';
-    for (f = 0; s_sox_format_fns[f].fn; ++f) {
+    for (f = 0; f < nformats; ++f) {
       sox_format_handler_t const * handler = s_sox_format_fns[f].fn();
 
       if (!(no_dev && (handler->flags & SOX_FILE_DEVICE)))