(typed_wu): Treat overlong message as internal error instead of just

truncating it silently.  Simplify.
This commit is contained in:
Markus Armbruster 2005-06-12 10:07:30 +00:00
parent bc8a443264
commit ff27a2644f

View file

@ -78,7 +78,15 @@ telegram_is_new(natid to, struct telstr *tel)
return is_new; return is_new;
} }
/*VARARGS*/ /*
* Send a telegram from FROM to TO.
* Format text to send under control of printf-style FORMAT using
* optional arguments. It is plain ASCII.
* If running from the update, telegram type is TEL_UPDATE.
* Else if FROM is a deity, type is TEL_BULLETIN.
* Else it is TEL_NORM.
* Return 0 on success, -1 on error.
*/
int int
wu(natid from, natid to, char *format, ...) wu(natid from, natid to, char *format, ...)
{ {
@ -98,10 +106,15 @@ wu(natid from, natid to, char *format, ...)
return typed_wu(from, to, buf, TEL_NORM); return typed_wu(from, to, buf, TEL_NORM);
} }
/*
* Send a telegram from FROM to TO.
* MESSAGE is the text to send, encoded as message text.
* TYPE is the telegram type.
* Return 0 on success, -1 on error.
*/
int int
typed_wu(natid from, natid to, char *message, int type) typed_wu(natid from, natid to, char *message, int type)
{ {
char *bp;
int len; int len;
struct telstr tel; struct telstr tel;
struct natstr *np; struct natstr *np;
@ -136,12 +149,11 @@ typed_wu(natid from, natid to, char *message, int type)
} }
tel.tel_from = from; tel.tel_from = from;
(void)time(&tel.tel_date); (void)time(&tel.tel_date);
bp = message; len = strlen(message);
while (*bp++) ; if (CANT_HAPPEN(len > MAXTELSIZE)) {
len = bp - message; len = MAXTELSIZE;
if (len >= MAXTELSIZE) message[len] = 0;
len = (MAXTELSIZE - 1); }
message[len] = 0;
tel.tel_length = len; tel.tel_length = len;
tel.tel_type = type; tel.tel_type = type;
#if !defined(_WIN32) #if !defined(_WIN32)