Refreshing Python filters?

Julien ÉLIE julien at trigofacile.com
Sun Jun 8 13:59:40 UTC 2008


Hi David,

[A nasty strcat...  But I do not understand why we cannot free(skey) or free(svalue)
with that.  Does someone have an explanation?
I switched to strlcpy and strlcat -- please tell me if my code is not optimal.]


> Wow , so my chances to realize it until tomorrow are definitely gone :(

No they aren't :-)

Could you please try this patch?
It seems to work well on the INN I use.


Index: nnrpd/python.c
===================================================================
--- nnrpd/python.c      (révision 7829)
+++ nnrpd/python.c      (copie de travail)
@@ -232,7 +232,7 @@
 PY_access(char* file, struct vector *access_vec, char *Username)
 {
     PyObject   *result, *key, *value, *proc;
-    char       *skey, *svalue, *temp;
+    char        *buffer;
     int                authnum;
     int                i;

@@ -298,6 +298,7 @@

     /* store dict values in proper format in access vector */
     i = 0;
+    buffer = xmalloc(BIG_BUFFER);
     while(PyDict_Next(result, &i, &key, &value)) {
         if (!PyString_Check(key)) {
             syslog(L_ERROR, "python access method return dictionary key %i not a string", i);
@@ -310,20 +311,15 @@
             ExitWithStats(1, false);
         }

-        temp = PyString_AsString(key);
-        skey = xstrdup(temp);
-
-        temp = PyString_AsString(value);
-        svalue = xstrdup(temp);
-
-        skey = strcat(skey, ": \"");
-        skey = strcat(skey, svalue);
-        skey = strcat(skey, "\"\n");
-        vector_add(access_vec, skey);
-
-        free(skey);
-        free(svalue);
+        strlcpy(buffer, PyString_AsString(key), BIG_BUFFER);
+        strlcat(buffer, ": \"", BIG_BUFFER);
+        strlcat(buffer, PyString_AsString(value), BIG_BUFFER);
+        strlcat(buffer, "\"\n", BIG_BUFFER);
+
+        vector_add(access_vec, xstrdup(buffer));
+        syslog(L_ERROR, "buffer %s", xstrdup(buffer));
     }
+    free(buffer);

     /* Clean up the dictionary object */
     PyDict_Clear(PYauthinfo);


-- 
Julien ÉLIE

« Je vais t'apprendre à chasser... Nous commencerons par les marcassins,
  et puis ensuite, nous passerons aux patrouilles romaines, et enfin
  aux sangliers ! » (Astérix)



More information about the inn-workers mailing list