From c72299766768d9c73ad7ee2eda23afb5033eaec7 Mon Sep 17 00:00:00 2001 From: piaip Date: Wed, 2 Apr 2008 15:05:19 +0000 Subject: - [announce] fix copy-paste endless loop (reported by Kinra@ptt1, thanks) git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@4068 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- mbbsd/announce.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mbbsd/announce.c b/mbbsd/announce.c index 6abae9bc..6e09946d 100644 --- a/mbbsd/announce.c +++ b/mbbsd/announce.c @@ -595,7 +595,8 @@ a_appenditem(const menu_t * pm, int isask) snprintf(fname, sizeof(fname), "%s/%s", pm->path, pm->header[pm->now - pm->page].filename); - if (!dashf(fname)) { + // if same file, abort. + if (!dashf(fname) || strcmp(fname, cq->copyfile) == 0) { vmsg("檔案不得附加於此!"); return; } @@ -629,7 +630,10 @@ a_appenditem(const menu_t * pm, int isask) "是否收錄簽名檔部份(Y/N)?[Y] ", ans, sizeof(ans), LCECHO); - while (fgets(buf, sizeof(buf), fin)) { + // XXX reported by Kinra, appending same file may cause endless loop here. + // we check file name at prior steps and do file size check here. + while (sz > 0 && fgets(buf, sizeof(buf), fin)) { + sz -= strlen(buf); if ((ans[0] == 'n') && !strcmp(buf, "--\n")) break; -- cgit v1.2.3