[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnurl] 46/73: cli tool: use file2memory() to buffer stdin
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnurl] 46/73: cli tool: use file2memory() to buffer stdin in -F option. |
Date: |
Tue, 24 Oct 2017 18:54:27 +0200 |
This is an automated email from the git hooks/post-receive script.
ng0 pushed a commit to branch master
in repository gnurl.
commit 56509055d23986479f472d667625426f51074992
Author: Patrick Monnerat <address@hidden>
AuthorDate: Thu Oct 12 16:42:02 2017 +0100
cli tool: use file2memory() to buffer stdin in -F option.
Closes PR https://github.com/curl/curl/pull/1985
---
src/tool_formparse.c | 53 +++++++++++++++-------------------------------------
1 file changed, 15 insertions(+), 38 deletions(-)
diff --git a/src/tool_formparse.c b/src/tool_formparse.c
index 976c3b795..b763d88a5 100644
--- a/src/tool_formparse.c
+++ b/src/tool_formparse.c
@@ -32,12 +32,12 @@
#include "tool_convert.h"
#include "tool_msgs.h"
#include "tool_binmode.h"
+#include "tool_getparam.h"
+#include "tool_paramhlp.h"
#include "tool_formparse.h"
#include "memdebug.h" /* keep this as LAST include */
-#define STDIN_BUFSIZE 0x4000 /* Always have 16K to read more stdin data. */
-
/* Stdin parameters. */
typedef struct {
char *data; /* Memory data. */
@@ -474,47 +474,24 @@ static CURLcode file_or_stdin(curl_mimepart *part, const
char *file)
if(sip->size < 0)
sip->size = 0;
}
- else {
- /* Not suitable for direct use, buffer stdin data. */
+ else { /* Not suitable for direct use, buffer stdin data. */
+ size_t stdinsize = 0;
+
sip->origin = 0;
- sip->size = 0;
- sip->curpos = STDIN_BUFSIZE;
- sip->data = malloc(STDIN_BUFSIZE);
- if(!sip->data) {
- stdin_free(sip);
- return CURLE_OUT_OF_MEMORY;
- }
- for(;;) {
- size_t wantbytes = (size_t) (sip->curpos - sip->size);
- size_t havebytes = fread(sip->data + (size_t) sip->size, 1, wantbytes,
- stdin);
- char *p;
-
- sip->size += havebytes;
- if(ferror(stdin)) {
- stdin_free(sip);
- return CURLE_READ_ERROR;
- }
- if(!havebytes || feof(stdin))
- break;
-
- /* Enlarge data buffer. */
- p = realloc(sip->data, (size_t) sip->size + STDIN_BUFSIZE);
- if(!p) {
- stdin_free(sip);
- return CURLE_OUT_OF_MEMORY;
- }
- sip->data = p;
- sip->curpos = sip->size + STDIN_BUFSIZE;
+ if(file2memory(&sip->data, &stdinsize, stdin) != PARAM_OK)
+ result = CURLE_OUT_OF_MEMORY;
+ else {
+ if(!stdinsize)
+ sip->data = NULL; /* Has been freed if no data. */
+ sip->size = stdinsize;
+ if(ferror(stdin))
+ result = CURLE_READ_ERROR;
}
- /* Shrink buffer to spare memory resources. */
- if(sip->size < sip->curpos)
- sip->data = realloc(sip->data, (size_t) sip->size);
}
- sip->curpos = 0; /* Rewind. */
/* Set remote file name. */
- result = curl_mime_filename(part, file);
+ if(!result)
+ result = curl_mime_filename(part, file);
/* Set part's data from callback. */
if(!result)
--
To stop receiving notification emails like this one, please contact
address@hidden
- [GNUnet-SVN] [gnurl] 37/73: smtp_done: free data before returning (on send failure), (continued)
- [GNUnet-SVN] [gnurl] 37/73: smtp_done: free data before returning (on send failure), gnunet, 2017/10/24
- [GNUnet-SVN] [gnurl] 21/73: curlver.h: next expected release is 7.57.0, gnunet, 2017/10/24
- [GNUnet-SVN] [gnurl] 27/73: ftpserver: properly reset $ftptargetdir., gnunet, 2017/10/24
- [GNUnet-SVN] [gnurl] 36/73: FTP: URL decode path for dir listing in nocwd mode, gnunet, 2017/10/24
- [GNUnet-SVN] [gnurl] 31/73: openssl: enable PKCS12 support for !BoringSSL, gnunet, 2017/10/24
- [GNUnet-SVN] [gnurl] 40/73: openssl: don't use old BORINGSSL_YYYYMM macros, gnunet, 2017/10/24
- [GNUnet-SVN] [gnurl] 41/73: url: Update current connection SSL verify params in setopt, gnunet, 2017/10/24
- [GNUnet-SVN] [gnurl] 29/73: mime: properly unbind mime structure in curl_mime_free()., gnunet, 2017/10/24
- [GNUnet-SVN] [gnurl] 32/73: FAQ: s/CURLOPT_PROGRESSFUNCTION/CURLOPT_XFERINFOFUNCTION, gnunet, 2017/10/24
- [GNUnet-SVN] [gnurl] 34/73: CURLOPT_XFERINFODATA.3: fix duplicate see also, gnunet, 2017/10/24
- [GNUnet-SVN] [gnurl] 46/73: cli tool: use file2memory() to buffer stdin in -F option.,
gnunet <=
- [GNUnet-SVN] [gnurl] 25/73: mime: refuse to add subparts to one of their own descendants., gnunet, 2017/10/24
- [GNUnet-SVN] [gnurl] 55/73: makefile.m32: allow to override gcc, ar and ranlib, gnunet, 2017/10/24
- [GNUnet-SVN] [gnurl] 50/73: mime: do not call failf() if easy handle is NULL., gnunet, 2017/10/24
- [GNUnet-SVN] [gnurl] 53/73: runtests: use valgrind for torture as well, gnunet, 2017/10/24
- [GNUnet-SVN] [gnurl] 49/73: test651: curl_formadd with huge COPYCONTENTS, gnunet, 2017/10/24
- [GNUnet-SVN] [gnurl] 63/73: runtests: support MultiSSL client feature, gnunet, 2017/10/24
- [GNUnet-SVN] [gnurl] 58/73: RELEASE-NOTES: synced with f121575c0, gnunet, 2017/10/24
- [GNUnet-SVN] [gnurl] 65/73: mime: do not reuse previously computed multipart size, gnunet, 2017/10/24
- [GNUnet-SVN] [gnurl] 59/73: mime: limit bas64-encoded lines length to 76 characters, gnunet, 2017/10/24
- [GNUnet-SVN] [gnurl] 69/73: mk-ca-bundle: Fix URL for NSS, gnunet, 2017/10/24