zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH 1/5] Modules/clone: fix double close()
@ 2018-11-07 13:04 Kamil Dudka
  2018-11-07 13:04 ` [PATCH 2/5] Zle/computil: do not use strcpy() for overlapping blocks Kamil Dudka
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Kamil Dudka @ 2018-11-07 13:04 UTC (permalink / raw)
  To: zsh-workers

Detected by Coverity Analysis.

Error: USE_AFTER_FREE (CWE-825):
zsh-5.5.1/Src/Modules/clone.c:71: closed_arg: "close(int)" closes "ttyfd".
zsh-5.5.1/Src/Modules/clone.c:99: double_close: Calling "close(int)" closes handle "ttyfd" which has already been closed.
 97|   	setsparam("TTY", ztrdup(ttystrname));
 98|       }
 99|->     close(ttyfd);
100|       if (pid < 0) {
101|   	zerrnam(nam, "fork failed: %e", errno);
---
 Src/Modules/clone.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/Src/Modules/clone.c b/Src/Modules/clone.c
index ef6275dcf..4b2655505 100644
--- a/Src/Modules/clone.c
+++ b/Src/Modules/clone.c
@@ -96,7 +96,8 @@ bin_clone(char *nam, char **args, UNUSED(Options ops), UNUSED(int func))
 	init_io(NULL);
 	setsparam("TTY", ztrdup(ttystrname));
     }
-    close(ttyfd);
+    else
+	close(ttyfd);
     if (pid < 0) {
 	zerrnam(nam, "fork failed: %e", errno);
 	return 1;
-- 
2.17.2


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2018-11-07 14:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-07 13:04 [PATCH 1/5] Modules/clone: fix double close() Kamil Dudka
2018-11-07 13:04 ` [PATCH 2/5] Zle/computil: do not use strcpy() for overlapping blocks Kamil Dudka
2018-11-07 13:04 ` [PATCH 3/5] Src/exec: avoid fd leak on fork() failure Kamil Dudka
2018-11-07 13:04 ` [PATCH 4/5] Src/module: fix use-after-free in setmathfuncs() Kamil Dudka
2018-11-07 14:21   ` Mikael Magnusson
2018-11-07 14:35     ` Kamil Dudka
2018-11-07 13:04 ` [PATCH 5/5] Src/utils: fix memory leaks in mailstat() Kamil Dudka

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).