From 4e8a2c25129260c61df345f15715d75c715cb92c Mon Sep 17 00:00:00 2001 From: kcwu Date: Sat, 8 Apr 2006 14:58:06 +0000 Subject: add a lot of assertions to ensure bid is in correct range when access via bid. git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3341 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- mbbsd/bbs.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) (limited to 'mbbsd/bbs.c') diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c index 0f6141f9..02eb00e7 100644 --- a/mbbsd/bbs.c +++ b/mbbsd/bbs.c @@ -147,6 +147,7 @@ set_board(void) { boardheader_t *bp; + assert(0<=currbid-1 && currbid-1perm_reload != last_chk_time) @@ -234,6 +236,7 @@ CheckPostPerm(void) if(!valid_index) { last_board_index = getbnum(currboard); + assert(0<=last_board_index-1 && last_board_index-1perm_reload; @@ -257,6 +260,7 @@ readtitle(void) boardheader_t *bp; char *brd_title; + assert(0<=currbid-1 && currbid-1bvote != 2 && bp->bvote) brd_title = "本看板進行投票中"; @@ -276,6 +280,7 @@ readtitle(void) #endif { char buf[32]; + assert(0<=currbid-1 && currbid-1bcache[currbid - 1].nuser); outslr("", 44, buf, -1); @@ -441,6 +446,7 @@ do_select(void) CompleteBoard(MSG_SELECT_BOARD, bname); if (bname[0] == '\0' || !(i = getbnum(bname))) return FULLUPDATE; + assert(0<=i-1 && i-1lastposttime[bid - 1] = now; touchbpostnum(bid, 1); } @@ -675,6 +682,7 @@ do_general(int isbid) int islocal, posttype=-1; ifuseanony = 0; + assert(0<=currbid-1 && currbid-1brdattr & BRD_VOTEBOARD) return do_voteboard(0); @@ -953,6 +962,7 @@ do_post_openbid(void) char ans[4]; boardheader_t *bp; + assert(0<=currbid-1 && currbid-1brdattr & BRD_VOTEBOARD)) { @@ -972,6 +982,7 @@ do_generalboardreply(/*const*/ fileheader_t * fhdr) { char genbuf[3]; + assert(0<=currbid-1 && currbid-1 (now - (time4_t)bcache[currbid - 1].post_limit_regtime * 2592000) || cuser.numlogins < ((unsigned int)(bcache[currbid - 1].post_limit_logins) * 10) || @@ -1046,6 +1057,7 @@ b_posttype(int ent, const fileheader_t * fhdr, const char *direct) if(!(currmode & MODE_BOARD)) return DONOTHING; + assert(0<=currbid-1 && currbid-1posttype_f = posttype_f; strlcpy(bp->posttype, posttype, sizeof(bp->posttype)); /* 這邊應該要防race condition */ + assert(0<=currbid-1 && currbid-1brdname, fhdr->filename); if (bp->brdattr & BRD_VOTEBOARD || (fhdr->filemode & FILE_VOTE)) @@ -1128,6 +1142,7 @@ edit_post(int ent, fileheader_t * fhdr, const char *direct) struct stat oldstat, newstat; int isSysop = 0, recordTouched = 0; + assert(0<=currbid-1 && currbid-1brdname, "Security") == 0) return DONOTHING; @@ -1292,6 +1307,7 @@ cross_post(int ent, fileheader_t * fhdr, const char *direct) move(2, 0); clrtoeol(); move(1, 0); + assert(0<=currbid-1 && currbid-1brdattr & BRD_VOTEBOARD) ) return FULLUPDATE; @@ -1309,6 +1325,7 @@ cross_post(int ent, fileheader_t * fhdr, const char *direct) /* 借用變數 */ ent = str_checksum(fhdr->title); author = getbnum(xboard); + assert(0<=author-1 && author-1brdattr & BRD_HIDE) && (bp->brdattr & BRD_POSTMASK)) { /* mosaic it */ @@ -1446,8 +1465,12 @@ cross_post(int ent, fileheader_t * fhdr, const char *direct) do_add_recommend(direct, fhdr, ent, buf, 2); } else #endif + { + int bid = getbnum(xboard); + assert(0<=bid-1 && bid-1 2550); bp->post_limit_posts = (unsigned char)(temp / 10); + assert(0<=currbid-1 && currbid-1brdname); vmsg("修改完成!"); @@ -1587,6 +1612,7 @@ do_limitedit(int ent, fileheader_t * fhdr, const char *direct) temp = atoi(genbuf); } while (temp < 0 || temp > 2550); bp->vote_limit_posts = (unsigned char)(temp / 10); + assert(0<=currbid-1 && currbid-1brdname); vmsg("修改完成!"); @@ -1650,6 +1676,7 @@ stop_gamble(void) { boardheader_t *bp = getbcache(currbid); char fn_ticket[128], fn_ticket_end[128]; + assert(0<=currbid-1 && currbid-1endgamble || bp->endgamble > now) return 0; @@ -1659,6 +1686,7 @@ stop_gamble(void) rename(fn_ticket, fn_ticket_end); if (bp->endgamble) { bp->endgamble = 0; + assert(0<=currbid-1 && currbid-1brdattr & BRD_BAD ) @@ -1705,6 +1735,7 @@ hold_gamble(void) rename(fn_ticket, fn_ticket_end); if (bp->endgamble) { bp->endgamble = 0; + assert(0<=currbid-1 && currbid-1endgamble = gettime(4, now, "封盤於"); + assert(0<=currbid-1 && currbid-1brdattr & BRD_NORECOMMEND || ((fhdr->filemode & FILE_MARKED) && (fhdr->filemode & FILE_SOLVED))) { @@ -2298,6 +2331,7 @@ recommend(int ent, fileheader_t * fhdr, const char *direct) inc_goodpost(fhdr->owner, 1); #endif lastrecommend = now; + assert(0<=currbid-1 && currbid-1filename, sizeof(lastrecommend_fname)); return FULLUPDATE; @@ -2344,6 +2378,7 @@ del_range(int ent, const fileheader_t *fhdr, const char *direct) /* 有三種情況會進這裡, 信件, 看板, 精華區 */ if( !(direct[0] == 'h') ){ /* 信件不用 check */ + assert(0<=currbid-1 && currbid-1brdname, "Security") == 0) return DONOTHING; @@ -2401,6 +2436,7 @@ del_post(int ent, fileheader_t * fhdr, char *direct) int not_owned, tusernum; boardheader_t *bp; + assert(0<=currbid-1 && currbid-1brdname, fn_notes); aborted = vedit(buf, NA, NULL); if (aborted == -1) { @@ -2660,6 +2697,7 @@ b_note_edit_bname(int bid) "有效日期至"); else fh->bupdate = 0; + assert(0<=bid-1 && bid-1title + 7, genbuf, sizeof(bp->title) - 7); + assert(0<=currbid-1 && currbid-1filemode ^= FILE_BOTTOM; num = delete_record(direct, sizeof(fileheader_t), ent); } + assert(0<=currbid-1 && currbid-1brdattr & BRD_HIDE)) { getdata(1, 0, "好文值得出版到全站文摘?(N/y)", genbuf2, 3, LCECHO); if(genbuf2[0] == 'y') @@ -3112,6 +3156,7 @@ b_config(void) } if(touched) { + assert(0<=currbid-1 && currbid-1brdname); pressanykey(); @@ -3179,6 +3225,7 @@ change_counting(void) bp->brdattr |= BRD_BMCOUNT; outs("快灌水衝十大第一吧。\n"); } + assert(0<=currbid-1 && currbid-1brdattr |= BRD_COOLDOWN; outs("開始冷靜。\n"); } + assert(0<=currbid-1 && currbid-1