[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] add missing null check in duplicate_buffered_stream()
From: |
Emanuele Torre |
Subject: |
[PATCH] add missing null check in duplicate_buffered_stream() |
Date: |
Thu, 4 May 2023 01:40:53 +0200 |
This was causing crashes when non-interactive shells that read stdin,
either source a file that dups stdin, or run an eval command that dups
stdin:
$ bash <<< 'echo hi 9<&0'
hi
$ printf %s\\n 'echo hi 9<&0' > file; bash <<< '. ./file'
Segmentation fault (core dumped)
$ bash <<< 'eval "echo hi 9<&0"'
Segmentation fault (core dumped)
---
input.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/input.c b/input.c
index 6eab9909..8c7756a9 100644
--- a/input.c
+++ b/input.c
@@ -359,7 +359,7 @@ duplicate_buffered_stream (int fd1, int fd2)
buffers[fd2]->b_flag |= B_WASBASHINPUT;
}
- if (fd_is_bash_input (fd1) || (buffers[fd1] && (buffers[fd1]->b_flag &
B_SHAREDBUF)))
+ if (buffers[fd2] && fd_is_bash_input (fd1) || (buffers[fd1] &&
(buffers[fd1]->b_flag & B_SHAREDBUF)))
buffers[fd2]->b_flag |= B_SHAREDBUF;
return (fd2);
--
2.40.1
- [PATCH] add missing null check in duplicate_buffered_stream(),
Emanuele Torre <=