[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r24280 - in gnunet/src: include testbed
From: |
gnunet |
Subject: |
[GNUnet-SVN] r24280 - in gnunet/src: include testbed |
Date: |
Thu, 11 Oct 2012 23:23:06 +0200 |
Author: harsha
Date: 2012-10-11 23:23:06 +0200 (Thu, 11 Oct 2012)
New Revision: 24280
Modified:
gnunet/src/include/gnunet_testbed_service.h
gnunet/src/testbed/sample_hosts.txt
gnunet/src/testbed/test_testbed_api_hosts.c
gnunet/src/testbed/testbed_api_hosts.c
Log:
fixes for invalid reads
Modified: gnunet/src/include/gnunet_testbed_service.h
===================================================================
--- gnunet/src/include/gnunet_testbed_service.h 2012-10-11 20:45:08 UTC (rev
24279)
+++ gnunet/src/include/gnunet_testbed_service.h 2012-10-11 21:23:06 UTC (rev
24280)
@@ -113,7 +113,8 @@
* Load a set of hosts from a configuration file.
*
* @param filename file with the host specification
- * @param hosts set to the hosts found in the file
+ * @param hosts set to the hosts found in the file; caller must free this if
+ * number of hosts returned is greater than 0
* @return number of hosts returned in 'hosts', 0 on error
*/
unsigned int
Modified: gnunet/src/testbed/sample_hosts.txt
===================================================================
--- gnunet/src/testbed/sample_hosts.txt 2012-10-11 20:45:08 UTC (rev 24279)
+++ gnunet/src/testbed/sample_hosts.txt 2012-10-11 21:23:06 UTC (rev 24280)
@@ -3,3 +3,13 @@
address@hidden:22
address@hidden:22
address@hidden:22
address@hidden:22
address@hidden:22
address@hidden:22
address@hidden:22
address@hidden:22
address@hidden:22
address@hidden:22
address@hidden:22
address@hidden:22
address@hidden:22
Modified: gnunet/src/testbed/test_testbed_api_hosts.c
===================================================================
--- gnunet/src/testbed/test_testbed_api_hosts.c 2012-10-11 20:45:08 UTC (rev
24279)
+++ gnunet/src/testbed/test_testbed_api_hosts.c 2012-10-11 21:23:06 UTC (rev
24280)
@@ -73,6 +73,7 @@
GNUNET_TESTBED_host_destroy (hosts[num_hosts - 1]);
num_hosts--;
}
+ GNUNET_free (hosts);
}
@@ -99,7 +100,7 @@
hosts = NULL;
num_hosts = GNUNET_TESTBED_hosts_load_from_file ("sample_hosts.txt",
&hosts);
- GNUNET_assert (5 == num_hosts);
+ GNUNET_assert (15 == num_hosts);
GNUNET_assert (NULL != hosts);
shutdown_id =
GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (2), &do_shutdown, NULL);
Modified: gnunet/src/testbed/testbed_api_hosts.c
===================================================================
--- gnunet/src/testbed/testbed_api_hosts.c 2012-10-11 20:45:08 UTC (rev
24279)
+++ gnunet/src/testbed/testbed_api_hosts.c 2012-10-11 21:23:06 UTC (rev
24280)
@@ -288,7 +288,8 @@
* Load a set of hosts from a configuration file.
*
* @param filename file with the host specification
- * @param hosts set to the hosts found in the file
+ * @param hosts set to the hosts found in the file; caller must free this if
+ * number of hosts returned is greater than 0
* @return number of hosts returned in 'hosts', 0 on error
*/
unsigned int
@@ -339,6 +340,8 @@
if (((data[offset] == '\n')) && (buf != &data[offset]))
{
data[offset] = '\0';
+ username = NULL;
+ hostname = NULL;
ret = SSCANF (buf, "address@hidden:%hd",
&username, &hostname, &port);
if (3 == ret)
@@ -347,19 +350,19 @@
"Successfully read host %s, port %d and user %s from
file\n",
hostname, port, username);
/* We store hosts in a static list; hence we only require the starting
- host pointer in that list to get the newly created list of hosts */
+ host pointer in that list to access the newly created list of hosts
*/
if (NULL == starting_host)
starting_host = GNUNET_TESTBED_host_create (hostname, username,
port);
else
(void) GNUNET_TESTBED_host_create (hostname, username, port);
count++;
- GNUNET_free (hostname);
- GNUNET_free (username);
}
else
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Error reading line `%s' in hostfile\n", buf);
+ GNUNET_free_non_null (hostname);
+ GNUNET_free_non_null (username);
buf = &data[offset + 1];
}
else if ((data[offset] == '\n') || (data[offset] == '\0'))
@@ -368,7 +371,10 @@
GNUNET_free (data);
if (NULL == starting_host)
return 0;
- *hosts = &host_list[GNUNET_TESTBED_host_get_id_ (starting_host)];
+ *hosts = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Host *) * count);
+ memcpy (*hosts,
+ &host_list[GNUNET_TESTBED_host_get_id_ (starting_host)],
+ sizeof (struct GNUNET_TESTBED_Host *) * count);
return count;
}
@@ -411,10 +417,9 @@
break;
host_list_size -= HOST_LIST_GROW_STEP;
}
- if (orig_size != host_list_size)
- host_list =
- GNUNET_realloc (host_list,
- sizeof (struct GNUNET_TESTBED_Host *) *
host_list_size);
+ host_list =
+ GNUNET_realloc (host_list,
+ sizeof (struct GNUNET_TESTBED_Host *) * host_list_size);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r24280 - in gnunet/src: include testbed,
gnunet <=