diff options
Diffstat (limited to 'sysdeps')
-rw-r--r-- | sysdeps/posix/tempname.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/sysdeps/posix/tempname.c b/sysdeps/posix/tempname.c index 9c6bc8f..0d4bbc4 100644 --- a/sysdeps/posix/tempname.c +++ b/sysdeps/posix/tempname.c @@ -231,10 +231,23 @@ __gen_tempname (char *tmpl, int kind) char *XXXXXX; static uint64_t value; uint64_t random_time_bits; - int count, fd = -1; + unsigned int count; + int fd = -1; int save_errno = errno; struct_stat64 st; + /* A lower bound on the number of temporary files to attempt to + generate. The maximum total number of temporary file names that + can exist for a given template is 62**6. It should never be + necessary to try all these combinations. Instead if a reasonable + number of names is tried (we define reasonable as 62**3) fail to + give the system administrator the chance to remove the problems. */ + unsigned int attempts_min = 62 * 62 * 62; + + /* The number of times to attempt to generate a temporary file. To + conform to POSIX, this must be no smaller than TMP_MAX. */ + unsigned int attempts = attempts_min < TMP_MAX ? TMP_MAX : attempts_min; + len = strlen (tmpl); if (len < 6 || strcmp (&tmpl[len - 6], "XXXXXX")) { @@ -261,7 +274,7 @@ __gen_tempname (char *tmpl, int kind) #endif value += random_time_bits ^ __getpid (); - for (count = 0; count < TMP_MAX; value += 7777, ++count) + for (count = 0; count < attempts; value += 7777, ++count) { uint64_t v = value; |