Fix MSAN errors

Fix multiple errors uncovered by Clang's Memory Sanitizer.

Closes: https://github.com/erikd/libsndfile/issues/248
This commit is contained in:
Erik de Castro Lopo 2017-05-04 05:59:31 +10:00
parent 6830c42189
commit b506de463d
10 changed files with 27 additions and 11 deletions

View File

@ -73,6 +73,10 @@ psf_bump_header_allocation (SF_PRIVATE * psf, sf_count_t needed)
return 1 ;
} ;
/* Always zero-out new header memory to avoid un-initializer memory accesses. */
if (newlen > psf->header.len)
memset ((char *) ptr + psf->header.len, 0, newlen - psf->header.len) ;
psf->header.ptr = ptr ;
psf->header.len = newlen ;
return 0 ;

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 1999-2015 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 1999-2017 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published by
@ -527,7 +527,7 @@ host_read_f2s (SF_PRIVATE *psf, short *ptr, sf_count_t len)
/* Fix me : Need lef2s_array */
if (psf->data_endswap == SF_TRUE)
endswap_int_array (ubuf.ibuf, bufferlen) ;
endswap_int_array (ubuf.ibuf, readcount) ;
convert (ubuf.fbuf, readcount, ptr + total, scale) ;
total += readcount ;

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2005-2012 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 2005-2017 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** All rights reserved.
**

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2008-2015 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 2008-2017 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
@ -87,6 +87,7 @@ checksum_test (const CHECKSUM * cksum)
print_test_name (__func__, cksum->enc_name) ;
memset (&info, 0, sizeof (info)) ;
info.format = cksum->enc_fmt ;
info.channels = 1 ;
info.samplerate = SAMPLE_RATE ;

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2001-2016 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 2001-2017 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
@ -1053,6 +1053,7 @@ broadcast_test (const char *filename, int filetype)
print_test_name ("broadcast_test", filename) ;
memset (&sfinfo, 0, sizeof (sfinfo)) ;
sfinfo.samplerate = 11025 ;
sfinfo.format = filetype ;
sfinfo.channels = 1 ;
@ -1415,6 +1416,7 @@ cart_test (const char *filename, int filetype)
print_test_name ("cart_test", filename) ;
memset (&sfinfo, 0, sizeof (sfinfo)) ;
sfinfo.samplerate = 11025 ;
sfinfo.format = filetype ;
sfinfo.channels = 1 ;

View File

@ -1,6 +1,6 @@
[+ AutoGen5 template c +]
/*
** Copyright (C) 1999-2016 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 1999-2017 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
@ -207,6 +207,7 @@ float_scaled_test (const char *filename, int allow_exit, int replace_float, int
gen_windowed_sine_float (float_data, DFT_DATA_LENGTH, 0.9999) ;
memset (&sfinfo, 0, sizeof (sfinfo)) ;
sfinfo.samplerate = SAMPLE_RATE ;
sfinfo.frames = DFT_DATA_LENGTH ;
sfinfo.channels = 1 ;
@ -259,6 +260,7 @@ double_scaled_test (const char *filename, int allow_exit, int replace_float, int
gen_windowed_sine_double (double_data, DFT_DATA_LENGTH, 0.9999) ;
memset (&sfinfo, 0, sizeof (sfinfo)) ;
sfinfo.samplerate = SAMPLE_RATE ;
sfinfo.frames = DFT_DATA_LENGTH ;
sfinfo.channels = 1 ;
@ -316,6 +318,7 @@ static void
gen_windowed_sine_[+ (get "float_name") +] ([+ (get "float_name") +]_data, ARRAY_LEN ([+ (get "float_name") +]_data), 0.9999) ;
memset (&sfinfo, 0, sizeof (sfinfo)) ;
sfinfo.samplerate = SAMPLE_RATE ;
sfinfo.frames = ARRAY_LEN ([+ (get "int_name") +]_data) ;
sfinfo.channels = 1 ;

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2011 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 2011-2017 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
@ -102,6 +102,7 @@ format_combo_test (void)
char filename [128] ;
int subtype_is_valid, check_is_valid ;
memset (&info, 0, sizeof (info)) ;
memset (&subtype_fmt_info, 0, sizeof (subtype_fmt_info)) ;
subtype_fmt_info.format = codec ;
subtype_is_valid = sf_command (NULL, SFC_GET_FORMAT_SUBTYPE, &subtype_fmt_info, sizeof (subtype_fmt_info)) == 0 ;

View File

@ -1,6 +1,6 @@
[+ AutoGen5 template c +]
/*
** Copyright (C) 2001-2012 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 2001-2017 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** This program is free software ; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
@ -247,10 +247,10 @@ update_header_sub (const char *filename, int typemajor, int write_mode)
SF_INFO sfinfo ;
int k ;
memset (&sfinfo, 0, sizeof (sfinfo)) ;
sfinfo.samplerate = 44100 ;
sfinfo.format = (typemajor | SF_FORMAT_PCM_16) ;
sfinfo.channels = 1 ;
sfinfo.frames = 0 ;
outfile = test_open_file_or_die (filename, write_mode, &sfinfo, SF_TRUE, __LINE__) ;
@ -340,6 +340,7 @@ update_seek_[+ (get "name") +]_test (const char *filename, int filetype)
memset (buffer, 0, sizeof (buffer)) ;
/* Create sound outfile with no data. */
memset (&sfinfo, 0, sizeof (sfinfo)) ;
sfinfo.format = filetype | [+ (get "format") +] ;
sfinfo.samplerate = 48000 ;
sfinfo.channels = 2 ;
@ -450,6 +451,7 @@ extra_header_test (const char *filename, int filetype)
print_test_name ("extra_header_test", filename) ;
memset (&sfinfo, 0, sizeof (sfinfo)) ;
sfinfo.samplerate = 44100 ;
sfinfo.format = (filetype | SF_FORMAT_PCM_16) ;
sfinfo.channels = 1 ;

View File

@ -1,6 +1,6 @@
[+ AutoGen5 template c +]
/*
** Copyright (C) 2001-2012 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 2001-2017 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
@ -129,6 +129,7 @@ pipe_read_test (int filetype, const char *ext)
snprintf (filename, sizeof (filename), "pipe_in.%s", ext) ;
print_test_name ("pipe_read_test", filename) ;
memset (&sfinfo, 0, sizeof (sfinfo)) ;
sfinfo.format = filetype | SF_FORMAT_PCM_16 ;
sfinfo.channels = 1 ;
sfinfo.samplerate = 44100 ;
@ -331,6 +332,7 @@ pipe_test_others (FILETYPE* list1, FILETYPE* list2)
SF_INFO sfinfo ;
int retval ;
memset (&sfinfo, 0, sizeof (sfinfo)) ;
sfinfo.format = info.format | SF_FORMAT_PCM_16 ;
sfinfo.channels = 1 ;
sfinfo.samplerate = 44100 ;

View File

@ -1,6 +1,6 @@
[+ AutoGen5 template h c +]
/*
** Copyright (C) 2002-2016 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 2002-2017 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
@ -239,6 +239,7 @@ create_short_sndfile (const char *filename, int format, int channels)
SNDFILE *file ;
SF_INFO sfinfo ;
memset (&sfinfo, 0, sizeof (sfinfo)) ;
sfinfo.samplerate = 44100 ;
sfinfo.channels = channels ;
sfinfo.format = format ;