diff options
author | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2009-08-16 15:30:28 +0800 |
---|---|---|
committer | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2009-08-16 15:30:28 +0800 |
commit | 9ba56ead6e563f7ced39551b4bec318b763780b0 (patch) | |
tree | 3bd08b324389c6476280f97cbbcdb5e600afab2a | |
parent | 1824e352a3e293832f5e75e1663f24033fd16596 (diff) | |
download | pttbbs-9ba56ead6e563f7ced39551b4bec318b763780b0.tar pttbbs-9ba56ead6e563f7ced39551b4bec318b763780b0.tar.gz pttbbs-9ba56ead6e563f7ced39551b4bec318b763780b0.tar.bz2 pttbbs-9ba56ead6e563f7ced39551b4bec318b763780b0.tar.lz pttbbs-9ba56ead6e563f7ced39551b4bec318b763780b0.tar.xz pttbbs-9ba56ead6e563f7ced39551b4bec318b763780b0.tar.zst pttbbs-9ba56ead6e563f7ced39551b4bec318b763780b0.zip |
* fix: endless loop if too many directories created by stampdir(). (occurs when too many directories were deleted and creates entry in man/deleted)
* note: to prevent compatibility issue, only expand when required.
git-svn-id: http://opensvn.csie.org/pttbbs/trunk@4747 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r-- | pttbbs/mbbsd/record.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/pttbbs/mbbsd/record.c b/pttbbs/mbbsd/record.c index 7e6206e8..6422253b 100644 --- a/pttbbs/mbbsd/record.c +++ b/pttbbs/mbbsd/record.c @@ -373,6 +373,7 @@ stampdir(char *fpath, fileheader_t * fh) register char *ip = fpath; time4_t dtime = COMMON_TIME; struct tm ptime; + int retries = 0; if (access(fpath, X_OK | R_OK | W_OK)) mkdir(fpath, 0755); @@ -380,7 +381,9 @@ stampdir(char *fpath, fileheader_t * fh) while (*(++ip)); *ip++ = '/'; do { - sprintf(ip, "D%X", (int)++dtime & 07777); + // XXX if directories exceed 4096(0xFFF), use 65536. + int mask = (++retries < 0xFFF) ? 0xFFF : 0xFFFF; + sprintf(ip, "D%X", (int)++dtime & mask); } while (mkdir(fpath, 0755) == -1); memset(fh, 0, sizeof(fileheader_t)); strlcpy(fh->filename, ip, sizeof(fh->filename)); |