<table><tr><td style="">mglb created this revision.<br />mglb added a reviewer: Konsole.<br />mglb added a project: Konsole.<br />mglb requested review of this revision.
</td><a style="text-decoration: none; padding: 4px 8px; margin: 0 8px 8px; float: right; color: #464C5C; font-weight: bold; border-radius: 3px; background-color: #F7F7F9; background-image: linear-gradient(to bottom,#fff,#f1f0f1); display: inline-block; border: 1px solid rgba(71,87,120,.2);" href="https://phabricator.kde.org/D14106">View Revision</a></tr></table><br /><div><strong>REVISION SUMMARY</strong><div><p>When there was at least one search attempt, search box is still opened,<br />
and the screen and/or history is cleared, there is a high chance that<br />
the line number remembered by the search is invalid. The line number is<br />
used as the lines array index, so this can lead to overflow and crash.</p>
<p>This is at this moment fixed with a check in <tt style="background: #ebebeb; font-size: 13px;">copyLineToStream()</tt>, which<br />
is a generic function that happens to be used by search function and<br />
where the line number is used. There still is an <tt style="background: #ebebeb; font-size: 13px;">assert</tt> which is<br />
triggered in debug builds.</p>
<p>The patch moves the check directly to a search function, where the line<br />
number is initialized before first search.</p></div></div><br /><div><strong>TEST PLAN</strong><div><p>You have to do the test in debug build - there is a hack in<br />
<tt style="background: #ebebeb; font-size: 13px;">copyLineToStream()</tt> which prevents crash, but <tt style="background: #ebebeb; font-size: 13px;">assert</tt> before it<br />
catches an error condition.</p>
<ul class="remarkup-list">
<li class="remarkup-list-item">Run <tt style="background: #ebebeb; font-size: 13px;">seq 5000</tt></li>
<li class="remarkup-list-item">Open search box, search for <tt style="background: #ebebeb; font-size: 13px;">000</tt></li>
<li class="remarkup-list-item">Clear screen/history</li>
<li class="remarkup-list-item">Search up/down</li>
</ul>
<p>Actual result: Crash<br />
Expected result: Search should begin from last/first visible line</p></div></div><br /><div><strong>REPOSITORY</strong><div><div>R319 Konsole</div></div></div><br /><div><strong>BRANCH</strong><div><div>arc/move-search-line-upper-bound-check-to-less-generic-function (branched from master)</div></div></div><br /><div><strong>REVISION DETAIL</strong><div><a href="https://phabricator.kde.org/D14106">https://phabricator.kde.org/D14106</a></div></div><br /><div><strong>AFFECTED FILES</strong><div><div>src/Screen.cpp<br />
src/SessionController.cpp</div></div></div><br /><div><strong>To: </strong>mglb, Konsole<br /><strong>Cc: </strong>konsole-devel, herrold, ngraham, maximilianocuria, hindenburg<br /></div>