diff options
author | Taylor Holberton <taylorcholberton@gmail.com> | 2016-06-26 14:29:36 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-06-26 14:29:36 -0400 |
commit | b47a014f1460ffd6479fd8306c679475b03f27f1 (patch) | |
tree | b1c07f0b1c902b31df401241931de0e57665c7bf | |
parent | 9bad3fa00f3080906566c6b3acd14513d1ae4afd (diff) | |
parent | 7ed2ffb4dd643f75022d1c18f2b7e615e9559840 (diff) |
Merge pull request #77 from bzhg/master
mixer: check for overflow and NULL return
-rw-r--r-- | mixer.c | 9 |
1 files changed, 9 insertions, 0 deletions
@@ -28,6 +28,7 @@ #include <stdio.h> #include <stdlib.h> +#include <stdint.h> #include <string.h> #include <unistd.h> #include <fcntl.h> @@ -366,7 +367,11 @@ int mixer_ctl_get_array(struct mixer_ctl *ctl, void *array, size_t count) struct snd_ctl_tlv *tlv; int ret; + if (count > SIZE_MAX - sizeof(*tlv)) + return -EINVAL; tlv = calloc(1, sizeof(*tlv) + count); + if (!tlv) + return -ENOMEM; tlv->numid = ctl->info.id.numid; tlv->length = count; ret = ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_TLV_READ, tlv); @@ -462,7 +467,11 @@ int mixer_ctl_set_array(struct mixer_ctl *ctl, const void *array, size_t count) if (ctl->info.access & SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE) { struct snd_ctl_tlv *tlv; int ret = 0; + if (count > SIZE_MAX - sizeof(*tlv)) + return -EINVAL; tlv = calloc(1, sizeof(*tlv) + count); + if (!tlv) + return -ENOMEM; tlv->numid = ctl->info.id.numid; tlv->length = count; memcpy(tlv->tlv, array, count); |