~ubuntu-branches/ubuntu/vivid/curl/vivid

« back to all changes in this revision

Viewing changes to src/urlglob.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Schuldei
  • Date: 2009-04-02 23:35:45 UTC
  • mto: (1.2.1 upstream) (3.2.3 sid)
  • mto: This revision was merged to the branch mainline in revision 38.
  • Revision ID: james.westby@ubuntu.com-20090402233545-geixkwhe3izccjt7
Tags: upstream-7.19.4
ImportĀ upstreamĀ versionĀ 7.19.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 *                            | (__| |_| |  _ <| |___
6
6
 *                             \___|\___/|_| \_\_____|
7
7
 *
8
 
 * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
 
8
 * Copyright (C) 1998 - 2008, Daniel Stenberg, <daniel@haxx.se>, et al.
9
9
 *
10
10
 * This software is licensed as described in the file COPYING, which
11
11
 * you should have received as part of this distribution. The terms
18
18
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
19
 * KIND, either express or implied.
20
20
 *
21
 
 * $Id: urlglob.c,v 1.48 2007-09-20 00:37:08 danf Exp $
 
21
 * $Id: urlglob.c,v 1.53 2008-10-14 09:12:44 bagder Exp $
22
22
 ***************************************************************************/
23
23
 
24
24
/* client-local setup.h */
70
70
  pat->type = UPTSet;
71
71
  pat->content.Set.size = 0;
72
72
  pat->content.Set.ptr_s = 0;
 
73
  /* FIXME: Here's a nasty zero size malloc */
73
74
  pat->content.Set.elements = (char**)malloc(0);
74
75
  ++glob->size;
75
76
 
79
80
    switch (*pattern) {
80
81
    case '\0':                  /* URL ended while set was still open */
81
82
      snprintf(glob->errormsg, sizeof(glob->errormsg),
82
 
               "unmatched brace at pos %d\n", (int)pos);
 
83
               "unmatched brace at pos %zu\n", pos);
83
84
      return GLOB_ERROR;
84
85
 
85
86
    case '{':
86
87
    case '[':                   /* no nested expressions at this time */
87
88
      snprintf(glob->errormsg, sizeof(glob->errormsg),
88
 
               "nested braces not supported at pos %d\n", (int)pos);
 
89
               "nested braces not supported at pos %zu\n", pos);
89
90
      return GLOB_ERROR;
90
91
 
91
92
    case ',':
122
123
 
123
124
    case ']':                           /* illegal closing bracket */
124
125
      snprintf(glob->errormsg, sizeof(glob->errormsg),
125
 
               "illegal pattern at pos %d\n", (int)pos);
 
126
               "illegal pattern at pos %zu\n", pos);
126
127
      return GLOB_ERROR;
127
128
 
128
129
    case '\\':                          /* escaped character, skip '\' */
141
142
      if(skip) {
142
143
        if (*(buf+1) == '\0') {           /* but no escaping of '\0'! */
143
144
          snprintf(glob->errormsg, sizeof(glob->errormsg),
144
 
                   "illegal pattern at pos %d\n", (int)pos);
 
145
                   "illegal pattern at pos %zu\n", pos);
145
146
          return GLOB_ERROR;
146
147
        }
147
148
        ++pattern;
186
187
    if ((rc < 3) || (min_c >= max_c) || ((max_c - min_c) > ('z' - 'a'))) {
187
188
      /* the pattern is not well-formed */
188
189
      snprintf(glob->errormsg, sizeof(glob->errormsg),
189
 
               "error: bad range specification after pos %d\n", pos);
 
190
               "error: bad range specification after pos %zu\n", pos);
190
191
      return GLOB_ERROR;
191
192
    }
192
193
 
193
194
    /* check the (first) separating character */
194
195
    if((sep != ']') && (sep != ':')) {
195
196
      snprintf(glob->errormsg, sizeof(glob->errormsg),
196
 
               "error: unsupported character (%c) after range at pos %d\n",
 
197
               "error: unsupported character (%c) after range at pos %zu\n",
197
198
               sep, pos);
198
199
      return GLOB_ERROR;
199
200
    }
217
218
    if ((rc < 2) || (min_n > max_n)) {
218
219
      /* the pattern is not well-formed */
219
220
      snprintf(glob->errormsg, sizeof(glob->errormsg),
220
 
               "error: bad range specification after pos %d\n", pos);
 
221
               "error: bad range specification after pos %zu\n", pos);
221
222
      return GLOB_ERROR;
222
223
    }
223
224
    pat->content.NumRange.ptr_n =  pat->content.NumRange.min_n = min_n;
239
240
  }
240
241
  else {
241
242
    snprintf(glob->errormsg, sizeof(glob->errormsg),
242
 
             "illegal character in range specification at pos %d\n", pos);
 
243
             "illegal character in range specification at pos %zu\n", pos);
243
244
    return GLOB_ERROR;
244
245
  }
245
246
 
335
336
   */
336
337
  URLGlob *glob_expand;
337
338
  int amount;
338
 
  char *glob_buffer=(char *)malloc(strlen(url)+1);
 
339
  char *glob_buffer = malloc(strlen(url)+1);
339
340
 
340
341
  *glob = NULL;
341
342
  if(NULL == glob_buffer)
342
343
    return CURLE_OUT_OF_MEMORY;
343
344
 
344
 
  glob_expand = (URLGlob*)calloc(sizeof(URLGlob), 1);
 
345
  glob_expand = calloc(sizeof(URLGlob), 1);
345
346
  if(NULL == glob_expand) {
346
347
    free(glob_buffer);
347
348
    return CURLE_OUT_OF_MEMORY;
495
496
   * be longer than the URL we use. We allocate a good start size, then
496
497
   * we need to realloc in case of need.
497
498
   */
498
 
  allocsize=strlen(filename);
 
499
  allocsize=strlen(filename)+1; /* make it at least one byte to store the
 
500
                                   trailing zero */
499
501
  target = malloc(allocsize);
500
502
  if(NULL == target)
501
503
    return NULL; /* major failure */
547
549
    }
548
550
    if(appendlen + stringlen >= allocsize) {
549
551
      char *newstr;
 
552
      /* we append a single byte to allow for the trailing byte to be appended
 
553
         at the end of this function outside the while() loop */
550
554
      allocsize = (appendlen + stringlen)*2;
551
 
      newstr=realloc(target, allocsize);
 
555
      newstr=realloc(target, allocsize + 1);
552
556
      if(NULL ==newstr) {
553
557
        free(target);
554
558
        return NULL;