diff options
author | Daniel Stenberg <daniel@haxx.se> | 2013-08-15 13:05:25 +0200 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2013-08-16 11:52:08 +0200 |
commit | 5ca96cb84410270e233c92bf1b2583cba40c3fad (patch) | |
tree | e577dbc96ddf320574a030213f4880815558ea84 /src/tool_urlglob.h | |
parent | 10afe7cf105d03b94b34f937d53e9b352b87817c (diff) | |
download | curl-5ca96cb84410270e233c92bf1b2583cba40c3fad.tar.gz |
urlglob: better detect unclosed braces, empty lists and overflows
A rather big overhaul and cleanup.
1 - curl wouldn't properly detect and reject globbing that ended with an
open brace if there were brackets or braces before it. Like "{}{" or
"[0-1]{"
2 - curl wouldn't properly reject empty lists so that "{}{}" would
result in curl getting (nil) strings in the output.
3 - By using strtoul() instead of sscanf() the code will now detected
over and underflows. It now also better parses the step argument to only
accept positive numbers and only step counters that is smaller than the
delta between the maximum and minimum numbers.
4 - By switching to unsigned longs instead of signed ints for the
counters, the max values for []-ranges are now very large (on 64bit
machines).
5 - Bumped the maximum number of globs in a single URL to 100 (from 10)
6 - Simplified the code somewhat and now it stores fixed strings as
single- entry lists. That's also one of the reasons why I did (5) as now
all strings between "globs" will take a slot in the array.
Added test 1234 and 1235 to verify. Updated test 87.
This commit fixes three separate bug reports.
Bug: http://curl.haxx.se/bug/view.cgi?id=1264
Bug: http://curl.haxx.se/bug/view.cgi?id=1265
Bug: http://curl.haxx.se/bug/view.cgi?id=1266
Reported-by: Will Dietz
Diffstat (limited to 'src/tool_urlglob.h')
-rw-r--r-- | src/tool_urlglob.h | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/src/tool_urlglob.h b/src/tool_urlglob.h index 9c0813750..e1e9c6384 100644 --- a/src/tool_urlglob.h +++ b/src/tool_urlglob.h @@ -7,7 +7,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -31,11 +31,13 @@ typedef enum { typedef struct { URLPatternType type; + int globindex; /* the number of this particular glob or -1 if not used + within {} or [] */ union { struct { char **elements; - short size; - short ptr_s; + int size; + int ptr_s; } Set; struct { char min_c; @@ -44,21 +46,20 @@ typedef struct { int step; } CharRange; struct { - int min_n; - int max_n; - short padlength; - int ptr_n; - int step; + unsigned long min_n; + unsigned long max_n; + int padlength; + unsigned long ptr_n; + unsigned long step; } NumRange ; } content; } URLPattern; /* the total number of globs supported */ -#define GLOB_PATTERN_NUM 9 +#define GLOB_PATTERN_NUM 100 typedef struct { - char *literal[10]; - URLPattern pattern[GLOB_PATTERN_NUM+1]; + URLPattern pattern[GLOB_PATTERN_NUM]; size_t size; size_t urllen; char *glob_buffer; @@ -66,7 +67,7 @@ typedef struct { char errormsg[80]; /* error message buffer */ } URLGlob; -int glob_url(URLGlob**, char*, int *, FILE *); +int glob_url(URLGlob**, char*, unsigned long *, FILE *); int glob_next_url(char **, URLGlob *); int glob_match_url(char **, char*, URLGlob *); void glob_cleanup(URLGlob* glob); |