tsmf: Prevent string overflow and unterminated strings

Device variable can overflow, or be unterminated. Replace strcpy
by strncpy and be sure that the string is terminated (sizeof() - 1).
This commit is contained in:
Ondrej Holy 2017-12-19 12:21:34 +01:00
parent 0389cb129e
commit e2f9a08107
3 changed files with 3 additions and 3 deletions

View 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);
}

View 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)

View 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)