Commit 87eb8d5b authored by Daniel Stenberg's avatar Daniel Stenberg
Browse files

http: don't clobber the receive buffer for timecond

parent f535f4f5
Loading
Loading
Loading
Loading
+21 −19
Original line number Original line Diff line number Diff line
@@ -1695,9 +1695,10 @@ CURLcode Curl_add_timecondition(struct Curl_easy *data,
                                Curl_send_buffer *req_buffer)
                                Curl_send_buffer *req_buffer)
{
{
  const struct tm *tm;
  const struct tm *tm;
  char *buf = data->state.buffer;
  struct tm keeptime;
  struct tm keeptime;
  CURLcode result;
  CURLcode result;
  char datestr[80];
  const char *condp;


  if(data->set.timecondition == CURL_TIMECOND_NONE)
  if(data->set.timecondition == CURL_TIMECOND_NONE)
    /* no condition was asked for */
    /* no condition was asked for */
@@ -1710,6 +1711,21 @@ CURLcode Curl_add_timecondition(struct Curl_easy *data,
  }
  }
  tm = &keeptime;
  tm = &keeptime;


  switch(data->set.timecondition) {
  default:
    return CURLE_BAD_FUNCTION_ARGUMENT;

  case CURL_TIMECOND_IFMODSINCE:
    condp = "If-Modified-Since";
    break;
  case CURL_TIMECOND_IFUNMODSINCE:
    condp = "If-Unmodified-Since";
    break;
  case CURL_TIMECOND_LASTMOD:
    condp = "Last-Modified";
    break;
  }

  /* The If-Modified-Since header family should have their times set in
  /* The If-Modified-Since header family should have their times set in
   * GMT as RFC2616 defines: "All HTTP date/time stamps MUST be
   * GMT as RFC2616 defines: "All HTTP date/time stamps MUST be
   * represented in Greenwich Mean Time (GMT), without exception. For the
   * represented in Greenwich Mean Time (GMT), without exception. For the
@@ -1718,8 +1734,9 @@ CURLcode Curl_add_timecondition(struct Curl_easy *data,
   */
   */


  /* format: "Tue, 15 Nov 1994 12:45:26 GMT" */
  /* format: "Tue, 15 Nov 1994 12:45:26 GMT" */
  snprintf(buf, BUFSIZE-1,
  snprintf(datestr, sizeof(datestr),
           "%s, %02d %s %4d %02d:%02d:%02d GMT",
           "%s: %s, %02d %s %4d %02d:%02d:%02d GMT\r\n",
           condp,
           Curl_wkday[tm->tm_wday?tm->tm_wday-1:6],
           Curl_wkday[tm->tm_wday?tm->tm_wday-1:6],
           tm->tm_mday,
           tm->tm_mday,
           Curl_month[tm->tm_mon],
           Curl_month[tm->tm_mon],
@@ -1728,22 +1745,7 @@ CURLcode Curl_add_timecondition(struct Curl_easy *data,
           tm->tm_min,
           tm->tm_min,
           tm->tm_sec);
           tm->tm_sec);


  switch(data->set.timecondition) {
  result = Curl_add_buffer(req_buffer, datestr, strlen(datestr));
  default:
    break;
  case CURL_TIMECOND_IFMODSINCE:
    result = Curl_add_bufferf(req_buffer,
                              "If-Modified-Since: %s\r\n", buf);
    break;
  case CURL_TIMECOND_IFUNMODSINCE:
    result = Curl_add_bufferf(req_buffer,
                              "If-Unmodified-Since: %s\r\n", buf);
    break;
  case CURL_TIMECOND_LASTMOD:
    result = Curl_add_bufferf(req_buffer,
                              "Last-Modified: %s\r\n", buf);
    break;
  }


  return result;
  return result;
}
}