Browse Source

bug report

master
CismonX 5 months ago
commit
4ae458f1b7
Signed by: CismonX GPG Key ID: 3094873E29A482FB
  1. 75
      README.md
  2. 13
      button.c.patch
  3. 25
      test.c

75
README.md

@ -0,0 +1,75 @@
# Bug Report for XTerm
## Summary
With 1002 and 1016 mode enabled, XTerm may produce invalid CSI sequence.
## Prerequisites
* XTerm version: 365
* XTerm configuration: default
* Operating System: GNU/Linux
## Steps to Reproduce
1. Compile [test.c](test.c) with `gcc -o test-xterm test.c`.
2. In XTerm, run `script -I input.esc`.
3. Run `./test-xterm`.
4. Move mouse pointer into the terminal window.
5. Press down mouse button (do not release yet).
6. Move mouse pointer across the top or left border of the terminal window.
7. Release mouse button.
8. Press Ctrl+D to quit the test program.
9. Execute `exit` to quit the `script` session.
10. Run `teseq -L input.esc | less`.
## Analyze the Input Log
In Teseq's output, you may see something like this:
```
: Esc [ < 32 ; 9 ; 492 M
: Esc [ < 32 ; 5 ; 492 M
: Esc [ < 32 ; 1 ; 492 M
: Esc [
|<32;-3;492M|
: Esc [
|<32;-5;492M|
: Esc [
|<32;-7;492M|
```
After the mouse pointer moves across the window border, XTerm prints the negative coordinates in the CSI sequence.
However, the hyphen character "-" is not a valid CSI parameter byte, according to ECMA-48.
## Bugfix
The bug is caused by the following code in button.c:
```C
// ...
if (screen->extend_coords == SET_PIXEL_POSITION_MOUSE) {
row = event->y - OriginY(screen);
col = event->x - OriginX(screen);
} else {
/* Compute character position of mouse pointer */
row = (event->y - screen->border) / FontHeight(screen);
col = (event->x - OriginX(screen)) / FontWidth(screen);
/* Limit to screen dimensions */
if (row < 0)
row = 0;
else if (row > screen->max_row)
row = screen->max_row;
if (col < 0)
col = 0;
else if (col > screen->max_col)
col = screen->max_col;
// ...
```
When 1016 mode is enabled, XTerm does not limit the coordinates to the screen dimensions, so that negative values may be produced.
Apply the patch [button.c.patch](button.c.patch) to button.c to fix the bug.

13
button.c.patch

@ -0,0 +1,13 @@
--- button.c 2021-02-04 09:00:26.000000000 +0800
+++ button.patched.c 2021-02-07 21:31:45.960978282 +0800
@@ -5258,6 +5258,10 @@
if (screen->extend_coords == SET_PIXEL_POSITION_MOUSE) {
row = event->y - OriginY(screen);
col = event->x - OriginX(screen);
+ if (row < 0)
+ row = 0;
+ if (col < 0)
+ col = 0;
} else {
/* Compute character position of mouse pointer */
row = (event->y - screen->border) / FontHeight(screen);

25
test.c

@ -0,0 +1,25 @@
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
int main()
{
struct termios old_termios, new_termios;
int ch, fd_in = STDIN_FILENO;
tcgetattr(fd_in, &old_termios);
new_termios = old_termios;
new_termios.c_lflag &= ~(ICANON | ECHO);
tcsetattr(fd_in, TCSANOW, &new_termios);
setvbuf(stdout, NULL, _IONBF, 0);
printf("\033[?1002h");
printf("\033[?1016h");
while (EOF != (ch = getchar())) {
if (ch == 0x04) {
break;
}
}
printf("\033[?1016l");
printf("\033[?1002l");
tcsetattr(fd_in, TCSANOW, &old_termios);
return 0;
}
Loading…
Cancel
Save