Commit d5ec44ca authored by Daniel Stenberg's avatar Daniel Stenberg
Browse files

INFILESIZE: fields in UserDefined must not be changed run-time

set.infilesize in this case was modified in several places, which could
lead to repeated requests using the same handle to get unintendent/wrong
consequences based on what the previous request did!
parent 9c941e92
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
 *                | (__| |_| |  _ <| |___
 *                 \___|\___/|_| \_\_____|
 *
 * Copyright (C) 2012 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
 * Copyright (C) 2010, Howard Chu, <hyc@highlandsun.com>
 *
 * This software is licensed as described in the file COPYING, which
@@ -240,7 +241,7 @@ static CURLcode rtmp_do(struct connectdata *conn, bool *done)
    return CURLE_FAILED_INIT;

  if(conn->data->set.upload) {
    Curl_pgrsSetUploadSize(conn->data, conn->data->set.infilesize);
    Curl_pgrsSetUploadSize(conn->data, conn->data->state.infilesize);
    Curl_setup_transfer(conn, -1, -1, FALSE, NULL, FIRSTSOCKET, NULL);
  }
  else
+3 −3
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@
 *                            | (__| |_| |  _ <| |___
 *                             \___|\___/|_| \_\_____|
 *
 * Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
 * Copyright (C) 1998 - 2014, 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
@@ -336,9 +336,9 @@ static CURLcode file_upload(struct connectdata *conn)
    return CURLE_WRITE_ERROR;
  }

  if(-1 != data->set.infilesize)
  if(-1 != data->state.infilesize)
    /* known size of data to "upload" */
    Curl_pgrsSetUploadSize(data, data->set.infilesize);
    Curl_pgrsSetUploadSize(data, data->state.infilesize);

  /* treat the negative resume offset value as the case of "-" */
  if(data->state.resume_from < 0) {
+7 −7
Original line number Diff line number Diff line
@@ -507,7 +507,7 @@ static CURLcode InitiateTransfer(struct connectdata *conn)
    /* When we know we're uploading a specified file, we can get the file
       size prior to the actual upload. */

    Curl_pgrsSetUploadSize(data, data->set.infilesize);
    Curl_pgrsSetUploadSize(data, data->state.infilesize);

    /* set the SO_SNDBUF for the secondary socket for those who need it */
    Curl_sndbufset(conn->sock[SECONDARYSOCKET]);
@@ -1683,10 +1683,10 @@ static CURLcode ftp_state_ul_setup(struct connectdata *conn,
      }
    }
    /* now, decrease the size of the read */
    if(data->set.infilesize>0) {
      data->set.infilesize -= data->state.resume_from;
    if(data->state.infilesize>0) {
      data->state.infilesize -= data->state.resume_from;

      if(data->set.infilesize <= 0) {
      if(data->state.infilesize <= 0) {
        infof(data, "File already completely uploaded\n");

        /* no data to transfer */
@@ -3382,13 +3382,13 @@ static CURLcode ftp_done(struct connectdata *conn, CURLcode status,
       use checking further */
    ;
  else if(data->set.upload) {
    if((-1 != data->set.infilesize) &&
       (data->set.infilesize != *ftp->bytecountp) &&
    if((-1 != data->state.infilesize) &&
       (data->state.infilesize != *ftp->bytecountp) &&
       !data->set.crlf &&
       (ftp->transfer == FTPTRANSFER_BODY)) {
      failf(data, "Uploaded unaligned file size (%" CURL_FORMAT_CURL_OFF_T
            " out of %" CURL_FORMAT_CURL_OFF_T " bytes)",
            *ftp->bytecountp, data->set.infilesize);
            *ftp->bytecountp, data->state.infilesize);
      result = CURLE_PARTIAL_FILE;
    }
  }
+10 −10
Original line number Diff line number Diff line
@@ -405,8 +405,8 @@ static CURLcode http_perhapsrewind(struct connectdata *conn)
        expectsend = (curl_off_t)strlen(data->set.postfields);
      break;
    case HTTPREQ_PUT:
      if(data->set.infilesize != -1)
        expectsend = data->set.infilesize;
      if(data->state.infilesize != -1)
        expectsend = data->state.infilesize;
      break;
    case HTTPREQ_POST_FORM:
      expectsend = http->postsize;
@@ -1885,7 +1885,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
    else {
      if((conn->handler->protocol&PROTO_FAMILY_HTTP) &&
         data->set.upload &&
         (data->set.infilesize == -1)) {
         (data->state.infilesize == -1)) {
        if(conn->bits.authneg)
          /* don't enable chunked during auth neg */
          ;
@@ -2123,10 +2123,10 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
      }

      /* now, decrease the size of the read */
      if(data->set.infilesize>0) {
        data->set.infilesize -= data->state.resume_from;
      if(data->state.infilesize>0) {
        data->state.infilesize -= data->state.resume_from;

        if(data->set.infilesize <= 0) {
        if(data->state.infilesize <= 0) {
          failf(data, "File already completely uploaded");
          return CURLE_PARTIAL_FILE;
        }
@@ -2162,13 +2162,13 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
        conn->allocptr.rangeline =
          aprintf("Content-Range: bytes 0-%" CURL_FORMAT_CURL_OFF_T
                  "/%" CURL_FORMAT_CURL_OFF_T "\r\n",
                  data->set.infilesize - 1, data->set.infilesize);
                  data->state.infilesize - 1, data->state.infilesize);

      }
      else if(data->state.resume_from) {
        /* This is because "resume" was selected */
        curl_off_t total_expected_size=
          data->state.resume_from + data->set.infilesize;
          data->state.resume_from + data->state.infilesize;
        conn->allocptr.rangeline =
          aprintf("Content-Range: bytes %s%" CURL_FORMAT_CURL_OFF_T
                  "/%" CURL_FORMAT_CURL_OFF_T "\r\n",
@@ -2180,7 +2180,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
           append total size */
        conn->allocptr.rangeline =
          aprintf("Content-Range: bytes %s/%" CURL_FORMAT_CURL_OFF_T "\r\n",
                  data->state.range, data->set.infilesize);
                  data->state.range, data->state.infilesize);
      }
      if(!conn->allocptr.rangeline)
        return CURLE_OUT_OF_MEMORY;
@@ -2455,7 +2455,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
    if(conn->bits.authneg)
      postsize = 0;
    else
      postsize = data->set.infilesize;
      postsize = data->state.infilesize;

    if((postsize != -1) && !data->req.upload_chunky &&
       !Curl_checkheaders(conn, "Content-Length:")) {
+3 −3
Original line number Diff line number Diff line
@@ -775,7 +775,7 @@ static CURLcode imap_perform_append(struct connectdata *conn)
  }

  /* Check we know the size of the upload */
  if(conn->data->set.infilesize < 0) {
  if(conn->data->state.infilesize < 0) {
    failf(conn->data, "Cannot APPEND with unknown input file size\n");
    return CURLE_UPLOAD_FAILED;
  }
@@ -787,7 +787,7 @@ static CURLcode imap_perform_append(struct connectdata *conn)

  /* Send the APPEND command */
  result = imap_sendf(conn, "APPEND %s (\\Seen) {%" CURL_FORMAT_CURL_OFF_T "}",
                      mailbox, conn->data->set.infilesize);
                      mailbox, conn->data->state.infilesize);

  Curl_safefree(mailbox);

@@ -1618,7 +1618,7 @@ static CURLcode imap_state_append_resp(struct connectdata *conn, int imapcode,
  }
  else {
    /* Set the progress upload size */
    Curl_pgrsSetUploadSize(data, data->set.infilesize);
    Curl_pgrsSetUploadSize(data, data->state.infilesize);

    /* IMAP upload */
    Curl_setup_transfer(conn, -1, -1, FALSE, NULL, FIRSTSOCKET, NULL);
Loading