subs: Oops when a telegram doesn't end with a newline

Telegrams should always end with a newline.  The common cause for a
missing newline is misuse of wu() to print partial lines.  Almost
always works, as the read command merges telegrams arriving in quick
succession.  But if the telegrams are more than five seconds apart
(clock jumped somehow), we get a telegram header in the middle of a
line.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
Markus Armbruster 2015-01-11 13:24:08 +01:00
parent 4401cca0af
commit 61fc526b5d

View file

@ -28,7 +28,7 @@
* *
* Known contributors to this file: * Known contributors to this file:
* Steve McClure, 2000 * Steve McClure, 2000
* Markus Armbruster, 2005-2011 * Markus Armbruster, 2005-2015
*/ */
#include <config.h> #include <config.h>
@ -138,6 +138,7 @@ 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);
len = strlen(message); len = strlen(message);
CANT_HAPPEN(len && message[len - 1] != '\n');
tel.tel_length = len; tel.tel_length = len;
tel.tel_type = type; tel.tel_type = type;
tel.tel_cont = !telegram_is_new(to, &tel); tel.tel_cont = !telegram_is_new(to, &tel);