summaryrefslogtreecommitdiff
path: root/lib/telnet.c
diff options
context:
space:
mode:
authorYang Tse <yangsita@gmail.com>2011-10-07 20:50:57 +0200
committerYang Tse <yangsita@gmail.com>2011-10-07 20:50:57 +0200
commit17f48fe87979f159e2d8769d678641c60f4c0eed (patch)
tree322c1d34d9c8d0a4d203d127765818f297ac93c7 /lib/telnet.c
parentb82bd05354cfa756a013d2bed4ffdc951ce903db (diff)
downloadcurl-17f48fe87979f159e2d8769d678641c60f4c0eed.tar.gz
libcurl: some OOM handling fixes
Diffstat (limited to 'lib/telnet.c')
-rw-r--r--lib/telnet.c35
1 files changed, 26 insertions, 9 deletions
diff --git a/lib/telnet.c b/lib/telnet.c
index 5af7c3970..d1bc43cc9 100644
--- a/lib/telnet.c
+++ b/lib/telnet.c
@@ -763,18 +763,25 @@ static void printsub(struct SessionHandle *data,
static CURLcode check_telnet_options(struct connectdata *conn)
{
struct curl_slist *head;
+ struct curl_slist *beg;
char option_keyword[128];
char option_arg[256];
char *buf;
struct SessionHandle *data = conn->data;
struct TELNET *tn = (struct TELNET *)conn->data->state.proto.telnet;
+ CURLcode result = CURLE_OK;
/* Add the user name as an environment variable if it
was given on the command line */
if(conn->bits.user_passwd) {
snprintf(option_arg, sizeof(option_arg), "USER,%s", conn->user);
- tn->telnet_vars = curl_slist_append(tn->telnet_vars, option_arg);
-
+ beg = curl_slist_append(tn->telnet_vars, option_arg);
+ if(!beg) {
+ curl_slist_free_all(tn->telnet_vars);
+ tn->telnet_vars = NULL;
+ return CURLE_OUT_OF_MEMORY;
+ }
+ tn->telnet_vars = beg;
tn->us_preferred[CURL_TELOPT_NEW_ENVIRON] = CURL_YES;
}
@@ -800,24 +807,33 @@ static CURLcode check_telnet_options(struct connectdata *conn)
/* Environment variable */
if(Curl_raw_equal(option_keyword, "NEW_ENV")) {
- buf = strdup(option_arg);
- if(!buf)
- return CURLE_OUT_OF_MEMORY;
- tn->telnet_vars = curl_slist_append(tn->telnet_vars, buf);
+ beg = curl_slist_append(tn->telnet_vars, option_arg);
+ if(!beg) {
+ result = CURLE_OUT_OF_MEMORY;
+ break;
+ }
+ tn->telnet_vars = beg;
tn->us_preferred[CURL_TELOPT_NEW_ENVIRON] = CURL_YES;
continue;
}
failf(data, "Unknown telnet option %s", head->data);
- return CURLE_UNKNOWN_TELNET_OPTION;
+ result = CURLE_UNKNOWN_TELNET_OPTION;
+ break;
}
else {
failf(data, "Syntax error in telnet option: %s", head->data);
- return CURLE_TELNET_OPTION_SYNTAX;
+ result = CURLE_TELNET_OPTION_SYNTAX;
+ break;
}
}
- return CURLE_OK;
+ if(result) {
+ curl_slist_free_all(tn->telnet_vars);
+ tn->telnet_vars = NULL;
+ }
+
+ return result;
}
/*
@@ -1109,6 +1125,7 @@ static CURLcode telnet_done(struct connectdata *conn,
(void)premature; /* not used */
curl_slist_free_all(tn->telnet_vars);
+ tn->telnet_vars = NULL;
free(conn->data->state.proto.telnet);
conn->data->state.proto.telnet = NULL;