# HG changeset patch # User Mikael Berthe # Date 1204293355 -3600 # Node ID 0623d694a77f178189b87d6695e34296ec4a6a8f # Parent b49a1edba9838e9b92458e5db4948c578f0c0587 Forbid NUL characters when using /say_to -f (Reported by Myhailo Danylenko) diff -r b49a1edba983 -r 0623d694a77f mcabber/src/commands.c --- a/mcabber/src/commands.c Fri Feb 29 13:02:04 2008 +0100 +++ b/mcabber/src/commands.c Fri Feb 29 14:55:55 2008 +0100 @@ -1356,6 +1356,7 @@ char *msgbuf, *msgbuf_utf8; char *p; char *next_utf8_char; + size_t len; fd = fopen(filename, "r"); @@ -1373,14 +1374,13 @@ } msgbuf = g_new0(char, HBB_BLOCKSIZE); - fread(msgbuf, HBB_BLOCKSIZE-1, 1, fd); + len = fread(msgbuf, 1, HBB_BLOCKSIZE-1, fd); fclose(fd); next_utf8_char = msgbuf; - // Strip trailing newlines + // Check there is no binary data. It must be a *message* file! for (p = msgbuf ; *p ; p++) { - // Check there is no binary data. It must be a *message* file! if (utf8_mode) { if (p == next_utf8_char) { if (!iswprint(get_char(p)) && *p != '\n') @@ -1394,7 +1394,7 @@ } } - if (*p) { // We're not at the End Of Line... + if (*p || (size_t)(p-msgbuf) != len) { // We're not at the End Of Line... scr_LogPrint(LPRINT_LOGNORM, "Message file contains " "invalid characters (%s)", filename); g_free(msgbuf); @@ -1402,6 +1402,7 @@ } // p is now at the EOL + // Let's strip trailing newlines if (p > msgbuf) p--; while (p > msgbuf && *p == '\n')