diff options
author | Taylor Holberton <taylorcholberton@gmail.com> | 2016-10-01 21:38:34 -0400 |
---|---|---|
committer | Taylor Holberton <taylorcholberton@gmail.com> | 2016-10-01 21:38:34 -0400 |
commit | 2fdee65cf739c58b83b113e6ca179ff2fd6159d2 (patch) | |
tree | 5100701f5b34555c1378739d48df71992a2f814b | |
parent | 7c8b20a6fec65113df0e2874cfb55cde31c666aa (diff) |
checking results of fread() calls
-rw-r--r-- | utils/tinyplay.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/utils/tinyplay.c b/utils/tinyplay.c index 920b0e8..cca8223 100644 --- a/utils/tinyplay.c +++ b/utils/tinyplay.c @@ -154,7 +154,11 @@ int main(int argc, char **argv) } if ( !is_raw ) { - fread(&riff_wave_header, sizeof(riff_wave_header), 1, file); + if (fread(&riff_wave_header, sizeof(riff_wave_header), 1, file) != 1){ + fprintf(stderr, "Error: '%s' does not contain a riff/wave header\n", filename); + fclose(file); + return 1; + } if ((riff_wave_header.riff_id != ID_RIFF) || (riff_wave_header.wave_id != ID_WAVE)) { fprintf(stderr, "Error: '%s' is not a riff/wave file\n", filename); @@ -162,10 +166,18 @@ int main(int argc, char **argv) return 1; } do { - fread(&chunk_header, sizeof(chunk_header), 1, file); + if (fread(&chunk_header, sizeof(chunk_header), 1, file) != 1){ + fprintf(stderr, "Error: '%s' does not contain a data chunk\n", filename); + fclose(file); + return 1; + } switch (chunk_header.id) { case ID_FMT: - fread(&chunk_fmt, sizeof(chunk_fmt), 1, file); + if (fread(&chunk_fmt, sizeof(chunk_fmt), 1, file) != 1){ + fprintf(stderr, "Error: '%s' has incomplete format chunk\n", filename); + fclose(file); + return 1; + } /* If the format header is larger, skip the rest */ if (chunk_header.sz > sizeof(chunk_fmt)) fseek(file, chunk_header.sz - sizeof(chunk_fmt), SEEK_CUR); |