~ubuntu-branches/ubuntu/lucid/curl/lucid-security

« back to all changes in this revision

Viewing changes to lib/transfer.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2005-12-12 15:04:52 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20051212150452-2ymlra67b2p7kjyy
Tags: 7.15.1-1ubuntu1
Resynchronise with Debian to get URL parser overflow fix from 7.15.1
(CVE-2005-4077).

Show diffs side-by-side

added added

removed removed

Lines of Context:
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: transfer.c,v 1.279 2005/05/10 23:02:37 bagder Exp $
 
21
 * $Id: transfer.c,v 1.290 2005/11/24 10:22:47 bagder Exp $
22
22
 ***************************************************************************/
23
23
 
24
24
#include "setup.h"
214
214
    if(data->set.ioctl) {
215
215
      curlioerr err;
216
216
 
217
 
      err = data->set.ioctl(data, CURLIOCMD_RESTARTREAD,
 
217
      err = (data->set.ioctl) (data, CURLIOCMD_RESTARTREAD,
218
218
                            data->set.ioctl_client);
219
219
      infof(data, "the ioctl callback returned %d\n", (int)err);
220
220
 
718
718
               the header completely if we get a 416 response as then we're
719
719
               resuming a document that we don't get, and this header contains
720
720
               info about the true size of the document we didn't get now. */
721
 
            if (!k->ignorecl &&
 
721
            if (!k->ignorecl && !data->set.ignorecl &&
722
722
                checkprefix("Content-Length:", k->p)) {
723
723
              contentlength = curlx_strtoofft(k->p+15, NULL, 10);
724
724
              if (data->set.max_filesize &&
833
833
              /* init our chunky engine */
834
834
              Curl_httpchunk_init(conn);
835
835
            }
 
836
 
 
837
            else if (checkprefix("Trailer:", k->p) ||
 
838
                     checkprefix("Trailers:", k->p)) {
 
839
              /*
 
840
               * This test helps Curl_httpchunk_read() to determine to look
 
841
               * for well formed trailers after the zero chunksize record. In
 
842
               * this case a CRLF is required after the zero chunksize record
 
843
               * when no trailers are sent, or after the last trailer record.
 
844
               *
 
845
               * It seems both Trailer: and Trailers: occur in the wild.
 
846
               */
 
847
              conn->bits.trailerHdrPresent = TRUE;
 
848
            }
 
849
 
836
850
            else if (checkprefix("Content-Encoding:", k->p) &&
837
851
                     data->set.encoding) {
838
852
              /*
866
880
              /* Content-Range: bytes [num]-
867
881
                 Content-Range: bytes: [num]-
868
882
 
869
 
                 The second format was added August 1st 2000 by Igor
870
 
                 Khristophorov since Sun's webserver JavaWebServer/1.1.1
871
 
                 obviously sends the header this way! :-( */
 
883
                 The second format was added since Sun's webserver
 
884
                 JavaWebServer/1.1.1 obviously sends the header this way!
 
885
              */
872
886
 
873
 
              char *ptr = strstr(k->p, "bytes");
 
887
              char *ptr = Curl_strcasestr(k->p, "bytes");
874
888
              ptr+=5;
875
889
 
876
890
              if(*ptr == ':')
1074
1088
             * the name says read, this function both reads and writes away
1075
1089
             * the data. The returned 'nread' holds the number of actual
1076
1090
             * data it wrote to the client.  */
 
1091
 
1077
1092
            CHUNKcode res =
1078
1093
              Curl_httpchunk_read(conn, k->str, nread, &nread);
1079
1094
 
1119
1134
              result = Curl_client_write(data, CLIENTWRITE_BODY,
1120
1135
                                         data->state.headerbuff,
1121
1136
                                         k->hbuflen);
 
1137
              if(result)
 
1138
                return result;
1122
1139
            }
1123
1140
            if(k->badheader < HEADER_ALLBAD) {
1124
1141
              /* This switch handles various content encodings. If there's an
1605
1622
CURLcode Curl_pretransfer(struct SessionHandle *data)
1606
1623
{
1607
1624
  CURLcode res;
1608
 
  if(!data->change.url)
 
1625
  if(!data->change.url) {
1609
1626
    /* we can't do anything wihout URL */
 
1627
    failf(data, "No URL set!\n");
1610
1628
    return CURLE_URL_MALFORMAT;
 
1629
  }
1611
1630
 
1612
1631
  /* Init the SSL session ID cache here. We do it here since we want to do it
1613
1632
     after the *_setopt() calls (that could change the size of the cache) but
1624
1643
  data->state.authhost.want = data->set.httpauth;
1625
1644
  data->state.authproxy.want = data->set.proxyauth;
1626
1645
 
1627
 
#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
1628
 
  /* If there was a list of cookie files to read and we haven't done it before,
1629
 
     do it now! */
1630
 
  if(data->change.cookielist) {
1631
 
    struct curl_slist *list = data->change.cookielist;
1632
 
    Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE);
1633
 
    while(list) {
1634
 
      data->cookies = Curl_cookie_init(data,
1635
 
                                       list->data,
1636
 
                                       data->cookies,
1637
 
                                       data->set.cookiesession);
1638
 
      list = list->next;
1639
 
    }
1640
 
    Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
1641
 
    curl_slist_free_all(data->change.cookielist); /* clean up list */
1642
 
    data->change.cookielist = NULL; /* don't do this again! */
1643
 
  }
1644
 
#endif   /* CURL_DISABLE_HTTP */
1645
 
 
 
1646
  /* If there is a list of cookie files to read, do it now! */
 
1647
  if(data->change.cookielist)
 
1648
    Curl_cookie_loadfiles(data);
1646
1649
 
1647
1650
 /* Allow data->set.use_port to set which port to use. This needs to be
1648
1651
  * disabled for example when we follow Location: headers to URLs using
1762
1765
  size_t newlen;
1763
1766
  char *newest;
1764
1767
 
1765
 
  if (data->set.maxredirs &&
 
1768
  if ((data->set.maxredirs != -1) &&
1766
1769
      (data->set.followlocation >= data->set.maxredirs)) {
1767
1770
    failf(data,"Maximum (%d) redirects followed", data->set.maxredirs);
1768
1771
    return CURLE_TOO_MANY_REDIRECTS;
2214
2217
  if(newurl)
2215
2218
    free(newurl);
2216
2219
 
 
2220
  if(res && !data->state.errorbuf) {
 
2221
    /*
 
2222
     * As an extra precaution: if no error string has been set and there was
 
2223
     * an error, use the strerror() string or if things are so bad that not
 
2224
     * even that is good, set a bad string that mentions the error code.
 
2225
     */
 
2226
    const char *str = curl_easy_strerror(res);
 
2227
    if(!str)
 
2228
      failf(data, "unspecified error %d", (int)res);
 
2229
    else
 
2230
      failf(data, "%s", str);
 
2231
  }
 
2232
 
2217
2233
  /* run post-transfer uncondionally, but don't clobber the return code if
2218
2234
     we already have an error code recorder */
2219
2235
  res2 = Curl_posttransfer(data);