opnsense-src/usr.bin/bsdiff/bsdiff
Mitchell Horne a521f21164 bsdiff: fix off-by-one error
The program reads oldsize bytes from oldfile, and proceeds to initialize
a suffix array of oldsize elements using divsufsort(). As per the
function's API [1], array indices 0 through n-1 are initialized.

Later, search() is called, but with index bounds [0, n]. Depending on
the contents of the malloc'd buffer, accessing this uninitialized index
at the end of can result in a segmentation fault. Fix this by passing
oldsize-1 to search(), limiting the search bounds to [0, n-1].

This bug is a result of r303285, which introduced divsufsort() as an
alternate suffix sorting function to the existing qsufsort(). It seems
that qsufsort() did initialize the final empty element, meaning it could
be safely accessed. This difference in the implementations was missed at
the time.

[1] https://github.com/y-256/libdivsufsort

Discussed with:	cperciva
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D26911
2020-11-16 18:41:49 +00:00
..
bsdiff.1 use .Mt to mark up email addresses consistently (part3) 2014-06-23 08:23:05 +00:00
bsdiff.c bsdiff: fix off-by-one error 2020-11-16 18:41:49 +00:00
config.h Change bsdiff to use divsufsort suffix sort library instead of qsufsort, 2016-07-25 03:58:19 +00:00
divsufsort64.h Change bsdiff to use divsufsort suffix sort library instead of qsufsort, 2016-07-25 03:58:19 +00:00
Makefile Adopt SRCTOP in usr.bin 2017-03-12 18:58:44 +00:00
Makefile.depend DIRDEPS_BUILD: Update dependencies. 2017-10-31 00:07:04 +00:00