Loading src/tool_operate.c +22 −8 Original line number Original line Diff line number Diff line Loading @@ -441,10 +441,18 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[]) if(!up && !infiles) if(!up && !infiles) Curl_nop_stmt; Curl_nop_stmt; else { else { if(inglob) if(inglob) { uploadfile = glob_next_url(inglob); res = glob_next_url(&uploadfile, inglob); else if(!up) if(res == CURLE_OUT_OF_MEMORY) helpf(config->errors, "out of memory\n"); } else if(!up) { uploadfile = strdup(infiles); uploadfile = strdup(infiles); if(!uploadfile) { helpf(config->errors, "out of memory\n"); res = CURLE_OUT_OF_MEMORY; } } else else uploadfile = NULL; uploadfile = NULL; if(!uploadfile) if(!uploadfile) Loading Loading @@ -492,10 +500,17 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[]) outs.stream = stdout; outs.stream = stdout; outs.config = config; outs.config = config; if(urls) if(urls) { this_url = glob_next_url(urls); res = glob_next_url(&this_url, urls); if(res) goto show_error; } else if(!i) { else if(!i) { this_url = strdup(urlnode->url); this_url = strdup(urlnode->url); if(!this_url) { res = CURLE_OUT_OF_MEMORY; goto show_error; } } } else else this_url = NULL; this_url = NULL; Loading Loading @@ -541,12 +556,11 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[]) else if(urls) { else if(urls) { /* fill '#1' ... '#9' terms from URL pattern */ /* fill '#1' ... '#9' terms from URL pattern */ char *storefile = outfile; char *storefile = outfile; outfile = glob_match_url(storefile, urls); res = glob_match_url(&outfile, storefile, urls); Curl_safefree(storefile); Curl_safefree(storefile); if(!outfile) { if(res) { /* bad globbing */ /* bad globbing */ warnf(config, "bad output glob!\n"); warnf(config, "bad output glob!\n"); res = CURLE_FAILED_INIT; goto quit_urls; goto quit_urls; } } } } Loading src/tool_urlglob.c +24 −11 Original line number Original line Diff line number Diff line Loading @@ -419,7 +419,7 @@ void glob_cleanup(URLGlob* glob) Curl_safefree(glob); Curl_safefree(glob); } } char *glob_next_url(URLGlob *glob) int glob_next_url(char **globbed, URLGlob *glob) { { URLPattern *pat; URLPattern *pat; char *lit; char *lit; Loading @@ -429,6 +429,8 @@ char *glob_next_url(URLGlob *glob) size_t buflen = glob->urllen + 1; size_t buflen = glob->urllen + 1; char *buf = glob->glob_buffer; char *buf = glob->glob_buffer; *globbed = NULL; if(!glob->beenhere) if(!glob->beenhere) glob->beenhere = 1; glob->beenhere = 1; else { else { Loading Loading @@ -464,11 +466,13 @@ char *glob_next_url(URLGlob *glob) break; break; default: default: printf("internal error: invalid pattern type (%d)\n", (int)pat->type); printf("internal error: invalid pattern type (%d)\n", (int)pat->type); exit (CURLE_FAILED_INIT); return CURLE_FAILED_INIT; } } } if(carry) { /* first pattern ptr has run into overflow, done! */ /* TODO: verify if this should actally return CURLE_OK. */ return CURLE_OK; /* CURLE_OK to match previous behavior */ } } if(carry) /* first pattern ptr has run into overflow, done! */ return NULL; } } for(j = 0; j < glob->size; ++j) { for(j = 0; j < glob->size; ++j) { Loading Loading @@ -502,15 +506,20 @@ char *glob_next_url(URLGlob *glob) break; break; default: default: printf("internal error: invalid pattern type (%d)\n", (int)pat->type); printf("internal error: invalid pattern type (%d)\n", (int)pat->type); exit (CURLE_FAILED_INIT); return CURLE_FAILED_INIT; } } } } } } *buf = '\0'; *buf = '\0'; return strdup(glob->glob_buffer); *globbed = strdup(glob->glob_buffer); if(!*globbed) return CURLE_OUT_OF_MEMORY; return CURLE_OK; } } char *glob_match_url(char *filename, URLGlob *glob) int glob_match_url(char **result, char *filename, URLGlob *glob) { { char *target; char *target; size_t allocsize; size_t allocsize; Loading @@ -519,6 +528,8 @@ char *glob_match_url(char *filename, URLGlob *glob) size_t appendlen = 0; size_t appendlen = 0; size_t stringlen = 0; size_t stringlen = 0; *result = NULL; /* We cannot use the glob_buffer for storage here since the filename may /* 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 * be longer than the URL we use. We allocate a good start size, then * we need to realloc in case of need. * we need to realloc in case of need. Loading @@ -527,7 +538,7 @@ char *glob_match_url(char *filename, URLGlob *glob) trailing zero */ trailing zero */ target = malloc(allocsize); target = malloc(allocsize); if(!target) if(!target) return NULL; /* major failure */ return CURLE_OUT_OF_MEMORY; while(*filename) { while(*filename) { if(*filename == '#' && ISDIGIT(filename[1])) { if(*filename == '#' && ISDIGIT(filename[1])) { Loading Loading @@ -563,7 +574,7 @@ char *glob_match_url(char *filename, URLGlob *glob) printf("internal error: invalid pattern type (%d)\n", printf("internal error: invalid pattern type (%d)\n", (int)pat.type); (int)pat.type); Curl_safefree(target); Curl_safefree(target); return NULL; return CURLE_FAILED_INIT; } } } } else { else { Loading @@ -585,7 +596,7 @@ char *glob_match_url(char *filename, URLGlob *glob) newstr = realloc(target, allocsize + 1); newstr = realloc(target, allocsize + 1); if(!newstr) { if(!newstr) { Curl_safefree(target); Curl_safefree(target); return NULL; return CURLE_OUT_OF_MEMORY; } } target = newstr; target = newstr; } } Loading @@ -593,5 +604,7 @@ char *glob_match_url(char *filename, URLGlob *glob) stringlen += appendlen; stringlen += appendlen; } } target[stringlen]= '\0'; target[stringlen]= '\0'; return target; *result = target; return CURLE_OK; } } src/tool_urlglob.h +2 −2 Original line number Original line Diff line number Diff line Loading @@ -64,8 +64,8 @@ typedef struct { } URLGlob; } URLGlob; int glob_url(URLGlob**, char*, int *, FILE *); int glob_url(URLGlob**, char*, int *, FILE *); char* glob_next_url(URLGlob*); int glob_next_url(char **, URLGlob *); char* glob_match_url(char*, URLGlob *); int glob_match_url(char **, char*, URLGlob *); void glob_cleanup(URLGlob* glob); void glob_cleanup(URLGlob* glob); #endif /* HEADER_CURL_TOOL_URLGLOB_H */ #endif /* HEADER_CURL_TOOL_URLGLOB_H */ Loading Loading
src/tool_operate.c +22 −8 Original line number Original line Diff line number Diff line Loading @@ -441,10 +441,18 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[]) if(!up && !infiles) if(!up && !infiles) Curl_nop_stmt; Curl_nop_stmt; else { else { if(inglob) if(inglob) { uploadfile = glob_next_url(inglob); res = glob_next_url(&uploadfile, inglob); else if(!up) if(res == CURLE_OUT_OF_MEMORY) helpf(config->errors, "out of memory\n"); } else if(!up) { uploadfile = strdup(infiles); uploadfile = strdup(infiles); if(!uploadfile) { helpf(config->errors, "out of memory\n"); res = CURLE_OUT_OF_MEMORY; } } else else uploadfile = NULL; uploadfile = NULL; if(!uploadfile) if(!uploadfile) Loading Loading @@ -492,10 +500,17 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[]) outs.stream = stdout; outs.stream = stdout; outs.config = config; outs.config = config; if(urls) if(urls) { this_url = glob_next_url(urls); res = glob_next_url(&this_url, urls); if(res) goto show_error; } else if(!i) { else if(!i) { this_url = strdup(urlnode->url); this_url = strdup(urlnode->url); if(!this_url) { res = CURLE_OUT_OF_MEMORY; goto show_error; } } } else else this_url = NULL; this_url = NULL; Loading Loading @@ -541,12 +556,11 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[]) else if(urls) { else if(urls) { /* fill '#1' ... '#9' terms from URL pattern */ /* fill '#1' ... '#9' terms from URL pattern */ char *storefile = outfile; char *storefile = outfile; outfile = glob_match_url(storefile, urls); res = glob_match_url(&outfile, storefile, urls); Curl_safefree(storefile); Curl_safefree(storefile); if(!outfile) { if(res) { /* bad globbing */ /* bad globbing */ warnf(config, "bad output glob!\n"); warnf(config, "bad output glob!\n"); res = CURLE_FAILED_INIT; goto quit_urls; goto quit_urls; } } } } Loading
src/tool_urlglob.c +24 −11 Original line number Original line Diff line number Diff line Loading @@ -419,7 +419,7 @@ void glob_cleanup(URLGlob* glob) Curl_safefree(glob); Curl_safefree(glob); } } char *glob_next_url(URLGlob *glob) int glob_next_url(char **globbed, URLGlob *glob) { { URLPattern *pat; URLPattern *pat; char *lit; char *lit; Loading @@ -429,6 +429,8 @@ char *glob_next_url(URLGlob *glob) size_t buflen = glob->urllen + 1; size_t buflen = glob->urllen + 1; char *buf = glob->glob_buffer; char *buf = glob->glob_buffer; *globbed = NULL; if(!glob->beenhere) if(!glob->beenhere) glob->beenhere = 1; glob->beenhere = 1; else { else { Loading Loading @@ -464,11 +466,13 @@ char *glob_next_url(URLGlob *glob) break; break; default: default: printf("internal error: invalid pattern type (%d)\n", (int)pat->type); printf("internal error: invalid pattern type (%d)\n", (int)pat->type); exit (CURLE_FAILED_INIT); return CURLE_FAILED_INIT; } } } if(carry) { /* first pattern ptr has run into overflow, done! */ /* TODO: verify if this should actally return CURLE_OK. */ return CURLE_OK; /* CURLE_OK to match previous behavior */ } } if(carry) /* first pattern ptr has run into overflow, done! */ return NULL; } } for(j = 0; j < glob->size; ++j) { for(j = 0; j < glob->size; ++j) { Loading Loading @@ -502,15 +506,20 @@ char *glob_next_url(URLGlob *glob) break; break; default: default: printf("internal error: invalid pattern type (%d)\n", (int)pat->type); printf("internal error: invalid pattern type (%d)\n", (int)pat->type); exit (CURLE_FAILED_INIT); return CURLE_FAILED_INIT; } } } } } } *buf = '\0'; *buf = '\0'; return strdup(glob->glob_buffer); *globbed = strdup(glob->glob_buffer); if(!*globbed) return CURLE_OUT_OF_MEMORY; return CURLE_OK; } } char *glob_match_url(char *filename, URLGlob *glob) int glob_match_url(char **result, char *filename, URLGlob *glob) { { char *target; char *target; size_t allocsize; size_t allocsize; Loading @@ -519,6 +528,8 @@ char *glob_match_url(char *filename, URLGlob *glob) size_t appendlen = 0; size_t appendlen = 0; size_t stringlen = 0; size_t stringlen = 0; *result = NULL; /* We cannot use the glob_buffer for storage here since the filename may /* 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 * be longer than the URL we use. We allocate a good start size, then * we need to realloc in case of need. * we need to realloc in case of need. Loading @@ -527,7 +538,7 @@ char *glob_match_url(char *filename, URLGlob *glob) trailing zero */ trailing zero */ target = malloc(allocsize); target = malloc(allocsize); if(!target) if(!target) return NULL; /* major failure */ return CURLE_OUT_OF_MEMORY; while(*filename) { while(*filename) { if(*filename == '#' && ISDIGIT(filename[1])) { if(*filename == '#' && ISDIGIT(filename[1])) { Loading Loading @@ -563,7 +574,7 @@ char *glob_match_url(char *filename, URLGlob *glob) printf("internal error: invalid pattern type (%d)\n", printf("internal error: invalid pattern type (%d)\n", (int)pat.type); (int)pat.type); Curl_safefree(target); Curl_safefree(target); return NULL; return CURLE_FAILED_INIT; } } } } else { else { Loading @@ -585,7 +596,7 @@ char *glob_match_url(char *filename, URLGlob *glob) newstr = realloc(target, allocsize + 1); newstr = realloc(target, allocsize + 1); if(!newstr) { if(!newstr) { Curl_safefree(target); Curl_safefree(target); return NULL; return CURLE_OUT_OF_MEMORY; } } target = newstr; target = newstr; } } Loading @@ -593,5 +604,7 @@ char *glob_match_url(char *filename, URLGlob *glob) stringlen += appendlen; stringlen += appendlen; } } target[stringlen]= '\0'; target[stringlen]= '\0'; return target; *result = target; return CURLE_OK; } }
src/tool_urlglob.h +2 −2 Original line number Original line Diff line number Diff line Loading @@ -64,8 +64,8 @@ typedef struct { } URLGlob; } URLGlob; int glob_url(URLGlob**, char*, int *, FILE *); int glob_url(URLGlob**, char*, int *, FILE *); char* glob_next_url(URLGlob*); int glob_next_url(char **, URLGlob *); char* glob_match_url(char*, URLGlob *); int glob_match_url(char **, char*, URLGlob *); void glob_cleanup(URLGlob* glob); void glob_cleanup(URLGlob* glob); #endif /* HEADER_CURL_TOOL_URLGLOB_H */ #endif /* HEADER_CURL_TOOL_URLGLOB_H */ Loading