Skip to content

Commit 590ec87

Browse files
committed
patch 8.0.1556: may not parse the t_RS response correctly
Problem: May not parse the t_RS response correctly, resulting in wrong characters in the input stream. Solution: When the t_RS response is partly received wait for more characters.
1 parent 77780b6 commit 590ec87

File tree

2 files changed

+37
-24
lines changed

2 files changed

+37
-24
lines changed

src/term.c

+35-24
Original file line numberDiff line numberDiff line change
@@ -4866,7 +4866,7 @@ check_termcode(
48664866
* {tail} can be Esc>\ or STERM
48674867
*
48684868
* Check for cursor shape response from xterm:
4869-
* {lead}1$r<number> q{tail}
4869+
* {lead}1$r<digit> q{tail}
48704870
*
48714871
* {lead} can be <Esc>P or DCS
48724872
* {tail} can be Esc>\ or STERM
@@ -4897,35 +4897,46 @@ check_termcode(
48974897
break;
48984898
}
48994899
}
4900-
else if ((len >= j + 6 && isdigit(argp[3]))
4901-
&& argp[4] == ' '
4902-
&& argp[5] == 'q')
4900+
else
49034901
{
4904-
/* cursor shape response */
4905-
i = j + 6;
4906-
if ((tp[i] == ESC && i + 1 < len && tp[i + 1] == '\\')
4907-
|| tp[i] == STERM)
4902+
/* Probably the cursor shape response. Make sure that "i"
4903+
* is equal to "len" when there are not sufficient
4904+
* characters. */
4905+
for (i = j + 3; i < len; ++i)
49084906
{
4909-
int number = argp[3] - '0';
4910-
4911-
/* 0, 1 = block blink, 2 = block
4912-
* 3 = underline blink, 4 = underline
4913-
* 5 = vertical bar blink, 6 = vertical bar */
4914-
number = number == 0 ? 1 : number;
4915-
initial_cursor_shape = (number + 1) / 2;
4916-
/* The blink flag is actually inverted, compared to
4917-
* the value set with T_SH. */
4918-
initial_cursor_shape_blink =
4907+
if (i - j == 3 && !isdigit(tp[i]))
4908+
break;
4909+
if (i - j == 4 && tp[i] != ' ')
4910+
break;
4911+
if (i - j == 5 && tp[i] != 'q')
4912+
break;
4913+
if (i - j == 6 && tp[i] != ESC && tp[i] != STERM)
4914+
break;
4915+
if ((i - j == 6 && tp[i] == STERM)
4916+
|| (i - j == 7 && tp[i] == '\\'))
4917+
{
4918+
int number = argp[3] - '0';
4919+
4920+
/* 0, 1 = block blink, 2 = block
4921+
* 3 = underline blink, 4 = underline
4922+
* 5 = vertical bar blink, 6 = vertical bar */
4923+
number = number == 0 ? 1 : number;
4924+
initial_cursor_shape = (number + 1) / 2;
4925+
/* The blink flag is actually inverted, compared to
4926+
* the value set with T_SH. */
4927+
initial_cursor_shape_blink =
49194928
(number & 1) ? FALSE : TRUE;
4920-
rcs_status = STATUS_GOT;
4921-
LOG_TR("Received cursor shape response");
4929+
rcs_status = STATUS_GOT;
4930+
LOG_TR("Received cursor shape response");
49224931

4923-
key_name[0] = (int)KS_EXTRA;
4924-
key_name[1] = (int)KE_IGNORE;
4925-
slen = i + 1 + (tp[i] == ESC);
4932+
key_name[0] = (int)KS_EXTRA;
4933+
key_name[1] = (int)KE_IGNORE;
4934+
slen = i + 1;
49264935
# ifdef FEAT_EVAL
4927-
set_vim_var_string(VV_TERMSTYLERESP, tp, slen);
4936+
set_vim_var_string(VV_TERMSTYLERESP, tp, slen);
49284937
# endif
4938+
break;
4939+
}
49294940
}
49304941
}
49314942

src/version.c

+2
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,8 @@ static char *(features[]) =
778778

779779
static int included_patches[] =
780780
{ /* Add new patch number below this line */
781+
/**/
782+
1556,
781783
/**/
782784
1555,
783785
/**/

0 commit comments

Comments
 (0)