Tobias Stoeckmann acabfdb582 sed: handle very long input lines with R (tiny change)
It is possible to trigger an out of bounds memory access when
using the sed command R with an input file containing very long
lines.

The problem is that the line length of parsed file is returned as
a size_t by ck_getdelim, but temporarily stored in an int and
then converted back into a size_t. On systems like amd64, on which
this problem can be triggered, size_t and int have different sizes.

If the input line is longer than 2 GB (which is parseable on amd64
or other 64 bit systems), this means that the temporarily stored
int turns negative. Converting the negative int back into a size_t
will lead to an excessively large size_t, as the conversion leads to
a lot of leading 1 bits.

Eventually ck_fwrite is called with this huge size_t which in turn
will lead to an out of bounds access on amd64 systems -- after all
the parsed text was just a bit above 2 GB, not near SIZE_MAX.

You can trigger this issue with GNU sed on OpenBSD like this:

$ dd if=/dev/zero bs=1M count=2049 | tr '\0' e > long.txt
$ sed Rlong.txt /etc/fstab
Segmentation fault (core dumped)

I was unable to trigger the bug on a Linux system with glibc due to
a bug in glibc's fwrite implementation -- it leads to a short write
and sed treats that correctly as an error.

* sed/execute.c (execute_program) [case 'R']: Declare result
to be of type size_t, not int.
* NEWS (Bug fixes): Mention it.
This addresses https://bugs.gnu.org/39166
2020-01-18 08:25:10 -08:00
2014-11-30 18:59:33 -08:00
2020-01-09 22:56:39 -08:00
2008-04-10 11:14:38 +02:00
2016-08-26 11:54:30 -04:00
2016-08-22 20:57:02 -04:00
2020-01-09 22:56:39 -08:00
2015-05-01 18:09:51 -07:00
2020-01-14 20:10:42 -08:00
2015-05-01 18:09:51 -07:00

This is the GNU implementation of sed, the Unix stream editor.

GNU Sed website: https://www.gnu.org/software/sed/

See the NEWS file for a brief summary and the ChangeLog for
more detailed descriptions of changes.

If you obtained this file as part of a "git clone", then see the
README-hacking file.  If this file came to you as part of a tar archive,
then see the file INSTALL for compilation and installation instructions.

See the file BUGS for instructions about reporting bugs.

See the files AUTHORS and THANKS for a list of authors and other contributors.

After installation run 'sed --help' or 'man sed' for short usage information,
and 'info sed' for the complete manual. The manual is also available on
sed's website.
S
Description
SED (stream editor) - неинтерактивный текстовый редактор командной строки
https://www.gnu.org/software/sed/
Readme GPL-3.0
3 MiB
0 Stars 1 Watchers 0 Forks
Languages
Shell 43%
C 26.4%
Perl 16.5%
sed 7.3%
Makefile 5.2%
Other 1.6%