Commit 6beb0eee authored by Brandon Casey's avatar Brandon Casey Committed by Daniel Stenberg
Browse files

Ensure progress.size_dl/progress.size_ul are always >= 0



Historically the default "unknown" value for progress.size_dl and
progress.size_ul has been zero, since these values are initialized
implicitly by the calloc that allocates the curl handle that these
variables are a part of.  Users of curl that install progress
callbacks may expect these values to always be >= 0.

Currently it is possible for progress.size_dl and progress.size_ul
to by set to a value of -1, if Curl_pgrsSetDownloadSize() or
Curl_pgrsSetUploadSize() are passed a "size" of -1 (which a few
places currently do, and a following patch will add more).  So
lets update Curl_pgrsSetDownloadSize() and Curl_pgrsSetUploadSize()
so they make sure that these variables always contain a value that
is >= 0.

Updates test579 and test599.

Signed-off-by: default avatarBrandon Casey <drafnel@gmail.com>
parent 8acbb074
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -4470,8 +4470,8 @@ CURLcode ftp_regular_transfer(struct connectdata *conn,

  Curl_pgrsSetUploadCounter(data, 0);
  Curl_pgrsSetDownloadCounter(data, 0);
  Curl_pgrsSetUploadSize(data, 0);
  Curl_pgrsSetDownloadSize(data, 0);
  Curl_pgrsSetUploadSize(data, -1);
  Curl_pgrsSetDownloadSize(data, -1);

  ftpc->ctl_valid = TRUE; /* starts good */

+1 −1
Original line number Diff line number Diff line
@@ -2351,7 +2351,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
    return result;

  http->postdata = NULL;  /* nothing to post at this point */
  Curl_pgrsSetUploadSize(data, 0); /* upload size is 0 atm */
  Curl_pgrsSetUploadSize(data, -1); /* upload size is unknown atm */

  /* If 'authdone' is FALSE, we must not set the write socket index to the
     Curl_transfer() call below, as we're not ready to actually upload any
+3 −3
Original line number Diff line number Diff line
@@ -1662,7 +1662,7 @@ static CURLcode imap_state_fetch_resp(struct connectdata *conn, int imapcode,
  (void)instate; /* no use for this yet */

  if(imapcode != '*') {
    Curl_pgrsSetDownloadSize(data, 0);
    Curl_pgrsSetDownloadSize(data, -1);
    state(conn, IMAP_STOP);
    return CURLE_REMOTE_FILE_NOT_FOUND; /* TODO: Fix error code */
  }
@@ -2336,8 +2336,8 @@ static CURLcode imap_regular_transfer(struct connectdata *conn,
  /* Set the progress data */
  Curl_pgrsSetUploadCounter(data, 0);
  Curl_pgrsSetDownloadCounter(data, 0);
  Curl_pgrsSetUploadSize(data, 0);
  Curl_pgrsSetDownloadSize(data, 0);
  Curl_pgrsSetUploadSize(data, -1);
  Curl_pgrsSetDownloadSize(data, -1);

  /* Carry out the perform */
  result = imap_perform(conn, &connected, dophase_done);
+2 −2
Original line number Diff line number Diff line
@@ -1935,8 +1935,8 @@ static CURLcode pop3_regular_transfer(struct connectdata *conn,
  /* Set the progress data */
  Curl_pgrsSetUploadCounter(data, 0);
  Curl_pgrsSetDownloadCounter(data, 0);
  Curl_pgrsSetUploadSize(data, 0);
  Curl_pgrsSetDownloadSize(data, 0);
  Curl_pgrsSetUploadSize(data, -1);
  Curl_pgrsSetDownloadSize(data, -1);

  /* Carry out the perform */
  result = pop3_perform(conn, &connected, dophase_done);
+14 −8
Original line number Diff line number Diff line
@@ -159,8 +159,8 @@ void Curl_pgrsResetTimesSizes(struct SessionHandle *data)
  data->progress.t_pretransfer = 0.0;
  data->progress.t_starttransfer = 0.0;

  Curl_pgrsSetDownloadSize(data, 0);
  Curl_pgrsSetUploadSize(data, 0);
  Curl_pgrsSetDownloadSize(data, -1);
  Curl_pgrsSetUploadSize(data, -1);
}

void Curl_pgrsTime(struct SessionHandle *data, timerid timer)
@@ -234,21 +234,27 @@ void Curl_pgrsSetUploadCounter(struct SessionHandle *data, curl_off_t size)

void Curl_pgrsSetDownloadSize(struct SessionHandle *data, curl_off_t size)
{
  if(size >= 0) {
    data->progress.size_dl = size;
  if(size >= 0)
    data->progress.flags |= PGRS_DL_SIZE_KNOWN;
  else
  }
  else {
    data->progress.size_dl = 0;
    data->progress.flags &= ~PGRS_DL_SIZE_KNOWN;
  }
}

void Curl_pgrsSetUploadSize(struct SessionHandle *data, curl_off_t size)
{
  if(size >= 0) {
    data->progress.size_ul = size;
  if(size >= 0)
    data->progress.flags |= PGRS_UL_SIZE_KNOWN;
  else
  }
  else {
    data->progress.size_ul = 0;
    data->progress.flags &= ~PGRS_UL_SIZE_KNOWN;
  }
}

/*
 * Curl_pgrsUpdate() returns 0 for success or the value returned by the
Loading