Author: jilles
Date: Sun Oct 24 20:09:49 2010
New Revision: 214290
URL: http://svn.freebsd.org/changeset/base/214290

Log:
  sh: Check whether dup2 was successful for >&FD and <&FD.
  
  A failure (usually caused by FD not being open) is a redirection error.
  
  Exp-run done by:      pav (with some other sh(1) changes)

Added:
  head/tools/regression/bin/sh/execution/redir4.0   (contents, props changed)
Modified:
  head/bin/sh/redir.c

Modified: head/bin/sh/redir.c
==============================================================================
--- head/bin/sh/redir.c Sun Oct 24 19:56:34 2010        (r214289)
+++ head/bin/sh/redir.c Sun Oct 24 20:09:49 2010        (r214290)
@@ -217,8 +217,11 @@ movefd:
                if (redir->ndup.dupfd >= 0) {   /* if not ">&-" */
                        if (memory[redir->ndup.dupfd])
                                memory[fd] = 1;
-                       else
-                               dup2(redir->ndup.dupfd, fd);
+                       else {
+                               if (dup2(redir->ndup.dupfd, fd) < 0)
+                                       error("%d: %s", redir->ndup.dupfd,
+                                                       strerror(errno));
+                       }
                } else {
                        close(fd);
                }

Added: head/tools/regression/bin/sh/execution/redir4.0
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/tools/regression/bin/sh/execution/redir4.0     Sun Oct 24 20:09:49 
2010        (r214290)
@@ -0,0 +1,4 @@
+# $FreeBSD$
+
+{ echo bad 0>&3; } 2>/dev/null 3>/dev/null 3>&-
+exit 0
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to