1
0
mirror of https://github.com/skeeto/w64devkit.git synced 2026-10-23 06:08:56 +03:00

Reject stty rows, cols, and columns on Windows

busybox-w32 recognized these settings but cannot set the window size.
The first pass checked the following number without consuming it, so
every use failed, and with nothing after them stty crashed on a null
pointer. Now they are rejected as invalid arguments.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Christopher Wellons
2026-10-22 21:08:02 -04:00
parent 0ca4aa683c
commit 081983e3ad
3 changed files with 41 additions and 8 deletions

View File

@@ -112,8 +112,8 @@ The settings
.BR cols ,
and
.BR columns ,
which resize the window on Unix, are recognized but always fail:
a number after one of them is reported as an invalid argument.
which resize the window on Unix, are not supported and are rejected as
invalid arguments.
.SH OPTIONS
.TP
.B \-a
@@ -235,14 +235,13 @@ There is no way to save the current mode and restore it later, because
.B \-g
is not supported.
.PP
When
busybox-w32 recognizes
.BR rows ,
.BR cols ,
or
.B columns
is the last argument, with no number after it,
.B stty
crashes instead of reporting an error.
and
.BR columns ,
but rejects the number after them, and crashes when nothing follows.
w64devkit rejects them outright.
.PP
.BR ttysize (1)
also prints the console size, prints the width first by default, and

View File

@@ -11,3 +11,4 @@ less-raw-sgr.patch
bare-drive.patch
rm-bare-drive.patch
drop-test2.patch
stty-winsize.patch

View File

@@ -0,0 +1,33 @@
On Windows, stty recognized rows, cols and columns as settings, though
it cannot set the window size and its usage lists only size. The first
pass checked the following number without consuming it, so "stty rows
30" always failed with "invalid argument '30'", and "stty rows" with
nothing after it dereferenced a null pointer and crashed. Recognize only
size, so these are rejected as invalid arguments like other settings
the Windows build lacks.
--- a/coreutils/stty.c
+++ b/coreutils/stty.c
@@ -1008,17 +1008,11 @@
static int find_param(const char *name)
{
- static const char params[] ALIGN1 =
- "rows\0" /* 1 */
- "cols\0" /* 2 */
- "columns\0" /* 3 */
- "size\0"; /* 4 */
- int i = index_in_strings(params, name) + 1;
- if (i == 0)
- return 0;
- if (i != 4)
- i |= 0x80;
- return i;
+ /* The window size cannot be set, so rows, cols and columns are
+ * not settings: accepting them consumed no argument, and with
+ * none following, dereferenced a null pointer.
+ */
+ return strcmp(name, "size") == 0 ? param_size : 0;
}
#endif