Apple's libc shells out to Perl to implement wordexp
1–10 of 49 posts
Re: Apple's libc shells out to Perl to implement wordexp
#2Also, that code seems to be from 2008 (or at least that's the latest year in the copyright header) despite the commit being from 2012. Does anyone know if this has been updated? Inserting a NUL byte between each word, and at the end doesn't sound like it requires Perl...
Re: Apple's libc shells out to Perl to implement wordexp
#3Re: Apple's libc shells out to Perl to implement wordexp
#4Re: Apple's libc shells out to Perl to implement wordexp
#5http://linux.die.net/man/3/wordexp
wordexp, wordfree - perform word expansion like a posix-shell
So, the implementer decided to take the short route, and just spawn a shell which, essentially, gets passed the input data to wordexp(), to do the work. But, of course, having something that starts with such a comment...
/* XXX this is _not_ designed to be fast (...) wordexp is also rife with security "challenges", unless you pass it WRDE_NOCMD it must support subshell expansion, and even if you don't beause it has to support so much of the standard shell (all the odd little variable expansion options for example) it is hard to do without a subshell). It is probably just plan a Bad Idea to call in anything setuid, or executing remotely. */
...in your standard C library wasn't such a smart idea to start with. Scroll down, there are many more gems in the comments!
Sometimes it's better to just implement it as
void wordexp() {
fprintf(stderr,"wordexp() is a security nightmare. Not implemented.\n");
assert(0);
}
or decide to deliberately only implement a safe subset of the full functionality specified (e.g. only ~user-homedir expansion and $VARIABLES), to at least cover the common use-cases without creating a security nightmare.(EDIT: typos)
Re: Apple's libc shells out to Perl to implement wordexp
#6Here's the current implementation: http://opensource.apple.com/source/Libc/Libc-1044.1.2/gen/Fr...
Re: Apple's libc shells out to Perl to implement wordexp
#7sometimes you have to get shit done
And Apple have always been masters in selling polished, nicely packages shit as the most advanced technology ever conceived.
Re: Apple's libc shells out to Perl to implement wordexp
#8 [ $# -gt 0 ] && export IFS="$1";/usr/lib/system/wordexp-helperRe: Apple's libc shells out to Perl to implement wordexp
#9As it's already written in the manual... http://linux.die.net/man/3/wordexp wordexp, wordfree - perform word expansion like a posix-shell So, the implementer decided to take the short route, and just spawn a shell which, essentially, gets passed the input data to wordexp(), to do the work. But, of course, having something that starts with such a comment... /* XXX this is _not_ designed to be fast (...) wordexp is als…
In an ideal world, we'd have a libsh that exposed all of the steps of what /bin/sh does in a nice fashion, this function would call one of the libsh functions, and /bin/sh would be a 10-line while (true) { libsh_this(); libsh_that(); }.
In a slightly less ideal world, the shell would have a way to separate things with null characters, without bothering Perl.
We really don't live in an ideal world.
Re: Apple's libc shells out to Perl to implement wordexp
#10This is source code from 2011. Checking http://opensource.apple.com will show that it's not longer implemented this way in 10.10. Here's the current implementation: http://opensource.apple.com/source/Libc/Libc-1044.1.2/gen/Fr...