cdda: fix possible buffer overrun

If the requested read was more than 32 frames, and reading them all at
once failed, we would try to read by chunk of 8 frames. But if the
original frame count was not a multiple of 8 we would not adjust the
count for the last read.

Unfortunately I could still panic the system after fixing this, so it is
not *the* cdda bug.
This commit is contained in:
Adrien Destugues
2014-11-12 16:22:48 +01:00
parent db214549c5
commit 938c41a1aa
@@ -9,6 +9,7 @@
#include <KernelExport.h>
#include <device/scsi.h>
#include <algorithm>
#include <ctype.h>
#include <errno.h>
#include <stdlib.h>
@@ -460,6 +461,12 @@ read_frames(int fd, off_t firstFrame, uint8 *buffer, size_t count)
size_t framesLeft = count;
while (framesLeft > 0) {
// If the initial count was >= 32, and not a multiple of 8, and the
// ioctl fails, we switch to reading 8 frames at a time. However the
// last read can read between 1 and 7 frames only, to not overflow
// the buffer.
count = std::min(count, framesLeft);
scsi_read_cd read;
read.start_m = firstFrame / kFramesPerMinute;
read.start_s = (firstFrame / kFramesPerSecond) % 60;
@@ -482,6 +489,7 @@ read_frames(int fd, off_t firstFrame, uint8 *buffer, size_t count)
count = 8;
else
count = 1;
continue;
}