From 876c92fd4c34ec80a5ada85ff29781522d43a233 Mon Sep 17 00:00:00 2001 From: naddy Date: Thu, 27 Oct 2022 14:43:29 +0000 Subject: [PATCH] audio/libao: check memory allocations for success From upstream, via Brad --- audio/libao/Makefile | 2 +- audio/libao/patches/patch-src_audio_out_c | 149 ++++++++++++++++++ .../patch-src_plugins_sndio_ao_sndio_c | 21 ++- 3 files changed, 166 insertions(+), 6 deletions(-) create mode 100644 audio/libao/patches/patch-src_audio_out_c diff --git a/audio/libao/Makefile b/audio/libao/Makefile index 642e0ca00a5..68249cd0805 100644 --- a/audio/libao/Makefile +++ b/audio/libao/Makefile @@ -4,7 +4,7 @@ DISTNAME= libao-1.2.0 CATEGORIES= audio HOMEPAGE= https://www.xiph.org/ao/ SHARED_LIBS= ao 5.0 # 5.0 -REVISION= 1 +REVISION= 2 MAINTAINER= Christian Weisgerber diff --git a/audio/libao/patches/patch-src_audio_out_c b/audio/libao/patches/patch-src_audio_out_c new file mode 100644 index 00000000000..1f62497252c --- /dev/null +++ b/audio/libao/patches/patch-src_audio_out_c @@ -0,0 +1,149 @@ +Check memory allocations for success +https://gitlab.xiph.org/xiph/libao/-/commit/d5221655dfd1a2156aa6be83b5aadea7c1e0f5bd + +Index: src/audio_out.c +--- src/audio_out.c.orig ++++ src/audio_out.c +@@ -634,6 +634,10 @@ static char *_sanitize_matrix(int maxchannels, char *m + char *ret = calloc(strlen(matrix)+1,1); /* can only get smaller */ + char *p=matrix; + int count=0; ++ ++ if(!ret) ++ return NULL; ++ + while(countp && isspace(*(t-1)))t--; + + ret[count] = calloc(t-p+1,1); ++ if(!ret[count]){ ++ _free_map(ret); ++ return NULL; ++ } + memcpy(ret[count],p,t-p); + count++; + if(!*h)break; +@@ -756,25 +775,22 @@ static char **_tokenize_matrix(char *matrix){ + } + + return ret; +- + } + +-static void _free_map(char **m){ +- char **in=m; +- while(m && *m){ +- free(*m); +- m++; +- } +- if(in)free(in); +-} +- + static unsigned int _matrix_to_channelmask(int ch, char *matrix, char *premap, int **mout){ + unsigned int ret=0; + char *p=matrix; + int *perm=(*mout=malloc(ch*sizeof(*mout))); + int i; +- char **map = _tokenize_matrix(premap); ++ char **map; + ++ if(!perm) ++ return 0; ++ ++ map = _tokenize_matrix(premap); ++ if(!map) ++ return 0; ++ + for(i=0;ioutput_matrix, + &device->input_map); + int channels = _channelmask_bits(mask); +- if(channels<0){ ++ if(channels<=0){ + aerror("Unable to map any channels from input matrix to output"); + errno = AO_EBADFORMAT; + goto error; +@@ -1061,7 +1083,7 @@ static ao_device* _open_device(int driver_id, ao_sampl + device->output_matrix, + &device->input_map); + int channels = _channelmask_bits(mask); +- if(channels<0){ ++ if(channels<=0){ + aerror("Unable to map any channels from input matrix to output"); + errno = AO_EBADFORMAT; + goto error; +@@ -1112,6 +1134,10 @@ static ao_device* _open_device(int driver_id, ao_sampl + int count=0; + device->inter_permute = calloc(device->output_channels,sizeof(int)); + ++ if (!device->inter_permute) { ++ errno = AO_EFAIL; ++ goto error; ++ } + adebug("\n"); + + while(countoutput_channels){ +@@ -1158,8 +1184,10 @@ static ao_device* _open_device(int driver_id, ao_sampl + for(i=0;ioutput_channels;i++) + if(device->inter_permute[i]==j)break; + if(i==device->output_channels){ +- adebug("input %d (%s)\t -> none\n", +- j,inch[j]); ++ if(inch){ ++ adebug("input %d (%s)\t -> none\n", ++ j,inch[j]); ++ } + unflag=1; + } + } diff --git a/audio/libao/patches/patch-src_plugins_sndio_ao_sndio_c b/audio/libao/patches/patch-src_plugins_sndio_ao_sndio_c index 0c9df6cc673..074b240ad83 100644 --- a/audio/libao/patches/patch-src_plugins_sndio_ao_sndio_c +++ b/audio/libao/patches/patch-src_plugins_sndio_ao_sndio_c @@ -1,6 +1,17 @@ ---- src/plugins/sndio/ao_sndio.c.orig Tue Feb 14 01:46:06 2012 -+++ src/plugins/sndio/ao_sndio.c Tue May 27 17:07:14 2014 -@@ -99,6 +99,7 @@ int ao_plugin_set_option(ao_device *device, const char +Index: src/plugins/sndio/ao_sndio.c +--- src/plugins/sndio/ao_sndio.c.orig ++++ src/plugins/sndio/ao_sndio.c +@@ -67,6 +67,9 @@ int ao_plugin_device_init(ao_device *device) + { + ao_sndio_internal *internal; + internal = (ao_sndio_internal *) calloc(1,sizeof(*internal)); ++ if (internal == NULL) ++ return 0; ++ + internal->id=-1; + device->internal = internal; + device->output_matrix_order = AO_OUTPUT_MATRIX_FIXED; +@@ -99,6 +102,7 @@ int ao_plugin_set_option(ao_device *device, const char int ao_plugin_open(ao_device *device, ao_sample_format *format) { ao_sndio_internal *internal = (ao_sndio_internal *) device->internal; @@ -8,7 +19,7 @@ struct sio_par par; if(!internal->dev && internal->id>=0){ -@@ -107,21 +108,27 @@ int ao_plugin_open(ao_device *device, ao_sample_format +@@ -107,21 +111,27 @@ int ao_plugin_open(ao_device *device, ao_sample_format internal->dev = strdup(buf); } @@ -42,7 +53,7 @@ if(!device->inter_matrix){ /* set up matrix such that users are warned about > stereo playback */ -@@ -148,9 +155,10 @@ int ao_plugin_close(ao_device *device) +@@ -148,9 +158,10 @@ int ao_plugin_close(ao_device *device) ao_sndio_internal *internal = (ao_sndio_internal *) device->internal; struct sio_hdl *hdl = internal->hdl;