three more patches for nano-5.4 in Debian stable

Benno Schulenberg <[email protected]>
Newsgroups gmane.editors.nano.devel
Message-ID <[email protected]>
Hello Jordi,

Attached three patches fix some relatively serious bugs in nano-5.4
as present in Debian bullseye.  Patch 0036 and 0037 fix unlikely but
possible crashes.  And patch 0038 fixes a character-eating bug when
two options are combined.  Not many people use --breaklonglines, but
the ones that do, and have --autoindent on too, will not like it that
nano can eat a bit of text when the cursor is in a certain position
when Enter is pressed.  Please consider applying these patches.

(You could apply the last patch also to 7.0, but nano-7.1 will be out
in about two weeks.)

Regards,

Benno
0036-input-ensure-that-no-more-bytes-are-consumed-than-ar.patch (text/x-patch, 1012 B)
From af63d94017a26cbf3446219de5ced30e677e0f13 Mon Sep 17 00:00:00 2001
From: Benno Schulenberg <[email protected]>
Date: Sun, 12 Dec 2021 15:43:15 +0100
Subject: [PATCH 36/38] input: ensure that no more bytes are consumed than are
 available

The value of 'consumed' may not exceed the given 'length'.

Bug existed since version 2.9.3, commit e739448c.

(Bug was found by studying Fedora crash reports.  Thank you, Fedora!)
---
 src/winio.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/winio.c b/src/winio.c
index 1116c172..e12d6e6b 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -466,8 +466,9 @@ int convert_SS3_sequence(const int *seq, size_t length, int *consumed)
 /* Translate a sequence that began with "Esc [" to its corresponding key code. */
 int convert_CSI_sequence(const int *seq, size_t length, int *consumed)
 {
-	if (seq[0] < '9')
+	if (seq[0] < '9' && length > 1)
 		*consumed = 2;
+
 	switch (seq[0]) {
 		case '1':
 			if (length > 1 && seq[1] == '~')
-- 
2.37.4
0037-execute-don-t-crash-when-an-empty-buffer-is-piped-th.patch (text/x-patch, 919 B)
From 35b67b15652102203161beb31db786f09981de81 Mon Sep 17 00:00:00 2001
From: Benno Schulenberg <[email protected]>
Date: Thu, 24 Feb 2022 11:57:56 +0100
Subject: [PATCH 37/38] execute: don't crash when an empty buffer is piped
 through a command

That is, take into account that the cutbuffer could be NULL
(when updating the undo item).

This fixes https://savannah.gnu.org/bugs/?62107.

Bug existed since version 4.9, commit b15c5a7e.
---
 src/text.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/text.c b/src/text.c
index 5ff5745d..c88ca516 100644
--- a/src/text.c
+++ b/src/text.c
@@ -1200,7 +1200,8 @@ void update_undo(undo_type action)
 		else if (cutbuffer != NULL) {
 			free_lines(u->cutbuffer);
 			u->cutbuffer = copy_buffer(cutbuffer);
-		}
+		} else
+			break;
 		if (!(u->xflags & MARK_WAS_SET)) {
 			linestruct *bottomline = u->cutbuffer;
 			size_t count = 0;
-- 
2.37.4
0038-text-upon-Enter-eat-only-lefthand-blanks-not-any-oth.patch (text/x-patch, 1.2 KB)
From 7338d67935876a05cc3743102821c12574c17435 Mon Sep 17 00:00:00 2001
From: Benno Schulenberg <[email protected]>
Date: Thu, 24 Nov 2022 15:51:43 +0100
Subject: [PATCH 38/38] text: upon Enter, eat only lefthand blanks, not any
 other characters

Make sure that there is only whitespace to the left of the cursor
before setting 'allblanks' to TRUE, because this latter value will
cause these characters to be eaten (as a special case, to avoid
creating lines that contain only blanks when both --autoindent
and --breaklonglines are on).

This fixes https://savannah.gnu.org/bugs/?63407.
Reported-by: Tasos Papastylianou <[email protected]>

Bug existed since version 2.9.8, commit d00ab406.
---
 src/text.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/text.c b/src/text.c
index c88ca516..9c6043e9 100644
--- a/src/text.c
+++ b/src/text.c
@@ -878,7 +878,7 @@ void do_enter(void)
 		if (extra > openfile->current_x)
 			extra = openfile->current_x;
 		else if (extra == openfile->current_x)
-			allblanks = TRUE;
+			allblanks = (indent_length(openfile->current->data) == extra);
 	}
 #endif /* NANO_TINY */
 	newnode->data = nmalloc(strlen(openfile->current->data +
-- 
2.37.4
OpenPGP_signature (application/pgp-signature, 840 B) - not displayed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.