From 56ce644a35d7da469905e786bc50b56f5454b034 Mon Sep 17 00:00:00 2001 From: in2 Date: Sat, 4 May 2002 13:50:26 +0000 Subject: avoid infinite loop git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk/pttbbs@145 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- mbbsd/cache.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'mbbsd') diff --git a/mbbsd/cache.c b/mbbsd/cache.c index dd00d010..fef81942 100644 --- a/mbbsd/cache.c +++ b/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.21 2002/04/28 19:35:28 in2 Exp $ */ +/* $Id: cache.c,v 1.22 2002/05/04 13:50:26 in2 Exp $ */ #include #include #include @@ -165,13 +165,17 @@ void attach_uhash() { void add_to_uhash(int n, char *id) { int *p, h = StringHash(id); + int times; strcpy(uhash->userid[n], id); p = &(uhash->hash_head[h]); - - while(*p != -1) + + for( times = 0 ; times < MAX_USERS && *p != -1 ; ++times ) p = &(uhash->next_in_hash[*p]); - + + if( times == MAX_USERS ) + abort_bbs(0); + uhash->next_in_hash[*p = n] = -1; } @@ -180,9 +184,14 @@ void add_to_uhash(int n, char *id) { void remove_from_uhash(int n) { int h = StringHash(uhash->userid[n]); int *p = &(uhash->hash_head[h]); - - while(*p != -1 && *p != n) + int times; + + for( times = 0 ; times < MAX_USERS && (*p != -1 && *p != n); ++times ) p = &(uhash->next_in_hash[*p]); + + if( times == MAX_USERS ) + abort_bbs(0); + if(*p == n) *p = uhash->next_in_hash[n]; } @@ -207,18 +216,18 @@ int moneyof(int uid){ /* ptt return uhash->money[uid-1]; } int searchuser(char *userid) { - int h,p; - + int h, p, times; h = StringHash(userid); p = uhash->hash_head[h]; - while(p != -1) { + for( times = 0 ; times < MAX_USERS && p != -1 ; ++times ){ if(strcasecmp(uhash->userid[p],userid) == 0) { strcpy(userid,uhash->userid[p]); return p + 1; } p = uhash->next_in_hash[p]; } + return 0; } -- cgit v1.2.3