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 | c53cecb7c896d8a08560a1f9e7eb41018a579d9e (patch) | |
tree | 7635ccfd66898e2409fab72469f687a448ff9b34 | |
parent | 88c522418f718bfaa9154b306248b030bfaacfc2 (diff) | |
download | pttbbs-c53cecb7c896d8a08560a1f9e7eb41018a579d9e.tar pttbbs-c53cecb7c896d8a08560a1f9e7eb41018a579d9e.tar.gz pttbbs-c53cecb7c896d8a08560a1f9e7eb41018a579d9e.tar.bz2 pttbbs-c53cecb7c896d8a08560a1f9e7eb41018a579d9e.tar.lz pttbbs-c53cecb7c896d8a08560a1f9e7eb41018a579d9e.tar.xz pttbbs-c53cecb7c896d8a08560a1f9e7eb41018a579d9e.tar.zst pttbbs-c53cecb7c896d8a08560a1f9e7eb41018a579d9e.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/pttbbs@4747 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r-- | mbbsd/record.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/mbbsd/record.c b/mbbsd/record.c index 7e6206e8..6422253b 100644 --- a/mbbsd/record.c +++ b/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)); |