fixed a security bug in logging, added basic xml support to as3 compiler
[swftools.git] / lib / python / pyutils.c
index 453b5c4..f5362fc 100644 (file)
@@ -10,7 +10,7 @@ char* setError(char*format, ...)
     int l;
     va_list arglist;
     va_start(arglist, format);
-    vsprintf(buf, format, arglist);
+    vsnprintf(buf, sizeof(buf)-1, format, arglist);
     va_end(arglist);
     l = strlen(buf);
     while(l && buf[l-1]=='\n') {
@@ -20,7 +20,7 @@ char* setError(char*format, ...)
     return strdup(buf);
 }
 
-int verbose = 1;
+static int verbose = 0;
 void mylog(char*format, ...)
 {
     char buf[1024];
@@ -29,7 +29,7 @@ void mylog(char*format, ...)
     if(!verbose)
        return;
     va_start(arglist, format);
-    vsprintf(buf, format, arglist);
+    vsnprintf(buf, sizeof(buf)-1, format, arglist);
     va_end(arglist);
     l = strlen(buf);
     while(l && buf[l-1]=='\n') {
@@ -70,9 +70,12 @@ PyMethodDef* addMethods(PyMethodDef*obj1, PyMethodDef*obj2)
     if(obj1) for(num1=0;obj1[num1].ml_name;num1++);
     if(obj2) for(num2=0;obj2[num2].ml_name;num2++);
     PyMethodDef* result = malloc(sizeof(PyMethodDef)*(num1+num2+1));
-    memcpy(result, obj1, num1*sizeof(PyMethodDef));
-    memcpy(&result[num1], obj2, (num2+1)*sizeof(PyMethodDef));
-    //free(obj1)?
+    if(obj1)
+       memcpy(result, obj1, num1*sizeof(PyMethodDef));
+    if(obj2)
+       memcpy(&result[num1], obj2, (num2+1)*sizeof(PyMethodDef));
+    if(obj1)
+       free(obj1);
     return result;
 }
 void setVerbosity(int _verbose)