mirror of
https://github.com/moparisthebest/curl
synced 2025-03-01 01:41:50 -05:00
curl tool: fix some OOM handling
This commit is contained in:
parent
d9f686db88
commit
f4853db5e6
@ -30,6 +30,7 @@
|
|||||||
#include "curlx.h"
|
#include "curlx.h"
|
||||||
|
|
||||||
#include "tool_cfgable.h"
|
#include "tool_cfgable.h"
|
||||||
|
#include "tool_msgs.h"
|
||||||
#include "tool_cb_hdr.h"
|
#include "tool_cb_hdr.h"
|
||||||
|
|
||||||
#include "memdebug.h" /* keep this as LAST include */
|
#include "memdebug.h" /* keep this as LAST include */
|
||||||
@ -47,6 +48,21 @@ size_t tool_header_cb(void *ptr, size_t size, size_t nmemb, void *userdata)
|
|||||||
const size_t cb = size * nmemb;
|
const size_t cb = size * nmemb;
|
||||||
const char *end = (char*)ptr + cb;
|
const char *end = (char*)ptr + cb;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Once that libcurl has called back tool_header_cb() the returned value
|
||||||
|
* is checked against the amount that was intended to be written, if
|
||||||
|
* it does not match then it fails with CURLE_WRITE_ERROR. So at this
|
||||||
|
* point returning a value different from sz*nmemb indicates failure.
|
||||||
|
*/
|
||||||
|
size_t failure = (size * nmemb) ? 0 : 1;
|
||||||
|
|
||||||
|
#ifdef DEBUGBUILD
|
||||||
|
if(sz * nmemb > (size_t)CURL_MAX_WRITE_SIZE) {
|
||||||
|
warnf(config, "Header data exceeds single call write limit!\n");
|
||||||
|
return failure;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if(cb > 20 && checkprefix("Content-disposition:", str)) {
|
if(cb > 20 && checkprefix("Content-disposition:", str)) {
|
||||||
const char *p = str + 20;
|
const char *p = str + 20;
|
||||||
|
|
||||||
@ -74,12 +90,13 @@ size_t tool_header_cb(void *ptr, size_t size, size_t nmemb, void *userdata)
|
|||||||
*/
|
*/
|
||||||
len = (ssize_t)cb - (p - str);
|
len = (ssize_t)cb - (p - str);
|
||||||
filename = parse_filename(p, len);
|
filename = parse_filename(p, len);
|
||||||
/* TODO: OOM handling - return (size_t)-1 ? */
|
|
||||||
if(filename) {
|
if(filename) {
|
||||||
outs->filename = filename;
|
outs->filename = filename;
|
||||||
outs->alloc_filename = TRUE;
|
outs->alloc_filename = TRUE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
return failure;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,11 +174,11 @@ static char *parse_filename(const char *ptr, size_t len)
|
|||||||
if(copy != p)
|
if(copy != p)
|
||||||
memmove(copy, p, strlen(p) + 1);
|
memmove(copy, p, strlen(p) + 1);
|
||||||
|
|
||||||
/* in case we built curl debug enabled, we allow an evironment variable
|
/* in case we built debug enabled, we allow an evironment variable
|
||||||
* named CURL_TESTDIR to prefix the given file name to put it into a
|
* named CURL_TESTDIR to prefix the given file name to put it into a
|
||||||
* specific directory
|
* specific directory
|
||||||
*/
|
*/
|
||||||
#ifdef CURLDEBUG
|
#ifdef DEBUGBUILD
|
||||||
{
|
{
|
||||||
char *tdir = curlx_getenv("CURL_TESTDIR");
|
char *tdir = curlx_getenv("CURL_TESTDIR");
|
||||||
if(tdir) {
|
if(tdir) {
|
||||||
|
@ -51,6 +51,13 @@ size_t tool_write_cb(void *buffer, size_t sz, size_t nmemb, void *userdata)
|
|||||||
*/
|
*/
|
||||||
const size_t err_rc = (sz * nmemb) ? 0 : 1;
|
const size_t err_rc = (sz * nmemb) ? 0 : 1;
|
||||||
|
|
||||||
|
#ifdef DEBUGBUILD
|
||||||
|
if(sz * nmemb > (size_t)CURL_MAX_WRITE_SIZE) {
|
||||||
|
warnf(config, "Data size exceeds single call write limit!\n");
|
||||||
|
return err_rc; /* Failure */
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if(!out->stream) {
|
if(!out->stream) {
|
||||||
out->bytes = 0; /* nothing written yet */
|
out->bytes = 0; /* nothing written yet */
|
||||||
if(!out->filename) {
|
if(!out->filename) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user