less: fix SEGV
authorDenys Vlasenko <vda.linux@googlemail.com>
Tue, 16 Aug 2016 13:09:40 +0000 (15:09 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Tue, 16 Aug 2016 13:09:40 +0000 (15:09 +0200)
testcase: echo "" | less, then press ')' key

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
miscutils/less.c

index d7076dbbc78b66d284abc2fdffdc3d1306318d23..10e1d8e1602d8ae0cd160b61ea7d95723b5dd23e 100644 (file)
@@ -1591,7 +1591,9 @@ static void match_right_bracket(char bracket)
 {
        unsigned i;
 
-       if (strchr(flines[cur_fline], bracket) == NULL) {
+       if (cur_fline >= max_fline
+        || strchr(flines[cur_fline], bracket) == NULL
+       ) {
                print_statusline("No bracket in top line");
                return;
        }
@@ -1609,7 +1611,9 @@ static void match_left_bracket(char bracket)
 {
        int i;
 
-       if (strchr(flines[cur_fline + max_displayed_line], bracket) == NULL) {
+       if (cur_fline + max_displayed_line >= max_fline
+        || strchr(flines[cur_fline + max_displayed_line], bracket) == NULL
+       ) {
                print_statusline("No bracket in bottom line");
                return;
        }