shithub: aubio

Download patch

ref: cf387e32a630e0abb171506fc6985986878515b9
parent: 0f5d3724a8342b5e119b7dd669c97f661fdc554e
author: Paul Brossier <piem@piem.org>
date: Sun Dec 16 14:15:42 EST 2018

[io] prevent crash on empty string and potential leak in sink_apple_audio

--- a/src/io/sink_apple_audio.c
+++ b/src/io/sink_apple_audio.c
@@ -61,11 +61,11 @@
   s->max_frames = MAX_SIZE;
   s->async = false;
 
-  if ( (uri == NULL) || (strlen(uri) < 1) ) {
+  if ( (uri == NULL) || (strnlen(uri, PATH_MAX) < 1) ) {
     AUBIO_ERROR("sink_apple_audio: Aborted opening null path\n");
     goto beach;
   }
-  if (s->path != NULL) AUBIO_FREE(s->path);
+
   s->path = AUBIO_ARRAY(char_t, strnlen(uri, PATH_MAX) + 1);
   strncpy(s->path, uri, strnlen(uri, PATH_MAX) + 1);
 
@@ -91,7 +91,7 @@
 
   return s;
 beach:
-  AUBIO_FREE(s);
+  del_aubio_sink_apple_audio(s);
   return NULL;
 }
 
@@ -102,7 +102,7 @@
   }
   s->samplerate = samplerate;
   // automatically open when both samplerate and channels have been set
-  if (s->samplerate != 0 && s->channels != 0) {
+  if (/* s->samplerate != 0 && */ s->channels != 0) {
     return aubio_sink_apple_audio_open(s);
   }
   return AUBIO_OK;
@@ -115,7 +115,7 @@
   }
   s->channels = channels;
   // automatically open when both samplerate and channels have been set
-  if (s->samplerate != 0 && s->channels != 0) {
+  if (s->samplerate != 0 /* && s->channels != 0 */) {
     return aubio_sink_apple_audio_open(s);
   }
   return AUBIO_OK;
@@ -249,11 +249,13 @@
 }
 
 void del_aubio_sink_apple_audio(aubio_sink_apple_audio_t * s) {
-  if (s->audioFile) aubio_sink_apple_audio_close (s);
-  if (s->path) AUBIO_FREE(s->path);
+  AUBIO_ASSERT(s);
+  if (s->audioFile)
+    aubio_sink_apple_audio_close (s);
+  if (s->path)
+    AUBIO_FREE(s->path);
   freeAudioBufferList(&s->bufferList);
   AUBIO_FREE(s);
-  return;
 }
 
 #endif /* HAVE_SINK_APPLE_AUDIO */