Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
fix(audio): keep the data pointed to by tmpDevName in scope
Browse files Browse the repository at this point in the history
Fix the use after free in Audio::initInput and Audio::initOutput
by storing the buffer returned by QString::toUtf8 (which contains data
pointed to by tmpDevName) in an intermediate variable, preventing the
buffer from falling out of scope for the duration of the function.

Fixes #3786
  • Loading branch information
kdhp committed Oct 6, 2016
1 parent bbdd4f0 commit af37fa7
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/audio/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,12 @@ bool Audio::initInput(const QString& deviceName)
const uint32_t chnls = AUDIO_CHANNELS;
const ALCsizei bufSize = (frameDuration * sampleRate * 4) / 1000 * chnls;

const QByteArray qDevName = deviceName.isEmpty()
? nullptr
: deviceName.toUtf8();
const ALchar* tmpDevName = deviceName.isEmpty()
? nullptr
: deviceName.toUtf8().constData();
: qDevName.constData();
alInDev = alcCaptureOpenDevice(tmpDevName, sampleRate, stereoFlag, bufSize);

// Restart the capture if necessary
Expand Down Expand Up @@ -386,9 +389,12 @@ bool Audio::initOutput(const QString& deviceName)
qDebug() << "Opening audio output" << deviceName;
assert(!alOutDev);

const QByteArray qDevName = deviceName.isEmpty()
? nullptr
: deviceName.toUtf8();
const ALchar* tmpDevName = deviceName.isEmpty()
? nullptr
: deviceName.toUtf8().constData();
: qDevName.constData();
alOutDev = alcOpenDevice(tmpDevName);

if (!alOutDev)
Expand Down

0 comments on commit af37fa7

Please sign in to comment.