diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-06-24 21:18:50 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-06-24 21:18:50 +0000 |
commit | 3ec72b9c2457f12977fbdad9badf534b1cd8c4e5 (patch) | |
tree | 1c355bb2e335ef9c98f52bc49e7d62b88d9da8f3 /src | |
parent | 8153b07b74e4fc34992dee4360173389656bb366 (diff) | |
download | gnunet-3ec72b9c2457f12977fbdad9badf534b1cd8c4e5.tar.gz gnunet-3ec72b9c2457f12977fbdad9badf534b1cd8c4e5.zip |
fix uninitialized timeout, use-after-free on mysql errors:
Diffstat (limited to 'src')
-rw-r--r-- | src/datastore/plugin_datastore_mysql.c | 43 |
1 files changed, 20 insertions, 23 deletions
diff --git a/src/datastore/plugin_datastore_mysql.c b/src/datastore/plugin_datastore_mysql.c index fb271d8d3..0041be378 100644 --- a/src/datastore/plugin_datastore_mysql.c +++ b/src/datastore/plugin_datastore_mysql.c | |||
@@ -311,26 +311,6 @@ get_my_cnf_path (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
311 | 311 | ||
312 | 312 | ||
313 | /** | 313 | /** |
314 | * Free a prepared statement. | ||
315 | * | ||
316 | * @param plugin plugin context | ||
317 | * @param s prepared statement | ||
318 | */ | ||
319 | static void | ||
320 | prepared_statement_destroy (struct Plugin *plugin, | ||
321 | struct GNUNET_MysqlStatementHandle *s) | ||
322 | { | ||
323 | GNUNET_CONTAINER_DLL_remove (plugin->shead, | ||
324 | plugin->stail, | ||
325 | s); | ||
326 | if (s->valid) | ||
327 | mysql_stmt_close (s->statement); | ||
328 | GNUNET_free (s->query); | ||
329 | GNUNET_free (s); | ||
330 | } | ||
331 | |||
332 | |||
333 | /** | ||
334 | * Close database connection and all prepared statements (we got a DB | 314 | * Close database connection and all prepared statements (we got a DB |
335 | * disconnect error). | 315 | * disconnect error). |
336 | * | 316 | * |
@@ -339,9 +319,16 @@ prepared_statement_destroy (struct Plugin *plugin, | |||
339 | static int | 319 | static int |
340 | iclose (struct Plugin *plugin) | 320 | iclose (struct Plugin *plugin) |
341 | { | 321 | { |
342 | while (NULL != plugin->shead) | 322 | struct GNUNET_MysqlStatementHandle *s; |
343 | prepared_statement_destroy (plugin, | 323 | |
344 | plugin->shead); | 324 | for (s = plugin->shead; s != NULL; s = s->next) |
325 | { | ||
326 | if (s->valid) | ||
327 | { | ||
328 | mysql_stmt_close (s->statement); | ||
329 | s->valid = GNUNET_NO; | ||
330 | } | ||
331 | } | ||
345 | if (plugin->dbf != NULL) | 332 | if (plugin->dbf != NULL) |
346 | { | 333 | { |
347 | mysql_close (plugin->dbf); | 334 | mysql_close (plugin->dbf); |
@@ -377,6 +364,7 @@ iopen (struct Plugin *plugin) | |||
377 | mysql_options (plugin->dbf, MYSQL_READ_DEFAULT_GROUP, "client"); | 364 | mysql_options (plugin->dbf, MYSQL_READ_DEFAULT_GROUP, "client"); |
378 | reconnect = 0; | 365 | reconnect = 0; |
379 | mysql_options (plugin->dbf, MYSQL_OPT_RECONNECT, &reconnect); | 366 | mysql_options (plugin->dbf, MYSQL_OPT_RECONNECT, &reconnect); |
367 | timeout = 120; /* in seconds */ | ||
380 | mysql_options (plugin->dbf, | 368 | mysql_options (plugin->dbf, |
381 | MYSQL_OPT_CONNECT_TIMEOUT, (const void *) &timeout); | 369 | MYSQL_OPT_CONNECT_TIMEOUT, (const void *) &timeout); |
382 | mysql_options(plugin->dbf, MYSQL_SET_CHARSET_NAME, "UTF8"); | 370 | mysql_options(plugin->dbf, MYSQL_SET_CHARSET_NAME, "UTF8"); |
@@ -1508,8 +1496,17 @@ libgnunet_plugin_datastore_mysql_done (void *cls) | |||
1508 | { | 1496 | { |
1509 | struct GNUNET_DATASTORE_PluginFunctions *api = cls; | 1497 | struct GNUNET_DATASTORE_PluginFunctions *api = cls; |
1510 | struct Plugin *plugin = api->cls; | 1498 | struct Plugin *plugin = api->cls; |
1499 | struct GNUNET_MysqlStatementHandle *s; | ||
1511 | 1500 | ||
1512 | iclose (plugin); | 1501 | iclose (plugin); |
1502 | while (NULL != (s = plugin->shead)) | ||
1503 | { | ||
1504 | GNUNET_CONTAINER_DLL_remove (plugin->shead, | ||
1505 | plugin->stail, | ||
1506 | s); | ||
1507 | GNUNET_free (s->query); | ||
1508 | GNUNET_free (s); | ||
1509 | } | ||
1513 | GNUNET_free_non_null (plugin->cnffile); | 1510 | GNUNET_free_non_null (plugin->cnffile); |
1514 | GNUNET_free (plugin); | 1511 | GNUNET_free (plugin); |
1515 | GNUNET_free (api); | 1512 | GNUNET_free (api); |