mirror of
https://github.com/moparisthebest/curl
synced 2024-11-11 20:15:03 -05:00
urlglob.c: fix OOM handling
This commit is contained in:
parent
72c14bd6f0
commit
777f9aea13
@ -86,13 +86,21 @@ static GlobCode glob_set(URLGlob *glob, char *pattern,
|
|||||||
case ',':
|
case ',':
|
||||||
case '}': /* set element completed */
|
case '}': /* set element completed */
|
||||||
*buf = '\0';
|
*buf = '\0';
|
||||||
if(pat->content.Set.elements)
|
if(pat->content.Set.elements) {
|
||||||
pat->content.Set.elements =
|
char **new_arr = realloc(pat->content.Set.elements,
|
||||||
realloc(pat->content.Set.elements,
|
(pat->content.Set.size + 1) * sizeof(char*));
|
||||||
(pat->content.Set.size + 1) * sizeof(char*));
|
if(!new_arr) {
|
||||||
|
short elem;
|
||||||
|
for(elem = 0; elem < pat->content.Set.size; elem++)
|
||||||
|
free(pat->content.Set.elements[elem]);
|
||||||
|
free(pat->content.Set.elements);
|
||||||
|
pat->content.Set.ptr_s = 0;
|
||||||
|
pat->content.Set.size = 0;
|
||||||
|
}
|
||||||
|
pat->content.Set.elements = new_arr;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
pat->content.Set.elements =
|
pat->content.Set.elements = malloc(sizeof(char*));
|
||||||
malloc((pat->content.Set.size + 1) * sizeof(char*));
|
|
||||||
if(!pat->content.Set.elements) {
|
if(!pat->content.Set.elements) {
|
||||||
snprintf(glob->errormsg, sizeof(glob->errormsg), "out of memory");
|
snprintf(glob->errormsg, sizeof(glob->errormsg), "out of memory");
|
||||||
return GLOB_ERROR;
|
return GLOB_ERROR;
|
||||||
@ -100,6 +108,13 @@ static GlobCode glob_set(URLGlob *glob, char *pattern,
|
|||||||
pat->content.Set.elements[pat->content.Set.size] =
|
pat->content.Set.elements[pat->content.Set.size] =
|
||||||
strdup(glob->glob_buffer);
|
strdup(glob->glob_buffer);
|
||||||
if(!pat->content.Set.elements[pat->content.Set.size]) {
|
if(!pat->content.Set.elements[pat->content.Set.size]) {
|
||||||
|
short elem;
|
||||||
|
for(elem = 0; elem < pat->content.Set.size; elem++)
|
||||||
|
free(pat->content.Set.elements[elem]);
|
||||||
|
free(pat->content.Set.elements);
|
||||||
|
pat->content.Set.elements = NULL;
|
||||||
|
pat->content.Set.ptr_s = 0;
|
||||||
|
pat->content.Set.size = 0;
|
||||||
snprintf(glob->errormsg, sizeof(glob->errormsg), "out of memory");
|
snprintf(glob->errormsg, sizeof(glob->errormsg), "out of memory");
|
||||||
return GLOB_ERROR;
|
return GLOB_ERROR;
|
||||||
}
|
}
|
||||||
@ -405,7 +420,8 @@ char *glob_next_url(URLGlob *glob)
|
|||||||
pat = &glob->pattern[i];
|
pat = &glob->pattern[i];
|
||||||
switch (pat->type) {
|
switch (pat->type) {
|
||||||
case UPTSet:
|
case UPTSet:
|
||||||
if(++pat->content.Set.ptr_s == pat->content.Set.size) {
|
if((pat->content.Set.elements) &&
|
||||||
|
(++pat->content.Set.ptr_s == pat->content.Set.size)) {
|
||||||
pat->content.Set.ptr_s = 0;
|
pat->content.Set.ptr_s = 0;
|
||||||
carry = TRUE;
|
carry = TRUE;
|
||||||
}
|
}
|
||||||
@ -445,11 +461,13 @@ char *glob_next_url(URLGlob *glob)
|
|||||||
pat = &glob->pattern[j/2];
|
pat = &glob->pattern[j/2];
|
||||||
switch(pat->type) {
|
switch(pat->type) {
|
||||||
case UPTSet:
|
case UPTSet:
|
||||||
len = strlen(pat->content.Set.elements[pat->content.Set.ptr_s]);
|
if(pat->content.Set.elements) {
|
||||||
snprintf(buf, buflen, "%s",
|
len = strlen(pat->content.Set.elements[pat->content.Set.ptr_s]);
|
||||||
pat->content.Set.elements[pat->content.Set.ptr_s]);
|
snprintf(buf, buflen, "%s",
|
||||||
buf += len;
|
pat->content.Set.elements[pat->content.Set.ptr_s]);
|
||||||
buflen -= len;
|
buf += len;
|
||||||
|
buflen -= len;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case UPTCharRange:
|
case UPTCharRange:
|
||||||
*buf++ = pat->content.CharRange.ptr_c;
|
*buf++ = pat->content.CharRange.ptr_c;
|
||||||
@ -501,8 +519,11 @@ char *glob_match_url(char *filename, URLGlob *glob)
|
|||||||
URLPattern pat = glob->pattern[i];
|
URLPattern pat = glob->pattern[i];
|
||||||
switch (pat.type) {
|
switch (pat.type) {
|
||||||
case UPTSet:
|
case UPTSet:
|
||||||
appendthis = pat.content.Set.elements[pat.content.Set.ptr_s];
|
if(pat.content.Set.elements) {
|
||||||
appendlen = strlen(pat.content.Set.elements[pat.content.Set.ptr_s]);
|
appendthis = pat.content.Set.elements[pat.content.Set.ptr_s];
|
||||||
|
appendlen =
|
||||||
|
strlen(pat.content.Set.elements[pat.content.Set.ptr_s]);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case UPTCharRange:
|
case UPTCharRange:
|
||||||
numbuf[0]=pat.content.CharRange.ptr_c;
|
numbuf[0]=pat.content.CharRange.ptr_c;
|
||||||
|
Loading…
Reference in New Issue
Block a user