X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fmisc%2Fwordexp.c;h=4a3efc7bc40a83d055bb1f4d952e6b70b2d4893c;hb=75483499dad38b97f5dabb710635e6a8bbbb1c84;hp=171f27027f6670bd735559948e1c1aef098cb167;hpb=f0fc95d439459bac27d0d26ec151700a1579b028;p=musl diff --git a/src/misc/wordexp.c b/src/misc/wordexp.c index 171f2702..4a3efc7b 100644 --- a/src/misc/wordexp.c +++ b/src/misc/wordexp.c @@ -7,6 +7,7 @@ #include #include #include +#include static char *getword(FILE *f) { @@ -14,7 +15,7 @@ static char *getword(FILE *f) return getdelim(&s, (size_t [1]){0}, 0, f) < 0 ? 0 : s; } -int wordexp(const char *s, wordexp_t *we, int flags) +static int do_wordexp(const char *s, wordexp_t *we, int flags) { size_t i, l; int sq=0, dq=0; @@ -83,8 +84,13 @@ int wordexp(const char *s, wordexp_t *we, int flags) i += we->we_offs; } - pipe(p); + if (pipe(p) < 0) return WRDE_NOSPACE; pid = fork(); + if (pid < 0) { + close(p[0]); + close(p[1]); + return WRDE_NOSPACE; + } if (!pid) { dup2(p[1], 1); close(p[0]); @@ -130,10 +136,20 @@ int wordexp(const char *s, wordexp_t *we, int flags) } we->we_wordv = wv; - we->we_wordc = i - we->we_offs; + we->we_wordc = i; + if (flags & WRDE_DOOFFS) we->we_wordc -= we->we_offs; return err; } +int wordexp(const char *s, wordexp_t *we, int flags) +{ + int r, cs; + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); + r = do_wordexp(s, we, flags); + pthread_setcancelstate(cs, 0); + return r; +} + void wordfree(wordexp_t *we) { size_t i;