[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [torsocks/master] Fix: check strdup return value
commit c54460b94e2a552a9e1fbe65c9f34210d4d1277a
Author: David Goulet <dgoulet@xxxxxxxxx>
Date: Thu Feb 20 11:05:57 2014 +0000
Fix: check strdup return value
Reported-by: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Signed-off-by: David Goulet <dgoulet@xxxxxxxxx>
---
src/common/utils.c | 8 ++++++++
src/lib/connect.c | 6 +++++-
src/lib/torsocks.c | 4 ++++
3 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/src/common/utils.c b/src/common/utils.c
index 578d290..3a62f6c 100644
--- a/src/common/utils.c
+++ b/src/common/utils.c
@@ -125,6 +125,10 @@ int utils_tokenize_ignore_comments(const char *_line, size_t size, char **tokens
assert(tokens);
line = strdup(_line);
+ if (!line) {
+ ret = -ENOMEM;
+ goto error;
+ }
/* Ignore line if it starts with a # meaning a comment. */
if (*line == '#') {
@@ -149,6 +153,10 @@ int utils_tokenize_ignore_comments(const char *_line, size_t size, char **tokens
c = strtok(line, " \t");
while (c != NULL) {
tokens[i] = strdup(c);
+ if (!tokens[i]) {
+ ret = -ENOMEM;
+ goto error;
+ }
c = strtok(NULL, " \t");
i++;
}
diff --git a/src/lib/connect.c b/src/lib/connect.c
index e47ab38..03f6900 100644
--- a/src/lib/connect.c
+++ b/src/lib/connect.c
@@ -113,8 +113,12 @@ LIBC_CONNECT_RET_TYPE tsocks_connect(LIBC_CONNECT_SIG)
goto error;
}
new_conn->dest_addr.domain = CONNECTION_DOMAIN_NAME;
- new_conn->dest_addr.hostname.addr = strdup(on_entry->hostname);
new_conn->dest_addr.hostname.port = inet_addr->sin_port;
+ new_conn->dest_addr.hostname.addr = strdup(on_entry->hostname);
+ if (!new_conn->dest_addr.hostname.addr) {
+ errno = ENOMEM;
+ goto error;
+ }
} else {
/*
* Check if address is localhost. At this point, we are sure it's not a
diff --git a/src/lib/torsocks.c b/src/lib/torsocks.c
index ba7142d..654f825 100644
--- a/src/lib/torsocks.c
+++ b/src/lib/torsocks.c
@@ -92,6 +92,10 @@ static void init_config(void)
*/
if (!tsocks_config.conf_file.tor_address) {
tsocks_config.conf_file.tor_address = strdup(DEFAULT_TOR_ADDRESS);
+ if (!tsocks_config.conf_file.tor_address) {
+ /* Most likely ENOMEM thus we can't continue. */
+ clean_exit(EXIT_FAILURE);
+ }
}
if (tsocks_config.conf_file.tor_port == 0) {
tsocks_config.conf_file.tor_port = DEFAULT_TOR_PORT;
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits