X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Ftemp%2Fmkostemps.c;h=8cc01e37e63a308a9d83f204b425efcffc4b0672;hb=8c741783fc96d559cfe79301c924c217b2905c0c;hp=804a5475d2787e34402ada30739cfb4d5c776cb9;hpb=2cc63358cdb0309ca996ffe56ccf402c2f2f16d5;p=musl diff --git a/src/temp/mkostemps.c b/src/temp/mkostemps.c index 804a5475..8cc01e37 100644 --- a/src/temp/mkostemps.c +++ b/src/temp/mkostemps.c @@ -9,18 +9,15 @@ char *__randname(char *); int __mkostemps(char *template, int len, int flags) { - if (len < 0) return EINVAL; - - size_t l = strlen(template)-len; - if (l < 6 || strncmp(template+l-6, "XXXXXX", 6)) { + size_t l = strlen(template); + if (l<6 || len>l-6 || memcmp(template+l-len-6, "XXXXXX", 6)) { errno = EINVAL; - *template = 0; return -1; } int fd, retries = 100; while (retries--) { - __randname(template+l-6); + __randname(template+l-len-6); if ((fd = open(template, flags | O_RDWR | O_CREAT | O_EXCL, 0600))>=0) return fd; if (errno != EEXIST) return -1;