[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnurl] 134/411: curl: make glob_match_url use dynbuf
From: |
gnunet |
Subject: |
[gnurl] 134/411: curl: make glob_match_url use dynbuf |
Date: |
Wed, 13 Jan 2021 01:19:09 +0100 |
This is an automated email from the git hooks/post-receive script.
nikita pushed a commit to branch master
in repository gnurl.
commit 70a3b003d964abad49635ba00b111b84a6c52afd
Author: Daniel Stenberg <daniel@haxx.se>
AuthorDate: Fri Sep 11 11:01:24 2020 +0200
curl: make glob_match_url use dynbuf
Closes #5952
---
src/tool_urlglob.c | 46 +++++++++++++++-------------------------------
1 file changed, 15 insertions(+), 31 deletions(-)
diff --git a/src/tool_urlglob.c b/src/tool_urlglob.c
index 430ca88ba..96c514493 100644
--- a/src/tool_urlglob.c
+++ b/src/tool_urlglob.c
@@ -28,6 +28,7 @@
#include "tool_doswin.h"
#include "tool_urlglob.h"
#include "tool_vms.h"
+#include "dynbuf.h"
#include "memdebug.h" /* keep this as LAST include */
@@ -607,26 +608,21 @@ CURLcode glob_next_url(char **globbed, struct URLGlob
*glob)
return CURLE_OK;
}
+#define MAX_OUTPUT_GLOB_LENGTH (10*1024)
+
CURLcode glob_match_url(char **result, char *filename, struct URLGlob *glob)
{
- char *target;
- size_t allocsize;
char numbuf[18];
char *appendthis = (char *)"";
size_t appendlen = 0;
- size_t stringlen = 0;
+ struct curlx_dynbuf dyn;
*result = NULL;
- /* We cannot use the glob_buffer for storage here since the filename may
- * be longer than the URL we use. We allocate a good start size, then
- * we need to realloc in case of need.
+ /* We cannot use the glob_buffer for storage since the filename may be
+ * longer than the URL we use.
*/
- allocsize = strlen(filename) + 1; /* make it at least one byte to store the
- trailing zero */
- target = malloc(allocsize);
- if(!target)
- return CURLE_OUT_OF_MEMORY;
+ curlx_dyn_init(&dyn, MAX_OUTPUT_GLOB_LENGTH);
while(*filename) {
if(*filename == '#' && ISDIGIT(filename[1])) {
@@ -671,7 +667,7 @@ CURLcode glob_match_url(char **result, char *filename,
struct URLGlob *glob)
default:
fprintf(stderr, "internal error: invalid pattern type (%d)\n",
(int)pat->type);
- Curl_safefree(target);
+ curlx_dyn_free(&dyn);
return CURLE_FAILED_INIT;
}
}
@@ -686,36 +682,24 @@ CURLcode glob_match_url(char **result, char *filename,
struct URLGlob *glob)
appendthis = filename++;
appendlen = 1;
}
- if(appendlen + stringlen >= allocsize) {
- char *newstr;
- /* we append a single byte to allow for the trailing byte to be appended
- at the end of this function outside the while() loop */
- allocsize = (appendlen + stringlen) * 2;
- newstr = realloc(target, allocsize + 1);
- if(!newstr) {
- Curl_safefree(target);
- return CURLE_OUT_OF_MEMORY;
- }
- target = newstr;
- }
- memcpy(&target[stringlen], appendthis, appendlen);
- stringlen += appendlen;
+ if(curlx_dyn_addn(&dyn, appendthis, appendlen))
+ return CURLE_OUT_OF_MEMORY;
}
- target[stringlen]= '\0';
#if defined(MSDOS) || defined(WIN32)
{
char *sanitized;
- SANITIZEcode sc = sanitize_file_name(&sanitized, target,
+ SANITIZEcode sc = sanitize_file_name(&sanitized, curlx_dyn_ptr(&dyn),
(SANITIZE_ALLOW_PATH |
SANITIZE_ALLOW_RESERVED));
- Curl_safefree(target);
+ curlx_dyn_free(&dyn);
if(sc)
return CURLE_URL_MALFORMAT;
- target = sanitized;
+ *result = sanitized;
+ return CURLE_OK;
}
#endif /* MSDOS || WIN32 */
- *result = target;
+ *result = curlx_dyn_ptr(&dyn);
return CURLE_OK;
}
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [gnurl] 117/411: lib583: fix enum mixup, (continued)
- [gnurl] 117/411: lib583: fix enum mixup, gnunet, 2021/01/12
- [gnurl] 114/411: RELEASE-NOTES: synced, gnunet, 2021/01/12
- [gnurl] 120/411: base64: also build for pop3 and imap, gnunet, 2021/01/12
- [gnurl] 89/411: libssh2: pass on the error from ssh_force_knownhost_key_type, gnunet, 2021/01/12
- [gnurl] 119/411: base64: enable in build with SMTP, gnunet, 2021/01/12
- [gnurl] 122/411: http: consolidate nghttp2_session_mem_recv() call paths, gnunet, 2021/01/12
- [gnurl] 115/411: lib: fix -Wassign-enum warnings, gnunet, 2021/01/12
- [gnurl] 118/411: curl_mime_headers.3: fix the example's use of curl_slist_append, gnunet, 2021/01/12
- [gnurl] 113/411: url: use blank credentials when using proxy w/o username and password, gnunet, 2021/01/12
- [gnurl] 136/411: ftp: a 550 response to SIZE returns CURLE_REMOTE_FILE_NOT_FOUND, gnunet, 2021/01/12
- [gnurl] 134/411: curl: make glob_match_url use dynbuf,
gnunet <=
- [gnurl] 105/411: CI/azure: add test number to title for display in analytics, gnunet, 2021/01/12
- [gnurl] 87/411: http_proxy: do not crash with HTTPS_PROXY and NO_PROXY set, gnunet, 2021/01/12
- [gnurl] 102/411: tests: remove pipelining tests, gnunet, 2021/01/12
- [gnurl] 126/411: dynbuf: provide curlx_ names for reuse by the curl tool, gnunet, 2021/01/12
- [gnurl] 121/411: HISTORY: mention alt-svc added in 2019, gnunet, 2021/01/12
- [gnurl] 96/411: easygetopt: pass a valid enum to avoid compiler warning, gnunet, 2021/01/12
- [gnurl] 94/411: tool: update --help with categories, gnunet, 2021/01/12
- [gnurl] 104/411: altsvc: clone setting in curl_easy_duphandle, gnunet, 2021/01/12
- [gnurl] 112/411: travis: add a build using libressl (from git master), gnunet, 2021/01/12
- [gnurl] 131/411: imap: set cselect_bits to CURL_CSELECT_IN initially, gnunet, 2021/01/12