diff options
Diffstat (limited to 'Src/Modules')
-rw-r--r-- | Src/Modules/socket.c | 10 | ||||
-rw-r--r-- | Src/Modules/tcp.c | 12 | ||||
-rw-r--r-- | Src/Modules/zpty.c | 7 |
3 files changed, 25 insertions, 4 deletions
diff --git a/Src/Modules/socket.c b/Src/Modules/socket.c index 469568a11..3f47636bc 100644 --- a/Src/Modules/socket.c +++ b/Src/Modules/socket.c @@ -120,13 +120,19 @@ bin_zsocket(char *nam, char **args, Options ops, UNUSED(int func)) } if (targetfd) { - redup(sfd, targetfd); - sfd = targetfd; + if (redup(sfd, targetfd) == -1) + sfd = -1; + else + sfd = targetfd; } else { /* move the fd since no one will want to read from it */ sfd = movefd(sfd); } + if (sfd == -1) { + zerrnam(nam, "cannot duplicate fd %d: %e", sfd, errno); + return 1; + } setiparam("REPLY", sfd); diff --git a/Src/Modules/tcp.c b/Src/Modules/tcp.c index 2b9e9df18..2825cb978 100644 --- a/Src/Modules/tcp.c +++ b/Src/Modules/tcp.c @@ -446,14 +446,22 @@ bin_ztcp(char *nam, char **args, Options ops, UNUSED(int func)) } if (targetfd) { - redup(sess->fd,targetfd); - sess->fd = targetfd; + if (redup(sess->fd,targetfd) == -1) + sess->fd = -1; + else + sess->fd = targetfd; } else { /* move the fd since no one will want to read from it */ sess->fd = movefd(sess->fd); } + if (sess->fd == -1) { + zwarnnam(nam, "cannot duplicate fd %d: %e", sess->fd, errno); + tcp_close(sess); + return 1; + } + setiparam("REPLY", sess->fd); if (verbose) diff --git a/Src/Modules/zpty.c b/Src/Modules/zpty.c index 4899f8e2e..16bec2bc9 100644 --- a/Src/Modules/zpty.c +++ b/Src/Modules/zpty.c @@ -401,6 +401,12 @@ newptycmd(char *nam, char *pname, char **args, int echo, int nblock) zexit(lastval, 0); } master = movefd(master); + if (master == -1) { + zerrnam(nam, "cannot duplicate fd %d: %e", master, errno); + scriptname = oscriptname; + ineval = oineval; + return 1; + } p = (Ptycmd) zalloc(sizeof(*p)); @@ -423,6 +429,7 @@ newptycmd(char *nam, char *pname, char **args, int echo, int nblock) scriptname = oscriptname; ineval = oineval; + return 0; } |