diff options
author | kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2005-08-18 01:28:19 +0800 |
---|---|---|
committer | kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2005-08-18 01:28:19 +0800 |
commit | 8a4bb1b3de7aff38b9c83cd3ec47099f55c22f43 (patch) | |
tree | 730c587e8ae7cc0a44f827a411ad0606ee6745d6 /util/buildAnnounce.c | |
parent | 8319804fdf2aca16a1e206e26f13c7b386cce525 (diff) | |
download | pttbbs-8a4bb1b3de7aff38b9c83cd3ec47099f55c22f43.tar pttbbs-8a4bb1b3de7aff38b9c83cd3ec47099f55c22f43.tar.gz pttbbs-8a4bb1b3de7aff38b9c83cd3ec47099f55c22f43.tar.bz2 pttbbs-8a4bb1b3de7aff38b9c83cd3ec47099f55c22f43.tar.lz pttbbs-8a4bb1b3de7aff38b9c83cd3ec47099f55c22f43.tar.xz pttbbs-8a4bb1b3de7aff38b9c83cd3ec47099f55c22f43.tar.zst pttbbs-8a4bb1b3de7aff38b9c83cd3ec47099f55c22f43.zip |
take care of buffer size, try to avoid crash.
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3060 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'util/buildAnnounce.c')
-rw-r--r-- | util/buildAnnounce.c | 52 |
1 files changed, 33 insertions, 19 deletions
diff --git a/util/buildAnnounce.c b/util/buildAnnounce.c index be1b4ad4..9f170cc6 100644 --- a/util/buildAnnounce.c +++ b/util/buildAnnounce.c @@ -11,24 +11,32 @@ int cmpboardclass(const void *a, const void *b) boardheader_t **brd = (boardheader_t **)a; boardheader_t **tmp = (boardheader_t **)b; return (strncmp((*brd)->title, (*tmp)->title, 4)<<8)+ - strcasecmp((*brd)->brdname, (*tmp)->brdname); + strncasecmp((*brd)->brdname, (*tmp)->brdname, IDLEN); } void buildchilds(int level,char *path,int gid) { char newpath[512]; int i,count=0; - boardheader_t *ptr, *selected[512]; + boardheader_t *ptr, **selected=NULL; fileheader_t item; + char *p; + int preserved=32; + selected=malloc(preserved * sizeof(boardheader_t*)); - for(i=0; i<numboards; i++) - { + /* XXX It will cost O(ngroup * numboards) totally. */ + for(i=0; i<numboards; i++) { ptr =&SHM->bcache[i]; - if( - ptr->gid != gid || - (ptr->brdattr&(BRD_BAD | BRD_HIDE))!=0 - || - (ptr->level && !(ptr->brdattr & BRD_POSTMASK))) + if(ptr->gid != gid) + continue; + if((ptr->brdattr&(BRD_BAD | BRD_HIDE))!=0) continue; + if((ptr->level && !(ptr->brdattr & BRD_POSTMASK))) + continue; + if(count==preserved) { + preserved*=2; + selected=(boardheader_t**)realloc(selected, preserved*sizeof(boardheader_t*)); + } + assert(selected); selected[count++]=ptr; } qsort(&selected, count, sizeof(boardheader_t *), @@ -40,24 +48,30 @@ void buildchilds(int level,char *path,int gid) ptr->brdname, ptr->title); if(ptr->brdattr & BRD_GROUPBOARD){ - sprintf(newpath,"%s/%s",path,ptr->brdname); + snprintf(newpath,sizeof(newpath),"%s/%s",path,ptr->brdname); mkdir(newpath,0766); buildchilds(level+1,newpath,ptr-bcache+1); } else{ - sprintf(newpath,"/bin/ln -s "BBSHOME"/man/boards/%c/%s %s/%s", - /* maybe something wrong with this ^^^^^ */ - ptr->brdname[0], ptr->brdname,path,ptr->brdname); - system(newpath); + if(!invalid_pname(path) && !invalid_pname(ptr->brdname) && + isalpha(ptr->brdname[0])) { + sprintf(newpath,"/bin/ln -s "BBSHOME"/man/boards/%c/%s %s/%s", + ptr->brdname[0], ptr->brdname,path,ptr->brdname); + system(newpath); + } else { + printf("something wrong: %s, %s\n",path, ptr->brdname); + } } - strcpy(item.owner,ptr->BM); - strtok(item.owner,"/"); - sprintf(item.title,"%-13.13s %-32.32s", level?ptr->brdname:"", ptr->title+7); + strlcpy(item.owner,ptr->BM, sizeof(item.owner)); + if((p=strchr(item.owner,'/'))!=NULL) + *p='\0'; + snprintf(item.title,sizeof(item.title),"%-13.13s %-32.32s", level?ptr->brdname:"", ptr->title+7); item.filemode = 0 ; - sprintf(item.filename,ptr->brdname); - sprintf(newpath,"%s/.DIR",path); + strlcpy(item.filename,ptr->brdname,sizeof(item.filename)); + snprintf(newpath,sizeof(newpath),"%s/.DIR",path); append_record(newpath, &item, sizeof(item)); } + free(selected); } |