X-Git-Url: http://nsz.repo.hu/git/?p=musl;a=blobdiff_plain;f=src%2Fmisc%2Fwordexp.c;h=617706e50d99c18f10eb9a85d836f6100abe63bc;hp=4609b99f624c0926d8ce054230562f8080863214;hb=509b50eda8ea7d4a28f738e4cf8ea98d25959f00;hpb=145c05345d6172eef1c8c274d696dbe1c01b88ab diff --git a/src/misc/wordexp.c b/src/misc/wordexp.c index 4609b99f..617706e5 100644 --- a/src/misc/wordexp.c +++ b/src/misc/wordexp.c @@ -82,6 +82,8 @@ static int do_wordexp(const char *s, wordexp_t *we, int flags) if (we->we_offs > SIZE_MAX/sizeof(void *)/4) return WRDE_NOSPACE; i += we->we_offs; + } else { + we->we_offs = 0; } if (pipe(p) < 0) return WRDE_NOSPACE; @@ -136,11 +138,16 @@ static int do_wordexp(const char *s, wordexp_t *we, int flags) } we->we_wordv = wv; - we->we_wordc = i - we->we_offs; + we->we_wordc = i; + + for (i=we->we_offs; i; i--) + we->we_wordv[i-1] = 0; + + if (flags & WRDE_DOOFFS) we->we_wordc -= we->we_offs; return err; } -int wordexp(const char *s, wordexp_t *we, int flags) +int wordexp(const char *restrict s, wordexp_t *restrict we, int flags) { int r, cs; pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);