bug-bash
[Top][All Lists]
Advanced

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

[PATCH] bash: fix error path of getc_with_restart()


From: Yong Zhang
Subject: [PATCH] bash: fix error path of getc_with_restart()
Date: Mon, 28 Oct 2013 19:51:46 -0700

When read() returns with ERROR, local_bufused will be set
to -1; and if we return with local_bufused == -1 left,
the next time we call getc_with_restart(), the condition
(local_index == local_bufused || local_bufused == 0)
will not match, thus we get random data from localbuf[]
with local_index increased each time, eventually we may
access data beyond array localbuf[]. Fix it by resetting
local_index and local_bufused in case of read failure.

Signed-off-by: Yong Zhang <address@hidden>
---
Please Cc me because I'm not subscribing this list.

 input.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/input.c b/input.c
index 2731e29..8362068 100644
--- a/input.c
+++ b/input.c
@@ -92,6 +92,8 @@ getc_with_restart (stream)
              if (sh_unset_nodelay_mode (fileno (stream)) < 0)
                {
                  sys_error (_("cannot reset nodelay mode for fd %d"), fileno 
(stream));
+                 local_index = 0;
+                 local_bufused = 0;
                  return EOF;
                }
              continue;
@@ -99,6 +101,7 @@ getc_with_restart (stream)
          else if (local_bufused == 0 || errno != EINTR)
            {
              local_index = 0;
+             local_bufused = 0;
              return EOF;
            }
        }
-- 
1.8.2.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]