tsmf: Prevent string overflow and unterminated strings
authorOndrej Holy <oholy@redhat.com>
Tue, 19 Dec 2017 11:21:34 +0000 (12:21 +0100)
committerOndrej Holy <oholy@redhat.com>
Tue, 19 Dec 2017 11:21:34 +0000 (12:21 +0100)
Device variable can overflow, or be unterminated. Replace strcpy
by strncpy and be sure that the string is terminated (sizeof() - 1).

channels/tsmf/client/alsa/tsmf_alsa.c
channels/tsmf/client/oss/tsmf_oss.c
channels/tsmf/client/pulse/tsmf_pulse.c

index 02f3941..78a0a66 100644 (file)
@@ -72,7 +72,7 @@ static BOOL tsmf_alsa_open(ITSMFAudioDevice *audio, const char *device)
        }
        else
        {
-               strncpy(alsa->device, device, sizeof(alsa->device));
+               strncpy(alsa->device, device, sizeof(alsa->device) - 1);
        }
        return tsmf_alsa_open_device(alsa);
 }
index 305f0ce..db88ddb 100644 (file)
@@ -81,7 +81,7 @@ static BOOL tsmf_oss_open(ITSMFAudioDevice* audio, const char* device)
        }
        else
        {
-               strncpy(oss->dev_name, device, sizeof(oss->dev_name));
+               strncpy(oss->dev_name, device, sizeof(oss->dev_name) - 1);
        }
 
        if ((oss->pcm_handle = open(oss->dev_name, O_WRONLY)) < 0)
index b61f989..e6da925 100644 (file)
@@ -115,7 +115,7 @@ static BOOL tsmf_pulse_open(ITSMFAudioDevice *audio, const char *device)
        TSMFPulseAudioDevice *pulse = (TSMFPulseAudioDevice *) audio;
        if(device)
        {
-               strcpy(pulse->device, device);
+               strncpy(pulse->device, device, sizeof(pulse->device) - 1);
        }
        pulse->mainloop = pa_threaded_mainloop_new();
        if(!pulse->mainloop)