Use dynamic buffer in log_message_class and log_message_method to prevent
authortwisti <none@none>
Wed, 15 Dec 2004 15:48:43 +0000 (15:48 +0000)
committertwisti <none@none>
Wed, 15 Dec 2004 15:48:43 +0000 (15:48 +0000)
buffer overflows.

src/toolbox/logging.c
src/toolbox/logging.h

index bbcc90b4e5c383607b8a4b8694a144245d66368c..011a4ac8e4f653c4ce05dff801d808426ae7a8b2 100644 (file)
@@ -26,7 +26,7 @@
 
    Authors: Reinhard Grafl
 
-   $Id: logging.c 1735 2004-12-07 14:33:27Z twisti $
+   $Id: logging.c 1761 2004-12-15 15:48:43Z twisti $
 
 */
 
@@ -36,6 +36,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "mm/memory.h"
 #include "toolbox/logging.h"
 #include "vm/global.h"
 #include "vm/tables.h"
@@ -179,14 +180,21 @@ void log_cputime()
 
 *******************************************************************************/
 
-void log_message_class(char *msg, classinfo *c)
+void log_message_class(const char *msg, classinfo *c)
 {
-       char logtext[MAXLOGTEXT];
+       char *buf;
+       s4    len;
 
-       sprintf(logtext, msg);
-       utf_sprint_classname(logtext + strlen(logtext), c->name);
+       len = strlen(msg) + utf_strlen(c->name) + 1;
 
-       log_text(logtext);
+       buf = MNEW(char, len);
+
+       sprintf(buf, msg);
+       utf_sprint_classname(buf + strlen(buf), c->name);
+
+       log_text(buf);
+
+       MFREE(buf, char, len);
 }
 
 
@@ -198,17 +206,25 @@ void log_message_class(char *msg, classinfo *c)
 
 *******************************************************************************/
 
-void log_message_method(char *msg, methodinfo *m)
+void log_message_method(const char *msg, methodinfo *m)
 {
-       char logtext[MAXLOGTEXT];
+       char *buf;
+       s4    len;
 
-       sprintf(logtext, msg);
-       utf_sprint_classname(logtext + strlen(logtext), m->class->name);
-       strcpy(logtext + strlen(logtext), ".");
-       utf_sprint(logtext + strlen(logtext), m->name);
-       utf_sprint_classname(logtext + strlen(logtext), m->descriptor);
+       len = strlen(msg) + utf_strlen(m->class->name) + 1 +
+               utf_strlen(m->name) + utf_strlen(m->descriptor) + 1;
 
-       log_text(logtext);
+       buf = MNEW(char, len);
+
+       sprintf(buf, msg);
+       utf_sprint_classname(buf + strlen(buf), m->class->name);
+       strcpy(buf + strlen(buf), ".");
+       utf_sprint(buf + strlen(buf), m->name);
+       utf_sprint_classname(buf + strlen(buf), m->descriptor);
+
+       log_text(buf);
+
+       MFREE(buf, char, len);
 }
 
 
index 0104b7c80abd6954b7d345912d7d23acca547808..98f6844805661ac453e0307c6e134d188718a272 100644 (file)
@@ -26,7 +26,7 @@
 
    Authors: Reinhard Grafl
 
-   $Id: logging.h 1735 2004-12-07 14:33:27Z twisti $
+   $Id: logging.h 1761 2004-12-15 15:48:43Z twisti $
 
 */
 
@@ -51,8 +51,8 @@ void log_nl();             /* newline and fflush */
 
 void log_cputime();
 
-void log_message_class(char *msg, classinfo *c);
-void log_message_method(char *msg, methodinfo *m);
+void log_message_class(const char *msg, classinfo *c);
+void log_message_method(const char *msg, methodinfo *m);
 
 void dolog(char *txt, ...);
 void dolog_plain(char *txt, ...); /* same as dolog without "LOG: " and newline */