Author: jilles
Date: Mon Apr  1 20:50:07 2013
New Revision: 248987
URL: http://svnweb.freebsd.org/changeset/base/248987

Log:
  wordexp(): Remove wrong IFS usage.
  
  Words in shell script are separated by spaces or tabs independent of the
  value of IFS. The value of IFS is only relevant for the result of
  substitutions. Therefore, there should be a space between 'wordexp' and the
  words to be expanded, not an IFS character.
  
  Paranoia might dictate that the shell ignore IFS from the environment (even
  though our sh currently uses it), so do not depend on it in the new test
  case.

Modified:
  head/lib/libc/gen/wordexp.c
  head/tools/regression/lib/libc/gen/test-wordexp.c

Modified: head/lib/libc/gen/wordexp.c
==============================================================================
--- head/lib/libc/gen/wordexp.c Mon Apr  1 20:44:21 2013        (r248986)
+++ head/lib/libc/gen/wordexp.c Mon Apr  1 20:50:07 2013        (r248987)
@@ -114,15 +114,12 @@ we_askshell(const char *words, wordexp_t
        int status;                     /* Child exit status */
        int error;                      /* Our return value */
        int serrno;                     /* errno to return */
-       char *ifs;                      /* IFS env. var. */
        char *np, *p;                   /* Handy pointers */
        char *nstrings;                 /* Temporary for realloc() */
        char **nwv;                     /* Temporary for realloc() */
        sigset_t newsigblock, oldsigblock;
 
        serrno = errno;
-       if ((ifs = getenv("IFS")) == NULL)
-               ifs = " \t\n";
 
        if (pipe(pdes) < 0)
                return (WRDE_NOSPACE);  /* XXX */
@@ -150,7 +147,7 @@ we_askshell(const char *words, wordexp_t
                if (_dup2(pdes[1], STDOUT_FILENO) < 0)
                        _exit(1);
                _close(pdes[1]);
-               if (asprintf(&cmd, "wordexp%c%s\n", *ifs, words) < 0)
+               if (asprintf(&cmd, "wordexp %s\n", words) < 0)
                        _exit(1);
                if ((flags & WRDE_SHOWERR) == 0) {
                        if ((devnull = _open(_PATH_DEVNULL, O_RDWR, 0666)) < 0)

Modified: head/tools/regression/lib/libc/gen/test-wordexp.c
==============================================================================
--- head/tools/regression/lib/libc/gen/test-wordexp.c   Mon Apr  1 20:44:21 
2013        (r248986)
+++ head/tools/regression/lib/libc/gen/test-wordexp.c   Mon Apr  1 20:50:07 
2013        (r248987)
@@ -208,6 +208,25 @@ main(int argc, char *argv[])
        assert(strcmp(we.we_wordv[1], "world") == 0);
        assert(we.we_wordv[2] == NULL);
        wordfree(&we);
+       sa.sa_handler = SIG_DFL;
+       r = sigaction(SIGCHLD, &sa, NULL);
+       assert(r == 0);
+
+       /*
+        * With IFS set to a non-default value (without depending on whether
+        * IFS is inherited or not).
+        */
+       r = setenv("IFS", ":", 1);
+       assert(r == 0);
+       r = wordexp("hello world", &we, 0);
+       assert(r == 0);
+       assert(we.we_wordc == 2);
+       assert(strcmp(we.we_wordv[0], "hello") == 0);
+       assert(strcmp(we.we_wordv[1], "world") == 0);
+       assert(we.we_wordv[2] == NULL);
+       wordfree(&we);
+       r = unsetenv("IFS");
+       assert(r == 0);
 
        printf("PASS wordexp()\n");
        printf("PASS wordfree()\n");
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to