Android-x86
Fork
Donation

  • R/O
  • HTTP
  • SSH
  • HTTPS

external-alsa-utils: Commit

external/alsa-utils


Commit MetaInfo

Revisión819e04c7a1958a1c4378d914b38bddaf248d9fc0 (tree)
Tiempo2019-03-13 22:42:42
AutorJaroslav Kysela <perex@pere...>
CommiterJaroslav Kysela

Log Message

axfer: coverity fixes

- container-voc.c - out of array access
- container-voc.c - handle correctly eof
- frame_cache.c - correct memory allocation
- container.c - byte_count might be used uninitialized
- xfer-libasound-irq-mmap.c - fix avail signess
- xfer-options.c - fix potential 32-bit wrap for duration

Signed-off-by: Jaroslav Kysela <perex@perex.cz>

Cambiar Resumen

Diferencia incremental

--- a/axfer/container-voc.c
+++ b/axfer/container-voc.c
@@ -234,7 +234,7 @@ static int build_time_constant(unsigned int frames_per_second,
234234 frames_per_second)
235235 break;
236236 }
237- if (i < ARRAY_SIZE(ex_v110_time_consts) ||
237+ if (i < ARRAY_SIZE(ex_v110_time_consts) &&
238238 frames_per_second <= 192000) {
239239 *code = ex_v110_time_consts[i].code;
240240 } else {
@@ -520,29 +520,31 @@ static int detect_format_block(struct container_context *cntr)
520520 {
521521 struct parser_state *state = cntr->private_data;
522522 struct block_header header;
523- void *buf = NULL;
523+ void *buf;
524524 int err;
525525
526526 again:
527+ buf = NULL;
527528 err = cache_data_block(cntr, &header, &buf);
528529 if (err < 0)
529530 return err;
531+ if (buf) {
532+ if (header.type == BLOCK_TYPE_EXTENDED_V110_FORMAT) {
533+ err = parse_extended_v110_format(state, buf);
534+ } else if (header.type == BLOCK_TYPE_V120_DATA) {
535+ err = parse_v120_format_block(state, buf);
536+ } else if (header.type == BLOCK_TYPE_V110_DATA) {
537+ err = parse_v110_data(state, buf);
538+ } else {
539+ free(buf);
540+ goto again;
541+ }
530542
531- if (header.type == BLOCK_TYPE_EXTENDED_V110_FORMAT) {
532- err = parse_extended_v110_format(state, buf);
533- } else if (header.type == BLOCK_TYPE_V120_DATA) {
534- err = parse_v120_format_block(state, buf);
535- } else if (header.type == BLOCK_TYPE_V110_DATA) {
536- err = parse_v110_data(state, buf);
537- } else {
538543 free(buf);
539- goto again;
540- }
541-
542- free(buf);
543544
544- if (err < 0)
545- return err;
545+ if (err < 0)
546+ return err;
547+ }
546548
547549 // Expect to detect block_v110_data.
548550 if (header.type == BLOCK_TYPE_EXTENDED_V110_FORMAT)
--- a/axfer/container.c
+++ b/axfer/container.c
@@ -296,7 +296,7 @@ int container_context_pre_process(struct container_context *cntr,
296296 unsigned int *frames_per_second,
297297 uint64_t *frame_count)
298298 {
299- uint64_t byte_count;
299+ uint64_t byte_count = 0;
300300 unsigned int bytes_per_frame;
301301 int err;
302302
--- a/axfer/frame-cache.c
+++ b/axfer/frame-cache.c
@@ -50,13 +50,18 @@ int frame_cache_init(struct frame_cache *cache, snd_pcm_access_t access,
5050 unsigned int samples_per_frame,
5151 unsigned int frames_per_cache)
5252 {
53+ cache->access = access;
54+ cache->remained_count = 0;
55+ cache->bytes_per_sample = bytes_per_sample;
56+ cache->samples_per_frame = samples_per_frame;
57+ cache->frames_per_cache = frames_per_cache;
58+
5359 if (access == SND_PCM_ACCESS_RW_INTERLEAVED)
5460 cache->align_frames = align_frames_in_i;
5561 else if (access == SND_PCM_ACCESS_RW_NONINTERLEAVED)
5662 cache->align_frames = align_frames_in_n;
5763 else
5864 return -EINVAL;
59- cache->access = access;
6065
6166 if (access == SND_PCM_ACCESS_RW_INTERLEAVED) {
6267 char *buf;
@@ -64,45 +69,42 @@ int frame_cache_init(struct frame_cache *cache, snd_pcm_access_t access,
6469 buf = calloc(frames_per_cache,
6570 bytes_per_sample * samples_per_frame);
6671 if (buf == NULL)
67- return -ENOMEM;
72+ goto nomem;
6873 cache->buf = buf;
6974 cache->buf_ptr = buf;
7075 } else {
71- char **bufs;
72- char **buf_ptrs;
76+ char **bufs = calloc(samples_per_frame, sizeof(*bufs));
77+ char **buf_ptrs = calloc(samples_per_frame, sizeof(*buf_ptrs));
7378 int i;
7479
75- bufs = calloc(samples_per_frame, sizeof(*bufs));
76- if (bufs == NULL)
77- return -ENOMEM;
78- buf_ptrs = calloc(samples_per_frame, sizeof(*buf_ptrs));
79- if (buf_ptrs == NULL)
80- return -ENOMEM;
80+ cache->buf = bufs;
81+ cache->buf_ptr = buf_ptrs;
82+ if (bufs == NULL || buf_ptrs == NULL)
83+ goto nomem;
8184 for (i = 0; i < samples_per_frame; ++i) {
8285 bufs[i] = calloc(frames_per_cache, bytes_per_sample);
8386 if (bufs[i] == NULL)
84- return -ENOMEM;
87+ goto nomem;
8588 buf_ptrs[i] = bufs[i];
8689 }
87- cache->buf = bufs;
88- cache->buf_ptr = buf_ptrs;
8990 }
9091
91- cache->remained_count = 0;
92- cache->bytes_per_sample = bytes_per_sample;
93- cache->samples_per_frame = samples_per_frame;
94- cache->frames_per_cache = frames_per_cache;
9592
9693 return 0;
94+
95+nomem:
96+ frame_cache_destroy(cache);
97+ return -ENOMEM;
9798 }
9899
99100 void frame_cache_destroy(struct frame_cache *cache)
100101 {
101102 if (cache->access == SND_PCM_ACCESS_RW_NONINTERLEAVED) {
102- int i;
103- for (i = 0; i < cache->samples_per_frame; ++i) {
104- char **bufs = cache->buf;
105- free(bufs[i]);
103+ char **bufs = cache->buf;
104+ if (bufs) {
105+ int i;
106+ for (i = 0; i < cache->samples_per_frame; ++i)
107+ free(bufs[i]);
106108 }
107109 free(cache->buf_ptr);
108110 }
--- a/axfer/xfer-libasound-irq-mmap.c
+++ b/axfer/xfer-libasound-irq-mmap.c
@@ -75,7 +75,7 @@ static int irq_mmap_process_frames(struct libasound_state *state,
7575 struct map_layout *layout = state->private_data;
7676 const snd_pcm_channel_area_t *areas;
7777 snd_pcm_uframes_t frame_offset;
78- snd_pcm_uframes_t avail;
78+ snd_pcm_sframes_t avail;
7979 unsigned int avail_count;
8080 void *frame_buf;
8181 snd_pcm_sframes_t consumed_count;
--- a/axfer/xfer-options.c
+++ b/axfer/xfer-options.c
@@ -395,7 +395,7 @@ void xfer_options_calculate_duration(struct xfer_context *xfer,
395395 uint64_t frame_count;
396396
397397 if (xfer->duration_seconds > 0) {
398- frame_count = xfer->duration_seconds * xfer->frames_per_second;
398+ frame_count = (uint64_t)xfer->duration_seconds * (uint64_t)xfer->frames_per_second;
399399 if (frame_count < *total_frame_count)
400400 *total_frame_count = frame_count;
401401 }
Show on old repository browser