diff options
author | Baili Deng <bailideng@google.com> | 2024-05-07 16:43:33 +0800 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2024-05-08 04:12:55 +0000 |
commit | 2975e1a2d677f2b3fca5f800281dad50828c8f13 (patch) | |
tree | d127ba870543f29543168d2341fcec1111ad485f | |
parent | ede94f8df6827db92ba961c92780c06aebed3744 (diff) | |
download | adhd-2975e1a2d677f2b3fca5f800281dad50828c8f13.tar.gz |
Set invalid aio->common.mmap_buf to NULL
Set aio->common.mmap_buf to NULL when cras_alsa_mmap_begin returns
error. This is to prevent bad mmap buffer causing issues with the
copying, and ensures any issues caused by this can be caught with a NULL
check.
BUG=b:332638238
TEST=Unit tests
Change-Id: Icd745b4d6aae27053fc20a22ac40b98d419d45f0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/adhd/+/5517972
Tested-by: Baili Deng <bailideng@google.com>
Auto-Submit: Baili Deng <bailideng@google.com>
Reviewed-by: Judy Hsiao <judyhsiao@google.com>
Tested-by: chromeos-cop-builder@chromeos-cop.iam.gserviceaccount.com <chromeos-cop-builder@chromeos-cop.iam.gserviceaccount.com>
Commit-Queue: Baili Deng <bailideng@google.com>
-rw-r--r-- | cras/src/server/cras_alsa_io.c | 3 | ||||
-rw-r--r-- | cras/src/server/cras_alsa_usb_io.c | 3 |
2 files changed, 4 insertions, 2 deletions
diff --git a/cras/src/server/cras_alsa_io.c b/cras/src/server/cras_alsa_io.c index c56b482e..e990edd7 100644 --- a/cras/src/server/cras_alsa_io.c +++ b/cras/src/server/cras_alsa_io.c @@ -446,6 +446,7 @@ static int get_buffer(struct cras_iodev* iodev, &aio->common.mmap_buf, &aio->common.mmap_offset, &nframes); if (rc < 0) { + aio->common.mmap_buf = NULL; return rc; } iodev->area->frames = nframes; @@ -483,7 +484,7 @@ static int put_buffer(struct cras_iodev* iodev, unsigned nwritten) { return -EINVAL; } memcpy(aio->common.mmap_buf, aio->common.sample_buf, - nwritten * format_bytes); + (size_t)nwritten * (size_t)format_bytes); unsigned int max_offset = cras_iodev_max_stream_offset(iodev); if (max_offset) { memmove(aio->common.sample_buf, diff --git a/cras/src/server/cras_alsa_usb_io.c b/cras/src/server/cras_alsa_usb_io.c index bec39cee..6f00743c 100644 --- a/cras/src/server/cras_alsa_usb_io.c +++ b/cras/src/server/cras_alsa_usb_io.c @@ -268,6 +268,7 @@ static int usb_get_buffer(struct cras_iodev* iodev, &aio->common.mmap_buf, &aio->common.mmap_offset, &nframes); if (rc < 0) { + aio->common.mmap_buf = NULL; return rc; } iodev->area->frames = nframes; @@ -293,7 +294,7 @@ static int usb_put_buffer(struct cras_iodev* iodev, unsigned nwritten) { size_t format_bytes = cras_get_format_bytes(iodev->format); if (iodev->direction == CRAS_STREAM_OUTPUT) { memcpy(aio->common.mmap_buf, aio->common.sample_buf, - nwritten * format_bytes); + (size_t)nwritten * (size_t)format_bytes); unsigned int max_offset = cras_iodev_max_stream_offset(iodev); if (max_offset) { memmove(aio->common.sample_buf, |