From d42342e0baecdedd92385129f9456b2d34bded12 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 5 Aug 2021 15:51:11 +0200 Subject: [PATCH] output/oss: check returned value in oss_try_ioctl() --- src/output/plugins/OssOutputPlugin.cxx | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/output/plugins/OssOutputPlugin.cxx b/src/output/plugins/OssOutputPlugin.cxx index 9228cd954..cd86757e6 100644 --- a/src/output/plugins/OssOutputPlugin.cxx +++ b/src/output/plugins/OssOutputPlugin.cxx @@ -252,19 +252,24 @@ oss_try_ioctl_r(FileDescriptor fd, unsigned long request, int *value_r, } /** - * Invoke an ioctl on the OSS file descriptor. + * Invoke an ioctl on the OSS file descriptor, and expect an + * unmodified effective value. * * Throws on error. */ static void -oss_try_ioctl(FileDescriptor fd, unsigned long request, int value, +OssIoctlExact(FileDescriptor fd, unsigned long request, int requested_value, const char *msg) { assert(fd.IsDefined()); assert(msg != nullptr); - if (ioctl(fd.Get(), request, &value) < 0) + int effective_value = requested_value; + if (ioctl(fd.Get(), request, &effective_value) < 0) throw MakeErrno(msg); + + if (effective_value != requested_value) + throw std::runtime_error(msg); } /** @@ -529,11 +534,11 @@ try { if (!fd.Open(device, O_WRONLY)) throw FormatErrno("Error opening OSS device \"%s\"", device); - oss_try_ioctl(fd, SNDCTL_DSP_CHANNELS, audio_format.channels, + OssIoctlExact(fd, SNDCTL_DSP_CHANNELS, audio_format.channels, "Failed to set channel count"); - oss_try_ioctl(fd, SNDCTL_DSP_SPEED, audio_format.sample_rate, + OssIoctlExact(fd, SNDCTL_DSP_SPEED, audio_format.sample_rate, "Failed to set sample rate"); - oss_try_ioctl(fd, SNDCTL_DSP_SAMPLESIZE, oss_format, + OssIoctlExact(fd, SNDCTL_DSP_SAMPLESIZE, oss_format, "Failed to set sample format"); } catch (...) { DoClose();