changeset 1443:0623d694a77f

Forbid NUL characters when using /say_to -f (Reported by Myhailo Danylenko)
author Mikael Berthe <mikael@lilotux.net>
date Fri, 29 Feb 2008 14:55:55 +0100
parents b49a1edba983
children 3bf11085c6a5
files mcabber/src/commands.c
diffstat 1 files changed, 5 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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')