summaryrefslogtreecommitdiff
path: root/lib/ftplistparser.c
diff options
context:
space:
mode:
authorYang Tse <yangsita@gmail.com>2011-09-25 18:53:29 +0200
committerYang Tse <yangsita@gmail.com>2011-09-25 19:05:46 +0200
commit119f43360b60c903982104944145d9cd8b7ec054 (patch)
tree7cba5f3f98a946c0dca572eb22a2f48e98c5ee10 /lib/ftplistparser.c
parente276802ff84d58aa2484f8292651dad4c50a5407 (diff)
downloadcurl-119f43360b60c903982104944145d9cd8b7ec054.tar.gz
allow write callbacks to indicate OOM to libcurl
Allow (*curl_write_callback) write callbacks to return CURL_WRITEFUNC_OUT_OF_MEMORY to properly indicate libcurl of OOM conditions inside the callback itself.
Diffstat (limited to 'lib/ftplistparser.c')
-rw-r--r--lib/ftplistparser.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/ftplistparser.c b/lib/ftplistparser.c
index bbf6e9ef9..12ee51d86 100644
--- a/lib/ftplistparser.c
+++ b/lib/ftplistparser.c
@@ -354,6 +354,8 @@ static CURLcode ftp_pl_insert_finfo(struct connectdata *conn,
return CURLE_OK;
}
+/* Curl_ftp_parselist is a write callback function */
+
size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
void *connptr)
{
@@ -365,6 +367,10 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
unsigned long i = 0;
CURLcode rc;
+ if(bufflen >= CURL_WRITEFUNC_PAUSE)
+ /* CURL_WRITEFUNC_PAUSE limits input size */
+ return CURL_WRITEFUNC_OUT_OF_MEMORY;
+
if(parser->error) { /* error in previous call */
/* scenario:
* 1. call => OK..
@@ -372,6 +378,9 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
* 3. (last) call => is skipped RIGHT HERE and the error is hadled later
* in wc_statemach()
*/
+ if(parser->error == CURLE_OUT_OF_MEMORY)
+ return CURL_WRITEFUNC_OUT_OF_MEMORY;
+
return bufflen;
}
@@ -388,12 +397,12 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->file_data = Curl_fileinfo_alloc();
if(!parser->file_data) {
parser->error = CURLE_OUT_OF_MEMORY;
- return bufflen;
+ return CURL_WRITEFUNC_OUT_OF_MEMORY;
}
parser->file_data->b_data = malloc(FTP_BUFFER_ALLOCSIZE);
if(!parser->file_data->b_data) {
PL_ERROR(conn, CURLE_OUT_OF_MEMORY);
- return bufflen;
+ return CURL_WRITEFUNC_OUT_OF_MEMORY;
}
parser->file_data->b_size = FTP_BUFFER_ALLOCSIZE;
parser->item_offset = 0;
@@ -416,7 +425,7 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->file_data = NULL;
parser->error = CURLE_OUT_OF_MEMORY;
PL_ERROR(conn, CURLE_OUT_OF_MEMORY);
- return bufflen;
+ return CURL_WRITEFUNC_OUT_OF_MEMORY;
}
}