From 1df9314337736a5d7b9b594d2791a62393a0d28c Mon Sep 17 00:00:00 2001 From: Peter Avalos Date: Sun, 25 Nov 2007 15:10:30 +0000 Subject: [PATCH] Import less-416: Fix crash when searching text with invalid UTF-8 sequences. --- contrib/less-4/NEWS | 2 +- contrib/less-4/less.nro | 21 ++++++++++++--------- contrib/less-4/lessecho.nro | 2 +- contrib/less-4/lesskey.nro | 2 +- contrib/less-4/search.c | 13 ++++++++----- contrib/less-4/version.c | 3 ++- 6 files changed, 25 insertions(+), 18 deletions(-) diff --git a/contrib/less-4/NEWS b/contrib/less-4/NEWS index 3d6b0983c2..e6cec6969b 100644 --- a/contrib/less-4/NEWS +++ b/contrib/less-4/NEWS @@ -13,7 +13,7 @@ ====================================================================== - Major changes between "less" versions 409 and 415 + Major changes between "less" versions 409 and 416 * New --follow-name option makes F command follow the name of a file rather than the file descriptor if an open file is renamed. diff --git a/contrib/less-4/less.nro b/contrib/less-4/less.nro index d2261811c4..d5dfb05349 100644 --- a/contrib/less-4/less.nro +++ b/contrib/less-4/less.nro @@ -1,4 +1,4 @@ -.TH LESS 1 "Version 415: 15 Nov 2007" +.TH LESS 1 "Version 416: 22 Nov 2007" .SH NAME less \- opposite of more .SH SYNOPSIS @@ -462,7 +462,7 @@ By default 64K of buffer space is used for each file The \-b option specifies instead that \fIn\fP kilobytes of buffer space should be used for each file. If \fIn\fP is \-1, buffer space is unlimited; that is, -the entire file is read into memory. +the entire file can be read into memory. .IP "\-B or \-\-auto-buffers" By default, when data is read from a pipe, buffers are allocated automatically as needed. @@ -473,7 +473,7 @@ so that only 64K (or the amount of space specified by the \-b option) is used for the pipe. Warning: use of \-B can result in erroneous display, since only the -most recently viewed part of the file is kept in memory; +most recently viewed part of the piped data is kept in memory; any earlier data is lost. .IP "\-c or \-\-clear-screen" Causes full screen repaints to be painted from the top line down. @@ -555,9 +555,9 @@ the pattern contains uppercase letters. .IP "\-j\fIn\fP or \-\-jump-target=\fIn\fP" Specifies a line on the screen where the "target" line is to be positioned. -A target line is the object of a text search, -tag search, jump to a line number, -jump to a file percentage, or jump to a marked position. +The target line is the line specified by any command to +search for a pattern, jump to a line number, +jump to a file percentage or jump to a tag. The screen line may be specified by a number: the top line on the screen is 1, the next is 2, and so on. The number may be negative to specify a line relative to the bottom @@ -569,10 +569,11 @@ screen, .3 is three tenths down from the first line, and so on. If the line is specified as a fraction, the actual line number is recalculated if the terminal window is resized, so that the target line remains at the specified fraction of the screen height. -If the \-j option is used, searches begin at the line immediately -after the target line. +If any form of the \-j option is used, +forward searches begin at the line immediately after the target line, +and backward searches begin at the target line. For example, if "\-j4" is used, the target line is the -fourth line on the screen, so searches begin at the fifth line +fourth line on the screen, so forward searches begin at the fifth line on the screen. .IP "\-J or \-\-status-column" Displays a status column at the left edge of the screen. @@ -597,6 +598,8 @@ to exit immediately when an interrupt character (usually ^C) is typed. Normally, an interrupt character causes .I less to stop whatever it is doing and return to its command prompt. +Note that use of this option makes it impossible to return to the +command prompt from the "F" command. .IP "\-L or \-\-no-lessopen" Ignore the LESSOPEN environment variable (see the INPUT PREPROCESSOR section below). diff --git a/contrib/less-4/lessecho.nro b/contrib/less-4/lessecho.nro index d31b83d054..05542f79f4 100644 --- a/contrib/less-4/lessecho.nro +++ b/contrib/less-4/lessecho.nro @@ -1,4 +1,4 @@ -.TH LESSECHO 1 "Version 415: 15 Nov 2007" +.TH LESSECHO 1 "Version 416: 22 Nov 2007" .SH NAME lessecho \- expand metacharacters .SH SYNOPSIS diff --git a/contrib/less-4/lesskey.nro b/contrib/less-4/lesskey.nro index a757bab7ef..47033212b7 100644 --- a/contrib/less-4/lesskey.nro +++ b/contrib/less-4/lesskey.nro @@ -1,4 +1,4 @@ -.TH LESSKEY 1 "Version 415: 15 Nov 2007" +.TH LESSKEY 1 "Version 416: 22 Nov 2007" .SH NAME lesskey \- specify key bindings for less .SH SYNOPSIS diff --git a/contrib/less-4/search.c b/contrib/less-4/search.c index b983334c7d..3a15380842 100755 --- a/contrib/less-4/search.c +++ b/contrib/less-4/search.c @@ -118,13 +118,16 @@ cvt_length(len, ops) int len; int ops; { - if (utf_mode && (ops & CVT_TO_LC)) + if (utf_mode) /* - * Converting case can cause a UTF-8 string to increase in length. - * Multiplying by 3 is the worst case. + * Just copying a string in UTF-8 mode can cause it to grow + * in length. + * Six output bytes for one input byte is the worst case + * (and unfortunately is far more than is needed in any + * non-pathological situation, so this is very wasteful). */ - len *= 3; - return len+1; + len *= 6; + return len + 1; } /* diff --git a/contrib/less-4/version.c b/contrib/less-4/version.c index 578dc55e07..bce2f82c07 100755 --- a/contrib/less-4/version.c +++ b/contrib/less-4/version.c @@ -701,6 +701,7 @@ v412 11/6/07 Use symbolic SEEK constants. v413 11/6/07 Fix search highlight bug with non-ASCII text. v414 11/6/07 Fix display bug with no-wrap terminals. v415 11/14/07 Add --follow-name option. +v416 11/22/07 Fix crash when searching text with invalid UTF-8 sequences. */ -char version[] = "415"; +char version[] = "416"; -- 2.41.0