diff options
author | Yang Tse <yangsita@gmail.com> | 2011-09-25 18:53:29 +0200 |
---|---|---|
committer | Yang Tse <yangsita@gmail.com> | 2011-09-25 19:05:46 +0200 |
commit | 119f43360b60c903982104944145d9cd8b7ec054 (patch) | |
tree | 7cba5f3f98a946c0dca572eb22a2f48e98c5ee10 /src/tool_cb_hdr.c | |
parent | e276802ff84d58aa2484f8292651dad4c50a5407 (diff) | |
download | curl-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 'src/tool_cb_hdr.c')
-rw-r--r-- | src/tool_cb_hdr.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/tool_cb_hdr.c b/src/tool_cb_hdr.c index 2643ad2cf..6dcc9f46a 100644 --- a/src/tool_cb_hdr.c +++ b/src/tool_cb_hdr.c @@ -47,6 +47,10 @@ size_t tool_header_cb(void *ptr, size_t size, size_t nmemb, void *userdata) const size_t cb = size * nmemb; const char *end = (char*)ptr + cb; + if(cb >= CURL_WRITEFUNC_PAUSE) + /* CURL_WRITEFUNC_PAUSE limits input size */ + return CURL_WRITEFUNC_OUT_OF_MEMORY; + if(cb > 20 && checkprefix("Content-disposition:", str)) { const char *p = str + 20; @@ -74,12 +78,13 @@ size_t tool_header_cb(void *ptr, size_t size, size_t nmemb, void *userdata) */ len = (ssize_t)cb - (p - str); filename = parse_filename(p, len); - /* TODO: OOM handling - return (size_t)-1 ? */ if(filename) { outs->filename = filename; outs->alloc_filename = TRUE; break; } + else + return CURL_WRITEFUNC_OUT_OF_MEMORY; } } |