diff options
author | scw <scw@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2004-08-22 12:28:03 +0800 |
---|---|---|
committer | scw <scw@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2004-08-22 12:28:03 +0800 |
commit | b4b0ca19b19796bb2dcfc9a786ae3934054f73b4 (patch) | |
tree | 1426ddd12333f9225fb6724cf8cbf3b2153912ac | |
parent | 612bac483e447184e224772d83b17f6a2958dfc8 (diff) | |
download | pttbbs-b4b0ca19b19796bb2dcfc9a786ae3934054f73b4.tar pttbbs-b4b0ca19b19796bb2dcfc9a786ae3934054f73b4.tar.gz pttbbs-b4b0ca19b19796bb2dcfc9a786ae3934054f73b4.tar.bz2 pttbbs-b4b0ca19b19796bb2dcfc9a786ae3934054f73b4.tar.lz pttbbs-b4b0ca19b19796bb2dcfc9a786ae3934054f73b4.tar.xz pttbbs-b4b0ca19b19796bb2dcfc9a786ae3934054f73b4.tar.zst pttbbs-b4b0ca19b19796bb2dcfc9a786ae3934054f73b4.zip |
USHM checking bug.
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@2165 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r-- | include/pttstruct.h | 5 | ||||
-rw-r--r-- | mbbsd/talk.c | 6 |
2 files changed, 7 insertions, 4 deletions
diff --git a/include/pttstruct.h b/include/pttstruct.h index ce58a08e..9d1b1935 100644 --- a/include/pttstruct.h +++ b/include/pttstruct.h @@ -368,7 +368,10 @@ typedef struct keeploc_t { struct keeploc_t *next; } keeploc_t; -#define USHM_SIZE (MAX_ACTIVE + 4) /* why+4? */ +#define VALID_USHM_ENTRY(X) ((X) >= 0 && (X) < USHM_SIZE) +#define USHM_SIZE (MAX_ACTIVE + 4) +/* USHM_SIZE 比 MAX_ACTIVE 大是為了防止檢查人數上限時, 又同時衝進來 + * 會造成找 shm 空位的無窮迴圈. 又, 因 USHM 中用 hash, 空間稍大時效率較好. */ /* MAX_BMs is dirty hardcode 4 in mbbsd/cache.c:is_BM_cache() */ #define MAX_BMs 4 /* for BMcache, 一個看板最多幾板主 */ diff --git a/mbbsd/talk.c b/mbbsd/talk.c index 2ae1f5ed..672dff81 100644 --- a/mbbsd/talk.c +++ b/mbbsd/talk.c @@ -293,7 +293,7 @@ friend_stat(userinfo_t * me, userinfo_t * ui) } for (i = 0; me->friend_online[i] && i < MAX_FRIEND; i++) { j = (me->friend_online[i] & 0xFFFFFF); - if (0 <= j && j < MAX_ACTIVE && ui == &SHM->uinfo[j]) { + if (VALID_USHM_ENTRY(j) && ui == &SHM->uinfo[j]) { hit |= me->friend_online[i] >> 24; break; } @@ -1719,7 +1719,7 @@ pickup_myfriend(pickup_t * friends, *myfriend = *friendme = 1; for (i = 0; currutmp->friend_online[i] && i < MAX_FRIEND; ++i) { where = currutmp->friend_online[i] & 0xFFFFFF; - if (0 <= where && where < MAX_ACTIVE && + if (VALID_USHM_ENTRY(where) && (uentp = &SHM->uinfo[where]) && uentp->pid && uentp != currutmp && isvisible_stat(currutmp, uentp, @@ -2314,7 +2314,7 @@ userlist(void) for (i = 0; currutmp->friend_online[i] && i < MAX_FRIEND; ++i) { where = currutmp->friend_online[i] & 0xFFFFFF; - if (0 <= where && where < MAX_ACTIVE && + if (VALID_USHM_ENTRY(where) && (uentp = &SHM->uinfo[where]) && uentp->pid && isvisible_stat(currutmp, uentp, |