diff options
author | Jeff Muizelaar <jmuizelaar@mozilla.com> | 2009-05-21 18:02:22 -0400 |
---|---|---|
committer | Jeff Muizelaar <jmuizelaar@mozilla.com> | 2009-05-21 18:02:22 -0400 |
commit | 5ba7271cb6f4ddaf443bc7a9fecdd06720d77859 (patch) | |
tree | e229ad7e7c74f8b98cfdf20692869b5f0c791539 | |
parent | b58b34e40bccd4dfb2b6c66358323f3c7d4ae26c (diff) |
Fix a memory leak when fread() fails
Fixes a possible leak in qcms_profile_from_file() when fread()
can't read the entire profile.
-rw-r--r-- | iccread.c | 4 | ||||
-rw-r--r-- | invalid-coverage.c | 3 | ||||
-rw-r--r-- | sample-trunc.icc | bin | 0 -> 73 bytes |
3 files changed, 6 insertions, 1 deletions
@@ -765,8 +765,10 @@ qcms_profile* qcms_profile_from_file(FILE *file) /* read the rest profile */ read_length = fread((unsigned char*)data + sizeof(length_be), 1, remaining_length, file); - if (read_length != remaining_length) + if (read_length != remaining_length) { + free(data); return INVALID_PROFILE; + } profile = qcms_profile_from_memory(data, length); free(data); diff --git a/invalid-coverage.c b/invalid-coverage.c index 312515b..c402252 100644 --- a/invalid-coverage.c +++ b/invalid-coverage.c @@ -153,6 +153,9 @@ int main() write_u32(128 + 4 + 4*6*3 + 4, 1100); // offset qcms_profile_release(qcms_profile_from_memory(buf, 1500)); + /* test out profiles that are the wrong size */ + qcms_profile_from_path("sample-trunc.icc"); + return 0; } diff --git a/sample-trunc.icc b/sample-trunc.icc Binary files differnew file mode 100644 index 0000000..8a41f39 --- /dev/null +++ b/sample-trunc.icc |