terminal: fix condition in zero-character handling

The condition must first check the io-buffer length and then check the
content. Otherwise, cat'ting a file that is padded with zeros up to
page size (io-buffer size) yields an out-of-range read access.
This commit is contained in:
Norman Feske 2018-04-16 15:04:07 +02:00 committed by Christian Helmuth
parent 1f1302e185
commit 13419755f9

View File

@ -104,13 +104,18 @@ class Terminal::Session_component : public Rpc_object<Session, Session_component
unsigned i = 0; unsigned i = 0;
for (Utf8_ptr utf8(src); utf8.complete() && i < max; ) { for (Utf8_ptr utf8(src); utf8.complete() && i < max; ) {
_character_consumer.consume_character(utf8.codepoint().value); _character_consumer.consume_character(utf8.codepoint().value);
i += utf8.length(); i += utf8.length();
if (i >= max)
break;
utf8 = Utf8_ptr(src + i); utf8 = Utf8_ptr(src + i);
} }
/* consume trailing zero characters */ /* consume trailing zero characters */
for (; src[i] == 0 && i < num_bytes; i++); for (; i < max && src[i] == 0; i++);
/* we don't support UTF-8 sequences split into multiple writes */ /* we don't support UTF-8 sequences split into multiple writes */
if (i != num_bytes) { if (i != num_bytes) {