gecko-dev/modules/libmar/src
Matt Howell 22e7297afd Bug 1209551 - Don't read past the end of a buffer in libmar
The index section of a MAR archive file contains several fixed-length fields
and also variable-length names for each file in the archive, terminated by a
null byte. Since that makes the length of the index variable, the length of the
entire index is also provided in the file.
When libmar opens a file, it allocates a buffer with the length given in the
file and reads the index from the file into that buffer.
mar_consume_index() then parses the entire index from that copy,
trying to make sure it doesn't read past the buffer it was given.

The length of the buffer is given to mar_consume_index()
by providing it a pointer to one byte past the end of the buffer.
However, mar_consume_index() treats this pointer as pointing *to* the end.
Therefore, it is possible for a malformed MAR file (one where the stated length
is less than the real length) to trigger a read of one byte beyond the
allocated memory.

Fix this by failing the parse when we reach the buffer end pointer minus one,
instead of when we reach that address itself.

--HG--
extra : amend_source : 3001a5bc08e790251759418e014bbd7153b66d8a
2015-10-06 09:11:43 -07:00
..
Makefile.in Bug 970745 - Move USE_STATIC_LIBS to moz.build; r=glandium 2014-02-11 09:12:33 -05:00
mar.h Bug 903135 - Updates to libmar needed to support B2G MAR signature verification. r=bbondy 2014-10-22 21:00:15 -04:00
mar_cmdline.h Bug 903135 - Updates to libmar needed to support B2G MAR signature verification. r=bbondy 2014-10-22 21:00:15 -04:00
mar_create.c Bug 1021142 - 'fclose()' at 2 places to avoid leaks on failure. r=bbondy 2014-08-28 11:35:50 -07:00
mar_extract.c Bug 904768 - Print filename when failing to open files in libmar; r=netzen 2013-08-13 15:18:03 -04:00
mar_private.h Bug 872127 - Part 2: Replace mozilla/StandardInteger.h with stdint.h; r=Waldo,ted 2013-07-30 10:25:31 -04:00
mar_read.c Bug 1209551 - Don't read past the end of a buffer in libmar 2015-10-06 09:11:43 -07:00
moz.build Bug 1202971 (part 1) - Fix compile warnings in libmar. r=rstrong. 2015-09-15 17:39:11 -07:00