On Tue 11 Mar 2003, jw schultz wrote: > > Hmm. I'm thinking we should just build fnametmp a piece at > a time. I coded it up to see how it would look. Not as > intuitive but there is a lot less strlen and no snprintf. > It also deals shortens the filename both for MAXPATHLEN and > for NAME_MAX so it is almost impossible for the function to > fail or produce a pathname that breaks things. ... > static int get_tmpname(char *fnametmp, char *fname) > { > char *f; > int length = 0; > int maxname; > > > if (tmpdir) > { > strlcpy(fnametmp, tmpdir, MAXPATHLEN - 2); > length = strlen(fnametmp); > } > > if (f = strrchr(fname, '/')) { > if (!tmpdir) { > length = f - fname; > strlcpy(fnametmp, fname, length); > } > ++f; > } else { > f = fname; > } > strcpy(fnametmp + length, "/."); > length += 2;
This will cause the tmpfile to end up in the root directory, if there is no tmpdir and no directory in fname! This is not good. How about: if (length) fnametmp[length++] = '/'; fnametmp[length++] = '.'; > > maxname = MIN(MAXPATHLEN - 8 - length, NAME_MAX - 9); Shouldn't this be: maxname = MIN(MAXPATHLEN - 7 - length, NAME_MAX - 7); because in both cases all we will be adding is ".XXXXXX" ? Paul Slootman -- To unsubscribe or change options: http://lists.samba.org/mailman/listinfo/rsync Before posting, read: http://www.tuxedo.org/~esr/faqs/smart-questions.html