Re: [PATCH] Cygwin: fstat_helper: always use handle in call to get_file_attribute

2020-01-31 Thread Corinna Vinschen
On Jan 30 12:01, Ken Brown wrote:
> When fhandler_base::fstat_helper is called, the handle h returned by
> get_stat_handle() should be pc.handle() and should be safe to use for
> getting the file information.  Previously, the call to
> get_file_attribute() for FIFOs set the first argument to NULL instead
> of h, thereby forcing the file to be opened for fetching the security
> descriptor in get_file_sd().
> ---
>  winsup/cygwin/fhandler_disk_file.cc | 9 +
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/winsup/cygwin/fhandler_disk_file.cc 
> b/winsup/cygwin/fhandler_disk_file.cc
> index f362e31e3..ad63af824 100644
> --- a/winsup/cygwin/fhandler_disk_file.cc
> +++ b/winsup/cygwin/fhandler_disk_file.cc
> @@ -394,13 +394,14 @@ fhandler_base::fstat_fs (struct stat *buf)
>return res;
>  }
>  
> +/* Called by fstat_by_handle and fstat_by_name. */
>  int __reg2
>  fhandler_base::fstat_helper (struct stat *buf)
>  {
>IO_STATUS_BLOCK st;
>FILE_COMPRESSION_INFORMATION fci;
> -  HANDLE h = get_stat_handle ();
> -  PFILE_ALL_INFORMATION pfai = pc.fai ();
> +  HANDLE h = get_stat_handle ();  /* Should always be pc.handle(). */
> +  pfile_all_information pfai = pc.fai ();

This lower-casing PFILE_ALL_INFORMATION looks like a typo.  Other than
that the patch looks ok.


Thanks,
Corinna

-- 
Corinna Vinschen
Cygwin Maintainer


signature.asc
Description: PGP signature


[PATCH] Cygwin: console: Revise color setting codes in legacy console mode.

2020-01-31 Thread Takashi Yano
- With this patch, foreground color and background color are allowed
  to be set simultaneously by escape sequence such as
  ESC[38;2;0;0;255;48;2;128;128;0m in legacy console mode.
---
 winsup/cygwin/fhandler_console.cc | 38 ---
 1 file changed, 20 insertions(+), 18 deletions(-)

diff --git a/winsup/cygwin/fhandler_console.cc 
b/winsup/cygwin/fhandler_console.cc
index f88d24701..e2832dad8 100644
--- a/winsup/cygwin/fhandler_console.cc
+++ b/winsup/cygwin/fhandler_console.cc
@@ -2020,38 +2020,39 @@ fhandler_console::char_command (char c)
   con.fg = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED;
   break;
 case 38:
-  if (con.nargs < 1)
+  if (con.nargs < i + 1)
 /* Sequence error (abort) */
 break;
-  switch (con.args[1])
+  switch (con.args[i + 1])
 {
 case 2:
-  if (con.nargs != 4)
+  if (con.nargs < i + 4)
 /* Sequence error (abort) */
 break;
-  r = con.args[2];
-  g = con.args[3];
-  b = con.args[4];
+  r = con.args[i + 2];
+  g = con.args[i + 3];
+  b = con.args[i + 4];
   r = r < (95 + 1) / 2 ? 0 : r > 255 ? 5 : (r - 55 + 20) / 40;
   g = g < (95 + 1) / 2 ? 0 : g > 255 ? 5 : (g - 55 + 20) / 40;
   b = b < (95 + 1) / 2 ? 0 : b > 255 ? 5 : (b - 55 + 20) / 40;
   con.fg = table256[16 + r*36 + g*6 + b];
+  i += 4;
   break;
 case 5:
-  if (con.nargs != 2)
+  if (con.nargs < i + 2)
 /* Sequence error (abort) */
 break;
   {
-int idx = con.args[2];
+int idx = con.args[i + 2];
 if (idx < 0)
   idx = 0;
 if (idx > 255)
   idx = 255;
 con.fg = table256[idx];
+i += 2;
   }
   break;
 }
-  i += con.nargs;
   break;
 case 39:
   con.fg = con.default_color & FOREGROUND_ATTR_MASK;
@@ -2081,38 +2082,39 @@ fhandler_console::char_command (char c)
   con.bg = BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED;
   break;
 case 48:
-  if (con.nargs < 1)
+  if (con.nargs < i + 1)
 /* Sequence error (abort) */
 break;
-  switch (con.args[1])
+  switch (con.args[i + 1])
 {
 case 2:
-  if (con.nargs != 4)
+  if (con.nargs < i + 4)
 /* Sequence error (abort) */
 break;
-  r = con.args[2];
-  g = con.args[3];
-  b = con.args[4];
+  r = con.args[i + 2];
+  g = con.args[i + 3];
+  b = con.args[i + 4];
   r = r < (95 + 1) / 2 ? 0 : r > 255 ? 5 : (r - 55 + 20) / 40;
   g = g < (95 + 1) / 2 ? 0 : g > 255 ? 5 : (g - 55 + 20) / 40;
   b = b < (95 + 1) / 2 ? 0 : b > 255 ? 5 : (b - 55 + 20) / 40;
   con.bg = table256[16 + r*36 + g*6 + b] << 4;
+  i += 4;
   break;
 case 5:
-  if (con.nargs != 2)
+  if (con.nargs < i + 2)
 /* Sequence error (abort) */
 break;
   {
-int idx = con.args[2];
+int idx = con.args[i + 2];
 if (idx < 0)
   idx = 0;
 if (idx > 255)
   idx = 255;
 con.bg = table256[idx] << 4;
+i += 2;
   }
   break;
 }
-  i += con.nargs;
   break;
 case 49:
   con.bg = con.default_color & BACKGROUND_ATTR_MASK;
-- 
2.21.0



[PATCH v2] Cygwin: console: Revise color setting codes in legacy console mode.

2020-01-31 Thread Takashi Yano
- With this patch, foreground color and background color are allowed
  to be set simultaneously by 24 bit color escape sequence such as
  ESC[38;2;0;0;255;48;2;128;128;0m in legacy console mode.
---
 winsup/cygwin/fhandler.h  |  2 +-
 winsup/cygwin/fhandler_console.cc | 47 ++-
 2 files changed, 28 insertions(+), 21 deletions(-)

diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h
index 80a78d14c..608932c9c 100644
--- a/winsup/cygwin/fhandler.h
+++ b/winsup/cygwin/fhandler.h
@@ -1829,7 +1829,7 @@ enum ansi_intensity
 #define gotrparen 9
 #define eatpalette 10
 #define endpalette 11
-#define MAXARGS 10
+#define MAXARGS 16
 
 enum cltype
 {
diff --git a/winsup/cygwin/fhandler_console.cc 
b/winsup/cygwin/fhandler_console.cc
index f88d24701..38eed05f4 100644
--- a/winsup/cygwin/fhandler_console.cc
+++ b/winsup/cygwin/fhandler_console.cc
@@ -1952,7 +1952,7 @@ fhandler_console::char_command (char c)
   switch (c)
 {
 case 'm':   /* Set Graphics Rendition */
-   for (int i = 0; i <= con.nargs; i++)
+   for (int i = 0; i < con.nargs; i++)
 switch (con.args[i])
   {
 case 0:/* normal color */
@@ -2020,38 +2020,39 @@ fhandler_console::char_command (char c)
   con.fg = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED;
   break;
 case 38:
-  if (con.nargs < 1)
+  if (con.nargs < i + 2)
 /* Sequence error (abort) */
 break;
-  switch (con.args[1])
+  switch (con.args[i + 1])
 {
 case 2:
-  if (con.nargs != 4)
+  if (con.nargs < i + 5)
 /* Sequence error (abort) */
 break;
-  r = con.args[2];
-  g = con.args[3];
-  b = con.args[4];
+  r = con.args[i + 2];
+  g = con.args[i + 3];
+  b = con.args[i + 4];
   r = r < (95 + 1) / 2 ? 0 : r > 255 ? 5 : (r - 55 + 20) / 40;
   g = g < (95 + 1) / 2 ? 0 : g > 255 ? 5 : (g - 55 + 20) / 40;
   b = b < (95 + 1) / 2 ? 0 : b > 255 ? 5 : (b - 55 + 20) / 40;
   con.fg = table256[16 + r*36 + g*6 + b];
+  i += 4;
   break;
 case 5:
-  if (con.nargs != 2)
+  if (con.nargs < i + 3)
 /* Sequence error (abort) */
 break;
   {
-int idx = con.args[2];
+int idx = con.args[i + 2];
 if (idx < 0)
   idx = 0;
 if (idx > 255)
   idx = 255;
 con.fg = table256[idx];
+i += 2;
   }
   break;
 }
-  i += con.nargs;
   break;
 case 39:
   con.fg = con.default_color & FOREGROUND_ATTR_MASK;
@@ -2081,38 +2082,39 @@ fhandler_console::char_command (char c)
   con.bg = BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED;
   break;
 case 48:
-  if (con.nargs < 1)
+  if (con.nargs < i + 2)
 /* Sequence error (abort) */
 break;
-  switch (con.args[1])
+  switch (con.args[i + 1])
 {
 case 2:
-  if (con.nargs != 4)
+  if (con.nargs < i + 5)
 /* Sequence error (abort) */
 break;
-  r = con.args[2];
-  g = con.args[3];
-  b = con.args[4];
+  r = con.args[i + 2];
+  g = con.args[i + 3];
+  b = con.args[i + 4];
   r = r < (95 + 1) / 2 ? 0 : r > 255 ? 5 : (r - 55 + 20) / 40;
   g = g < (95 + 1) / 2 ? 0 : g > 255 ? 5 : (g - 55 + 20) / 40;
   b = b < (95 + 1) / 2 ? 0 : b > 255 ? 5 : (b - 55 + 20) / 40;
   con.bg = table256[16 + r*36 + g*6 + b] << 4;
+  i += 4;
   break;
 case 5:
-  if (con.nargs != 2)
+  if (con.nargs < i + 3)
 /* Sequence error (abort) */
 break;
   {
-int idx = con.args[2];
+int idx = con.args[i + 2];
 if (idx < 0)
   idx = 0;
 if (idx > 255)
   idx = 255;
 con.bg = table256[idx] << 4;
+i += 2;
   }
   break;
 }
-  i += con.nargs;
   break;
 case 49:
   con.bg = con.default_color & BACKGROUND_ATT