NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

lib/58151: Should Curses getnstr() family handle erase and kill characters when input is not a tty?



>Number:         58151
>Category:       lib
>Synopsis:       Should Curses getnstr() family handle erase and kill characters when input is not a tty?
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Apr 14 14:30:01 +0000 2024
>Originator:     Anthony Howe
>Release:        10.0
>Organization:
>Environment:
NetBSD elf.snert.com 10.0 NetBSD 10.0 (GENERIC) #0: Thu Mar 28 08:33:33 UTC 2024  mkrepro%mkrepro.NetBSD.org@localhost:/usr/src/sys/arch/amd64/compile/GENERIC amd64

>Description:
When input is from a TTY, the Curses getnstr() family of functions correctly handle erasechar() (killchar() is subject of bug #57860).

If I attempt to pipe input to a Curses program (see below) which contains erasechar() or killchar() or both, then those characters are not processed and appear as part of the input buffer.

I expect Curses to treat standard input from a TTY or pipe the same.  One use case for this is it allows creating application test cases where input is piped.

In the case of redirected input, a Curses application would use the TERM defined keys or fall back on ^H and ^U when undefined.


>How-To-Repeat:
```
#include <stdio.h>
#include <string.h>
#include <curses.h>
#include <unistd.h>

int
main(int argc, char **argv)
{
	int erase, kill;
	char buf[80];
	if (initscr() == NULL) {
		return 1;
	}
	echo();
	cbreak();
	addstr(" 123456789.123456789.123456789.1234567890\n");
	standout();
	addstr("[                                        ]\n");
	mvgetnstr(1, 1, buf, sizeof (buf));
	standend();
	erase = erasechar();
	kill = killchar();
	endwin();
	printf("%ld:\"%s\"\n", strlen(buf), buf);
	printf("erasechar=%d killchar=%d\n", erase, kill);
	return 0;
}

/*
Type in a string like "abcdefghi", ^U, 1234.
Observe how there is a gap between 1 and 2.
Appears kill char ^U not handled properly.
Backspace / erase char (^H) works just fine.

NetBSD 9.3 lib/57860
*/
```

$ gcc getnstr.c -lcurses
$ print "abcd\b\b\b123\n" | ./a.out | tee output
$ od -a output

Note:
1. the erasechar and killchar are both zero (no defaults).
2. the buffer length is 10, instead of 4, and contains the BS characters from the pipe.


>Fix:



Home | Main Index | Thread Index | Old Index