From: ian Date: Sun, 4 May 2008 21:49:59 +0000 (+0000) Subject: cope with 0-length messages in oprintf, and do tryflush just before bombing due to... X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=c9cb45bbcfcd5297e9f34b46a1cb6d9b17384042;p=trains.git cope with 0-length messages in oprintf, and do tryflush just before bombing due to buffer overflow --- diff --git a/hostside/obc.c b/hostside/obc.c index 6eafc19..c522afb 100644 --- a/hostside/obc.c +++ b/hostside/obc.c @@ -78,6 +78,7 @@ static void addlink(OutBufferChain *ch, OutBuffer *ob) { char what[128]; snprintf(what,sizeof(what)-1,"`%.*s...'", ob->l,ob->m); what[sizeof(what)-1]= 0; + obc_tryflush(ch); ch->error(ch,"buffer limit exceeded",what); } } @@ -100,7 +101,9 @@ void ovprintf(OutBufferChain *ch, const char *fmt, va_list al) { OutBuffer *ob; ob= mmalloc(sizeof(*ob)); - ob->l= vasprintf(&ob->m, fmt, al); if (ob->l <= 0) diem(); + ob->l= vasprintf(&ob->m, fmt, al); + if (ob->l < 0) diem(); + if (!ob->l) { free(ob->m); free(ob); return; } addlink(ch, ob); }