From 91515a92e554a74f73a15212bea26006f373c5d8 Mon Sep 17 00:00:00 2001 From: kcwu Date: Sat, 13 Jul 2013 06:19:40 +0000 Subject: Fix incorrect snprintf usage. git-svn-id: http://opensvn.csie.org/pttbbs/trunk@5852 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/ccw.c | 3 +++ pttbbs/util/outmail.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/pttbbs/mbbsd/ccw.c b/pttbbs/mbbsd/ccw.c index 137e9d44..8155e75a 100644 --- a/pttbbs/mbbsd/ccw.c +++ b/pttbbs/mbbsd/ccw.c @@ -778,6 +778,9 @@ ccw_chat_send(CCW_CTX *ctx, const char *buf) char genbuf[200]; len = snprintf(genbuf, sizeof(genbuf), "%s\n", buf); + assert(len < sizeof(genbuf)); + if (len > sizeof(genbuf)) + len = sizeof(genbuf); // XXX if remote is closed (without MSG_NOSIGNAL), // this may raise a SIGPIPE and cause BBS to abort... return (tosend(ctx->fd, genbuf, len, MSG_NOSIGNAL) == len); diff --git a/pttbbs/util/outmail.c b/pttbbs/util/outmail.c index fe2d05f6..48adb6e2 100644 --- a/pttbbs/util/outmail.c +++ b/pttbbs/util/outmail.c @@ -101,6 +101,9 @@ void doSendBody(int sock, FILE *fp, char *from, char *to, char *subject) { starttime, (msgid += (int)(random() >> 24)), disclaimer); + assert(n < sizeof(buf)); + if (n > sizeof(buf)) + n = sizeof(buf); write(sock, buf, n); while(fgets(buf, sizeof(buf), fp)) { -- cgit v1.2.3