Modified the patch to print warning only once when null byte is ignored.

----- Original Message -----
> From: "Siteshwar Vashisht" <svashi...@redhat.com>
> To: bug-bash@gnu.org
> Sent: Friday, July 28, 2017 3:59:15 PM
> Subject: read builtin goes into uninterruptible loop if input only contains   
> zeros
> 
> Configuration Information [Automatically generated, do not change]:
> Machine: x86_64
> OS: linux-gnu
> Compiler: gcc
> Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64'
> -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-unknown-linux-gnu'
> -DCONF_VENDOR='unknown' -DLOCALEDIR='/usr/local/share/locale'
> -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib   -g
> -O0 -Wno-parentheses -Wno-format-security
> uname output: Linux localhost.localdomain 4.11.6-201.fc25.x86_64 #1 SMP Tue
> Jun 20 20:21:11 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
> Machine Type: x86_64-unknown-linux-gnu
> 
> Bash Version: 4.4
> Patch Level: 12
> Release Status: release
> 
> Description:
>         read builtin goes into uninterruptible loop if input comes from
>         /dev/zero.
> 
> Repeat-By:
>         read -N 1 _ < /dev/zero
> 
> Fix:
>         Attached patch fixes the bug.
> 
> 
> --
> --
> Siteshwar Vashisht
> 

-- 
--
Siteshwar Vashisht
From 87f9e379ef4618d434ebc376d7d63a98ad620273 Mon Sep 17 00:00:00 2001
From: Siteshwar Vashisht <svashi...@redhat.com>
Date: Fri, 28 Jul 2017 15:51:07 +0200
Subject: [PATCH] Make read builtin interruptible if input contains zeros

---
 builtins/read.def | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/builtins/read.def b/builtins/read.def
index 33821f3..4865c36 100644
--- a/builtins/read.def
+++ b/builtins/read.def
@@ -194,6 +194,7 @@ read_builtin (list)
   struct stat tsb;
   SHELL_VAR *var;
   TTYSTRUCT ttattrs, ttset;
+  int nullbyte;
 #if defined (ARRAY_VARS)
   WORD_LIST *alist;
 #endif
@@ -243,6 +244,7 @@ read_builtin (list)
   nr = nchars = input_is_tty = input_is_pipe = unbuffered_read = have_timeout = 0;
   delim = '\n';		/* read until newline */
   ignore_delim = 0;
+  nullbyte = 0;
 
   reset_internal_getopt ();
   while ((opt = internal_getopt (list, "ersa:d:i:n:p:t:u:N:")) != -1)
@@ -609,7 +611,7 @@ read_builtin (list)
 	  break;
 	}
 
-      CHECK_ALRM;
+      check_signals();
 
 #if defined (READLINE)
 	}
@@ -662,7 +664,14 @@ read_builtin (list)
 	break;
 
       if (c == '\0' && delim != '\0')
-	continue;		/* skip NUL bytes in input */
+	{
+	  if (nullbyte == 0)
+	  {
+	    internal_warning ("read_builtin: ignored null byte in input");
+	    nullbyte = 1;
+	  }
+	  continue;		/* skip NUL bytes in input */
+	}
 
       if ((skip_ctlesc == 0 && c == CTLESC) || (skip_ctlnul == 0 && c == CTLNUL))
 	{
-- 
2.9.4

Reply via email to