Fixed callback parameter checks.
authorArmin Novak <armin.novak@thincast.com>
Mon, 30 Jul 2018 09:22:11 +0000 (11:22 +0200)
committerArmin Novak <armin.novak@thincast.com>
Mon, 30 Jul 2018 09:22:11 +0000 (11:22 +0200)
channels/audin/client/alsa/audin_alsa.c
channels/audin/client/audin_main.c
channels/audin/client/opensles/audin_opensl_es.c
channels/audin/client/pulse/audin_pulse.c
channels/audin/client/winmm/audin_winmm.c

index 4f9b986..169422a 100644 (file)
@@ -215,7 +215,10 @@ out:
 static UINT audin_alsa_free(IAudinDevice* device)
 {
        AudinALSADevice* alsa = (AudinALSADevice*) device;
-       free(alsa->device_name);
+
+       if (alsa)
+               free(alsa->device_name);
+
        free(alsa);
        return CHANNEL_RC_OK;
 }
@@ -223,6 +226,9 @@ static UINT audin_alsa_free(IAudinDevice* device)
 static BOOL audin_alsa_format_supported(IAudinDevice* device,
                                         const AUDIO_FORMAT* format)
 {
+       if (!device || !format)
+               return FALSE;
+
        switch (format->wFormatTag)
        {
                case WAVE_FORMAT_PCM:
@@ -256,6 +262,10 @@ static UINT audin_alsa_set_format(IAudinDevice* device, const AUDIO_FORMAT* form
                                   UINT32 FramesPerPacket)
 {
        AudinALSADevice* alsa = (AudinALSADevice*) device;
+
+       if (!alsa || !format)
+               return ERROR_INVALID_PARAMETER;
+
        alsa->aformat = *format;
        alsa->frames_per_packet = FramesPerPacket;
 
@@ -274,6 +284,10 @@ static UINT audin_alsa_open(IAudinDevice* device, AudinReceive receive,
                             void* user_data)
 {
        AudinALSADevice* alsa = (AudinALSADevice*) device;
+
+       if (!device || !receive || !user_data)
+               return ERROR_INVALID_PARAMETER;
+
        alsa->receive = receive;
        alsa->user_data = user_data;
 
@@ -307,6 +321,9 @@ static UINT audin_alsa_close(IAudinDevice* device)
        UINT error = CHANNEL_RC_OK;
        AudinALSADevice* alsa = (AudinALSADevice*) device;
 
+       if (!alsa)
+               return ERROR_INVALID_PARAMETER;
+
        if (alsa->stopEvent)
        {
                SetEvent(alsa->stopEvent);
index 6f8fb42..619286d 100644 (file)
@@ -696,6 +696,13 @@ static UINT audin_on_new_channel_connection(IWTSListenerCallback* pListenerCallb
 static UINT audin_plugin_initialize(IWTSPlugin* pPlugin, IWTSVirtualChannelManager* pChannelMgr)
 {
        AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*) pPlugin;
+
+       if (!audin)
+               return CHANNEL_RC_BAD_CHANNEL_HANDLE;
+
+       if (!pChannelMgr)
+               return ERROR_INVALID_PARAMETER;
+
        WLog_Print(audin->log, WLOG_TRACE, "...");
        audin->listener_callback = (AUDIN_LISTENER_CALLBACK*) calloc(1, sizeof(AUDIN_LISTENER_CALLBACK));
 
@@ -721,6 +728,10 @@ static UINT audin_plugin_terminated(IWTSPlugin* pPlugin)
 {
        AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*) pPlugin;
        UINT error = CHANNEL_RC_OK;
+
+       if (!audin)
+               return CHANNEL_RC_BAD_CHANNEL_HANDLE;
+
        WLog_Print(audin->log, WLOG_TRACE, "...");
 
        if (audin->device)
index 1216e4d..5b89e7e 100644 (file)
@@ -145,6 +145,10 @@ out:
 static UINT audin_opensles_free(IAudinDevice* device)
 {
        AudinOpenSLESDevice* opensles = (AudinOpenSLESDevice*) device;
+
+       if (!opensles)
+               return ERROR_INVALID_PARAMETER;
+
        WLog_Print(opensles->log, WLOG_DEBUG, "device=%p", (void*) device);
 
        /* The function may have been called out of order,
@@ -163,6 +167,10 @@ static BOOL audin_opensles_format_supported(IAudinDevice* device,
         const AUDIO_FORMAT* format)
 {
        AudinOpenSLESDevice* opensles = (AudinOpenSLESDevice*) device;
+
+       if (!opensles || !format)
+               return FALSE;
+
        WLog_Print(opensles->log, WLOG_DEBUG, "device=%p, format=%p", (void*) opensles, (void*) format);
        assert(format);
 
@@ -198,6 +206,10 @@ static UINT audin_opensles_set_format(IAudinDevice* device,
                                       const AUDIO_FORMAT* format, UINT32 FramesPerPacket)
 {
        AudinOpenSLESDevice* opensles = (AudinOpenSLESDevice*) device;
+
+       if (!opensles || !format)
+               return ERROR_INVALID_PARAMETER;
+
        WLog_Print(opensles->log, WLOG_DEBUG, "device=%p, format=%p, FramesPerPacket=%"PRIu32"",
                   (void*) device, (void*) format, FramesPerPacket);
        assert(format);
@@ -255,6 +267,10 @@ static UINT audin_opensles_open(IAudinDevice* device, AudinReceive receive,
                                 void* user_data)
 {
        AudinOpenSLESDevice* opensles = (AudinOpenSLESDevice*) device;
+
+       if (!opensles || !receive || !user_data)
+               return ERROR_INVALID_PARAMETER;
+
        WLog_Print(opensles->log, WLOG_DEBUG, "device=%p, receive=%p, user_data=%p", (void*) device,
                   (void*) receive,
                   (void*) user_data);
index cd687b3..3a5ff73 100644 (file)
@@ -178,6 +178,9 @@ static BOOL audin_pulse_format_supported(IAudinDevice* device, const AUDIO_FORMA
 {
        AudinPulseDevice* pulse = (AudinPulseDevice*) device;
 
+       if (!pulse || !format)
+               return FALSE;
+
        if (!pulse->context)
                return 0;
 
@@ -224,6 +227,9 @@ static UINT audin_pulse_set_format(IAudinDevice* device, const AUDIO_FORMAT* for
        pa_sample_spec sample_spec = { 0 };
        AudinPulseDevice* pulse = (AudinPulseDevice*) device;
 
+       if (!pulse || !format)
+               return ERROR_INVALID_PARAMETER;
+
        if (!pulse->context)
                return ERROR_INVALID_PARAMETER;
 
@@ -317,6 +323,9 @@ static UINT audin_pulse_close(IAudinDevice* device)
 {
        AudinPulseDevice* pulse = (AudinPulseDevice*) device;
 
+       if (!pulse)
+               return ERROR_INVALID_PARAMETER;
+
        if (pulse->stream)
        {
                pa_threaded_mainloop_lock(pulse->mainloop);
@@ -342,6 +351,9 @@ static UINT audin_pulse_open(IAudinDevice* device, AudinReceive receive, void* u
        pa_buffer_attr buffer_attr = { 0 };
        AudinPulseDevice* pulse = (AudinPulseDevice*) device;
 
+       if (!pulse || !receive || !user_data)
+               return ERROR_INVALID_PARAMETER;
+
        if (!pulse->context)
                return ERROR_INVALID_PARAMETER;
 
index d80e61a..5e21005 100644 (file)
@@ -242,6 +242,9 @@ static UINT audin_winmm_free(IAudinDevice* device)
        UINT32 i;
        AudinWinmmDevice* winmm = (AudinWinmmDevice*) device;
 
+       if (!winmm)
+               return ERROR_INVALID_PARAMETER;
+
        for (i = 0; i < winmm->cFormats; i++)
        {
                free(winmm->ppwfx[i]);
@@ -263,6 +266,10 @@ static UINT audin_winmm_close(IAudinDevice* device)
        DWORD status;
        UINT error = CHANNEL_RC_OK;
        AudinWinmmDevice* winmm = (AudinWinmmDevice*) device;
+
+       if (!winmm)
+               return ERROR_INVALID_PARAMETER;
+
        SetEvent(winmm->stopEvent);
        status = WaitForSingleObject(winmm->thread, INFINITE);
 
@@ -292,6 +299,10 @@ static UINT audin_winmm_set_format(IAudinDevice* device, const AUDIO_FORMAT* for
 {
        UINT32 i;
        AudinWinmmDevice* winmm = (AudinWinmmDevice*) device;
+
+       if (!winmm || !format)
+               return ERROR_INVALID_PARAMETER;
+
        winmm->frames_per_packet = FramesPerPacket;
 
        for (i = 0; i < winmm->cFormats; i++)
@@ -313,6 +324,10 @@ static BOOL audin_winmm_format_supported(IAudinDevice* device, const AUDIO_FORMA
        AudinWinmmDevice* winmm = (AudinWinmmDevice*) device;
        PWAVEFORMATEX pwfx;
        BYTE* data;
+
+       if (!winmm || !format)
+               return FALSE;
+
        pwfx = (PWAVEFORMATEX)malloc(sizeof(WAVEFORMATEX) + format->cbSize);
 
        if (!pwfx)
@@ -362,6 +377,10 @@ static BOOL audin_winmm_format_supported(IAudinDevice* device, const AUDIO_FORMA
 static UINT audin_winmm_open(IAudinDevice* device, AudinReceive receive, void* user_data)
 {
        AudinWinmmDevice* winmm = (AudinWinmmDevice*) device;
+
+       if (!winmm || !receive || !user_data)
+               return ERROR_INVALID_PARAMETER;
+
        winmm->receive = receive;
        winmm->user_data = user_data;