projects
/
oweals
/
gnunet.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
3e820b5
)
fixes for invalid reads
author
Sree Harsha Totakura
<totakura@in.tum.de>
Thu, 11 Oct 2012 21:23:06 +0000
(21:23 +0000)
committer
Sree Harsha Totakura
<totakura@in.tum.de>
Thu, 11 Oct 2012 21:23:06 +0000
(21:23 +0000)
src/include/gnunet_testbed_service.h
patch
|
blob
|
history
src/testbed/sample_hosts.txt
patch
|
blob
|
history
src/testbed/test_testbed_api_hosts.c
patch
|
blob
|
history
src/testbed/testbed_api_hosts.c
patch
|
blob
|
history
diff --git
a/src/include/gnunet_testbed_service.h
b/src/include/gnunet_testbed_service.h
index 065cd0c0ff4811e0267b64a964db888d51038907..ba3b8961f46e9e938410fb22f5dc367472b0f98a 100644
(file)
--- a/
src/include/gnunet_testbed_service.h
+++ b/
src/include/gnunet_testbed_service.h
@@
-113,7
+113,8
@@
GNUNET_TESTBED_host_create_with_id (uint32_t id,
* Load a set of hosts from a configuration file.
*
* @param filename file with the host specification
* 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
* @return number of hosts returned in 'hosts', 0 on error
*/
unsigned int
diff --git
a/src/testbed/sample_hosts.txt
b/src/testbed/sample_hosts.txt
index 61b07f3c29419e211f58f902f1bfe9cd45510ab1..5b661696bc13c2ca71980fafdbab2ff3df0bc24c 100644
(file)
--- a/
src/testbed/sample_hosts.txt
+++ b/
src/testbed/sample_hosts.txt
@@
-3,3
+3,13
@@
totakura@192.168.0.2:22
totakura@192.168.0.3:22
totakura@192.168.0.4:22
totakura@192.168.0.5:22
totakura@192.168.0.3:22
totakura@192.168.0.4:22
totakura@192.168.0.5:22
+totakura@192.168.0.6:22
+totakura@192.168.0.7:22
+totakura@192.168.0.8:22
+totakura@192.168.0.9:22
+totakura@192.168.0.10:22
+totakura@192.168.0.11:22
+totakura@192.168.0.12:22
+totakura@192.168.0.13:22
+totakura@192.168.0.14:22
+totakura@192.168.0.15:22
diff --git
a/src/testbed/test_testbed_api_hosts.c
b/src/testbed/test_testbed_api_hosts.c
index e98bc8e21591570ab18c0d9ca8d4835185df7220..0102b9e26ed9630de95b09a2afec2e23744531cc 100644
(file)
--- a/
src/testbed/test_testbed_api_hosts.c
+++ b/
src/testbed/test_testbed_api_hosts.c
@@
-73,6
+73,7
@@
do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
GNUNET_TESTBED_host_destroy (hosts[num_hosts - 1]);
num_hosts--;
}
GNUNET_TESTBED_host_destroy (hosts[num_hosts - 1]);
num_hosts--;
}
+ GNUNET_free (hosts);
}
}
@@
-99,7
+100,7
@@
run (void *cls, char *const *args, const char *cfgfile,
hosts = NULL;
num_hosts = GNUNET_TESTBED_hosts_load_from_file ("sample_hosts.txt",
&hosts);
hosts = NULL;
num_hosts = GNUNET_TESTBED_hosts_load_from_file ("sample_hosts.txt",
&hosts);
- GNUNET_assert (5 == num_hosts);
+ GNUNET_assert (
1
5 == num_hosts);
GNUNET_assert (NULL != hosts);
shutdown_id =
GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (2), &do_shutdown, NULL);
GNUNET_assert (NULL != hosts);
shutdown_id =
GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (2), &do_shutdown, NULL);
diff --git
a/src/testbed/testbed_api_hosts.c
b/src/testbed/testbed_api_hosts.c
index 91fffc92d57b97ae6d925046c87e97ae9c458522..4a69a17ddb36a995b3f0c0487491c81b94aabb3e 100644
(file)
--- a/
src/testbed/testbed_api_hosts.c
+++ b/
src/testbed/testbed_api_hosts.c
@@
-288,7
+288,8
@@
GNUNET_TESTBED_host_create (const char *hostname, const char *username,
* Load a set of hosts from a configuration file.
*
* @param filename file with the host specification
* 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
* @return number of hosts returned in 'hosts', 0 on error
*/
unsigned int
@@
-339,6
+340,8
@@
GNUNET_TESTBED_hosts_load_from_file (const char *filename,
if (((data[offset] == '\n')) && (buf != &data[offset]))
{
data[offset] = '\0';
if (((data[offset] == '\n')) && (buf != &data[offset]))
{
data[offset] = '\0';
+ username = NULL;
+ hostname = NULL;
ret = SSCANF (buf, "%a[a-zA-Z0-9_]@%a[a-zA-Z0-9.]:%hd",
&username, &hostname, &port);
if (3 == ret)
ret = SSCANF (buf, "%a[a-zA-Z0-9_]@%a[a-zA-Z0-9.]:%hd",
&username, &hostname, &port);
if (3 == ret)
@@
-347,19
+350,19
@@
GNUNET_TESTBED_hosts_load_from_file (const char *filename,
"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
"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++;
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);
}
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'))
buf = &data[offset + 1];
}
else if ((data[offset] == '\n') || (data[offset] == '\0'))
@@
-368,7
+371,10
@@
GNUNET_TESTBED_hosts_load_from_file (const char *filename,
GNUNET_free (data);
if (NULL == starting_host)
return 0;
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;
}
return count;
}
@@
-411,10
+417,9
@@
GNUNET_TESTBED_host_destroy (struct GNUNET_TESTBED_Host *host)
break;
host_list_size -= HOST_LIST_GROW_STEP;
}
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);
}
}