gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r15770 - gnunet/src/datastore


From: gnunet
Subject: [GNUnet-SVN] r15770 - gnunet/src/datastore
Date: Fri, 24 Jun 2011 23:18:50 +0200

Author: grothoff
Date: 2011-06-24 23:18:50 +0200 (Fri, 24 Jun 2011)
New Revision: 15770

Modified:
   gnunet/src/datastore/plugin_datastore_mysql.c
Log:
fix uninitialized timeout, use-after-free on mysql errors:


Modified: gnunet/src/datastore/plugin_datastore_mysql.c
===================================================================
--- gnunet/src/datastore/plugin_datastore_mysql.c       2011-06-24 08:04:56 UTC 
(rev 15769)
+++ gnunet/src/datastore/plugin_datastore_mysql.c       2011-06-24 21:18:50 UTC 
(rev 15770)
@@ -311,26 +311,6 @@
 
 
 /**
- * Free a prepared statement.
- *
- * @param plugin plugin context
- * @param s prepared statement
- */
-static void
-prepared_statement_destroy (struct Plugin *plugin, 
-                           struct GNUNET_MysqlStatementHandle *s)
-{
-  GNUNET_CONTAINER_DLL_remove (plugin->shead,
-                              plugin->stail,
-                              s);
-  if (s->valid)
-    mysql_stmt_close (s->statement);
-  GNUNET_free (s->query);
-  GNUNET_free (s);
-}
-
-
-/**
  * Close database connection and all prepared statements (we got a DB
  * disconnect error).
  * 
@@ -339,9 +319,16 @@
 static int
 iclose (struct Plugin *plugin)
 {
-  while (NULL != plugin->shead)
-    prepared_statement_destroy (plugin,
-                               plugin->shead);
+  struct GNUNET_MysqlStatementHandle *s;
+
+  for (s = plugin->shead; s != NULL; s = s->next)
+    {
+      if (s->valid)
+       {
+         mysql_stmt_close (s->statement);
+         s->valid = GNUNET_NO;
+       }
+    }
   if (plugin->dbf != NULL)
     {
       mysql_close (plugin->dbf);
@@ -377,6 +364,7 @@
   mysql_options (plugin->dbf, MYSQL_READ_DEFAULT_GROUP, "client");
   reconnect = 0;
   mysql_options (plugin->dbf, MYSQL_OPT_RECONNECT, &reconnect);
+  timeout = 120; /* in seconds */
   mysql_options (plugin->dbf,
                  MYSQL_OPT_CONNECT_TIMEOUT, (const void *) &timeout);
   mysql_options(plugin->dbf, MYSQL_SET_CHARSET_NAME, "UTF8");
@@ -1508,8 +1496,17 @@
 {
   struct GNUNET_DATASTORE_PluginFunctions *api = cls;
   struct Plugin *plugin = api->cls;
+  struct GNUNET_MysqlStatementHandle *s;
 
   iclose (plugin);
+  while (NULL != (s = plugin->shead))
+    {
+      GNUNET_CONTAINER_DLL_remove (plugin->shead,
+                                  plugin->stail,
+                                  s);
+      GNUNET_free (s->query);
+      GNUNET_free (s);
+    }
   GNUNET_free_non_null (plugin->cnffile);
   GNUNET_free (plugin);
   GNUNET_free (api);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]