]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
lib: remove bad set.opt_no_body assignments
authorDaniel Stenberg <daniel@haxx.se>
Fri, 11 Nov 2022 09:57:04 +0000 (10:57 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 11 Nov 2022 14:56:05 +0000 (15:56 +0100)
This struct field MUST remain what the application set it to, so that
handle reuse and handle duplication work.

Instead, the request state bit 'no_body' is introduced for code flows
that need to change this in run-time.

Closes #9888

13 files changed:
lib/file.c
lib/ftp.c
lib/http.c
lib/imap.c
lib/pop3.c
lib/rtsp.c
lib/smtp.c
lib/transfer.c
lib/url.c
lib/urldata.h
lib/vssh/libssh.c
lib/vssh/libssh2.c
lib/vssh/wolfssh.c

index 323148b2730a0d93a4f1e02f2b17f2937c071005..3f642be4619934d9266f150e755019c7254af9f5 100644 (file)
@@ -482,13 +482,13 @@ static CURLcode file_do(struct Curl_easy *data, bool *done)
               tm->tm_hour,
               tm->tm_min,
               tm->tm_sec,
-              data->set.opt_no_body ? "": "\r\n");
+              data->req.no_body ? "": "\r\n");
     result = Curl_client_write(data, CLIENTWRITE_HEADER, header, headerlen);
     if(result)
       return result;
     /* set the file size to make it available post transfer */
     Curl_pgrsSetDownloadSize(data, expected_size);
-    if(data->set.opt_no_body)
+    if(data->req.no_body)
       return result;
   }
 
index b85a27493339bfd3db70ca1977f541c8b1362039..2c639ebff449cecd6c5e20e8af5b79b6ad552831 100644 (file)
--- a/lib/ftp.c
+++ b/lib/ftp.c
@@ -1510,7 +1510,7 @@ static CURLcode ftp_state_type(struct Curl_easy *data)
   /* If we have selected NOBODY and HEADER, it means that we only want file
      information. Which in FTP can't be much more than the file size and
      date. */
-  if(data->set.opt_no_body && ftpc->file &&
+  if(data->req.no_body && ftpc->file &&
      ftp_need_type(conn, data->state.prefer_ascii)) {
     /* The SIZE command is _not_ RFC 959 specified, and therefore many servers
        may not support it! It is however the only way we have to get a file's
@@ -2082,7 +2082,7 @@ static CURLcode ftp_state_mdtm_resp(struct Curl_easy *data,
       /* If we asked for a time of the file and we actually got one as well,
          we "emulate" an HTTP-style header in our output. */
 
-      if(data->set.opt_no_body &&
+      if(data->req.no_body &&
          ftpc->file &&
          data->set.get_filetime &&
          (data->info.filetime >= 0) ) {
@@ -3699,7 +3699,7 @@ CURLcode ftp_perform(struct Curl_easy *data,
 
   DEBUGF(infof(data, "DO phase starts"));
 
-  if(data->set.opt_no_body) {
+  if(data->req.no_body) {
     /* requested no body means no transfer... */
     struct FTP *ftp = data->req.p.ftp;
     ftp->transfer = PPTRANSFER_INFO;
index 8ad429322169123878fcd0a0ccbe392c2d555c9b..13fdfa66907deea68891b6f96104d8515a0628ae 100644 (file)
@@ -2047,7 +2047,7 @@ void Curl_http_method(struct Curl_easy *data, struct connectdata *conn,
   if(data->set.str[STRING_CUSTOMREQUEST])
     request = data->set.str[STRING_CUSTOMREQUEST];
   else {
-    if(data->set.opt_no_body)
+    if(data->req.no_body)
       request = "HEAD";
     else {
       DEBUGASSERT((httpreq >= HTTPREQ_GET) && (httpreq <= HTTPREQ_HEAD));
@@ -4201,7 +4201,7 @@ CURLcode Curl_http_readwrite_headers(struct Curl_easy *data,
          * If we requested a "no body", this is a good time to get
          * out and return home.
          */
-        if(data->set.opt_no_body)
+        if(data->req.no_body)
           *stop_reading = TRUE;
 #ifndef CURL_DISABLE_RTSP
         else if((conn->handler->protocol & CURLPROTO_RTSP) &&
index 1eb10543581d8be47f6e325b7be47f100d280694..49c5c49d71b8c57c1c6b7d75d4b2bdbe456d4121 100644 (file)
@@ -1568,7 +1568,7 @@ static CURLcode imap_perform(struct Curl_easy *data, bool *connected,
 
   DEBUGF(infof(data, "DO phase starts"));
 
-  if(data->set.opt_no_body) {
+  if(data->req.no_body) {
     /* Requested no body means no transfer */
     imap->transfer = PPTRANSFER_INFO;
   }
index 48f589bce6879585fc1cb4b0a86b314e34e4f8be..b6ba0ea1aa2c422495b75c7476132ae2a7ea7218 100644 (file)
@@ -956,7 +956,7 @@ static CURLcode pop3_state_command_resp(struct Curl_easy *data,
          content so send it as such. Note that there may even be additional
          "headers" after the body */
 
-      if(!data->set.opt_no_body) {
+      if(!data->req.no_body) {
         result = Curl_pop3_write(data, pp->cache, pp->cache_size);
         if(result)
           return result;
@@ -1204,7 +1204,7 @@ static CURLcode pop3_perform(struct Curl_easy *data, bool *connected,
 
   DEBUGF(infof(data, "DO phase starts"));
 
-  if(data->set.opt_no_body) {
+  if(data->req.no_body) {
     /* Requested no body means no transfer */
     pop3->transfer = PPTRANSFER_INFO;
   }
index b071458beb413fddf0a2a06e9f572505751d2fd4..7ed2635febac7271e6e970c82e0e2e4bbc67482f 100644 (file)
@@ -283,7 +283,7 @@ static CURLcode rtsp_do(struct Curl_easy *data, bool *done)
    * Since all RTSP requests are included here, there is no need to
    * support custom requests like HTTP.
    **/
-  data->set.opt_no_body = TRUE; /* most requests don't contain a body */
+  data->req.no_body = TRUE; /* most requests don't contain a body */
   switch(rtspreq) {
   default:
     failf(data, "Got invalid RTSP request");
@@ -293,7 +293,7 @@ static CURLcode rtsp_do(struct Curl_easy *data, bool *done)
     break;
   case RTSPREQ_DESCRIBE:
     p_request = "DESCRIBE";
-    data->set.opt_no_body = FALSE;
+    data->req.no_body = FALSE;
     break;
   case RTSPREQ_ANNOUNCE:
     p_request = "ANNOUNCE";
@@ -313,7 +313,7 @@ static CURLcode rtsp_do(struct Curl_easy *data, bool *done)
   case RTSPREQ_GET_PARAMETER:
     /* GET_PARAMETER's no_body status is determined later */
     p_request = "GET_PARAMETER";
-    data->set.opt_no_body = FALSE;
+    data->req.no_body = FALSE;
     break;
   case RTSPREQ_SET_PARAMETER:
     p_request = "SET_PARAMETER";
@@ -324,7 +324,7 @@ static CURLcode rtsp_do(struct Curl_easy *data, bool *done)
   case RTSPREQ_RECEIVE:
     p_request = "";
     /* Treat interleaved RTP as body */
-    data->set.opt_no_body = FALSE;
+    data->req.no_body = FALSE;
     break;
   case RTSPREQ_LAST:
     failf(data, "Got invalid RTSP request: RTSPREQ_LAST");
@@ -573,7 +573,7 @@ static CURLcode rtsp_do(struct Curl_easy *data, bool *done)
     else if(rtspreq == RTSPREQ_GET_PARAMETER) {
       /* Check for an empty GET_PARAMETER (heartbeat) request */
       data->state.httpreq = HTTPREQ_HEAD;
-      data->set.opt_no_body = TRUE;
+      data->req.no_body = TRUE;
     }
   }
 
index 89be8164fc55182e608b8edae1920fd71bd3f198..e704236036ed842e1fa89745a0de7a4ef6c997a1 100644 (file)
@@ -1050,7 +1050,7 @@ static CURLcode smtp_state_command_resp(struct Curl_easy *data, int smtpcode,
   }
   else {
     /* Temporarily add the LF character back and send as body to the client */
-    if(!data->set.opt_no_body) {
+    if(!data->req.no_body) {
       line[len] = '\n';
       result = Curl_client_write(data, CLIENTWRITE_BODY, line, len + 1);
       line[len] = '\0';
@@ -1490,7 +1490,7 @@ static CURLcode smtp_perform(struct Curl_easy *data, bool *connected,
 
   DEBUGF(infof(data, "DO phase starts"));
 
-  if(data->set.opt_no_body) {
+  if(data->req.no_body) {
     /* Requested no body means no transfer */
     smtp->transfer = PPTRANSFER_INFO;
   }
index d1b7083439f39849136002931bab35887d95a684..5ced156982e99c7b1c7794ab95c1b080b697bbef 100644 (file)
@@ -668,7 +668,7 @@ static CURLcode readwrite_data(struct Curl_easy *data,
        is non-headers. */
     if(!k->header && (nread > 0 || is_empty_data)) {
 
-      if(data->set.opt_no_body) {
+      if(data->req.no_body) {
         /* data arrives although we want none, bail out */
         streamclose(conn, "ignoring body");
         *done = TRUE;
@@ -1310,7 +1310,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
      * returning.
      */
 
-    if(!(data->set.opt_no_body) && (k->size != -1) &&
+    if(!(data->req.no_body) && (k->size != -1) &&
        (k->bytecount != k->size) &&
 #ifdef CURL_DO_LINEEND_CONV
        /* Most FTP servers don't adjust their file SIZE response for CRLFs,
@@ -1325,7 +1325,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
       result = CURLE_PARTIAL_FILE;
       goto out;
     }
-    if(!(data->set.opt_no_body) && k->chunk &&
+    if(!(data->req.no_body) && k->chunk &&
        (conn->chunk.state != CHUNK_STOP)) {
       /*
        * In chunked mode, return an error if the connection is closed prior to
@@ -1839,7 +1839,7 @@ CURLcode Curl_follow(struct Curl_easy *data,
       data->state.httpreq = HTTPREQ_GET;
       data->set.upload = false;
       infof(data, "Switch to %s",
-            data->set.opt_no_body?"HEAD":"GET");
+            data->req.no_body?"HEAD":"GET");
     }
     break;
   case 304: /* Not Modified */
@@ -1881,7 +1881,7 @@ CURLcode Curl_retry_request(struct Curl_easy *data, char **url)
 
   if((data->req.bytecount + data->req.headerbytecount == 0) &&
      conn->bits.reuse &&
-     (!data->set.opt_no_body || (conn->handler->protocol & PROTO_FAMILY_HTTP))
+     (!data->req.no_body || (conn->handler->protocol & PROTO_FAMILY_HTTP))
 #ifndef CURL_DISABLE_RTSP
      && (data->set.rtspreq != RTSPREQ_RECEIVE)
 #endif
@@ -1995,7 +1995,7 @@ Curl_setup_transfer(
       Curl_pgrsSetDownloadSize(data, size);
   }
   /* we want header and/or body, if neither then don't do this! */
-  if(k->getheader || !data->set.opt_no_body) {
+  if(k->getheader || !data->req.no_body) {
 
     if(sockindex != -1)
       k->keepon |= KEEP_RECV;
@@ -2031,6 +2031,6 @@ Curl_setup_transfer(
         k->keepon |= KEEP_SEND;
       }
     } /* if(writesockindex != -1) */
-  } /* if(k->getheader || !data->set.opt_no_body) */
+  } /* if(k->getheader || !data->req.no_body) */
 
 }
index ebaedd5f287f3f8dcf3d965ed1c27afd41339713..23038eb31b1c606dfe420c57b18c733260bb19c6 100644 (file)
--- a/lib/url.c
+++ b/lib/url.c
@@ -4115,6 +4115,7 @@ CURLcode Curl_connect(struct Curl_easy *data,
   Curl_free_request_state(data);
   memset(&data->req, 0, sizeof(struct SingleRequest));
   data->req.size = data->req.maxdownload = -1;
+  data->req.no_body = data->set.opt_no_body;
 
   /* call the stuff that needs to be called */
   result = create_conn(data, &conn, asyncp);
@@ -4176,7 +4177,7 @@ CURLcode Curl_init_do(struct Curl_easy *data, struct connectdata *conn)
   data->state.done = FALSE; /* *_done() is not called yet */
   data->state.expect100header = FALSE;
 
-  if(data->set.opt_no_body)
+  if(data->req.no_body)
     /* in HTTP lingo, no body means using the HEAD request... */
     data->state.httpreq = HTTPREQ_HEAD;
 
index 4809c4d3ccbfcb6ebe6b0ddeb59ac464f64a924c..9cc2b323033bb8ef200feab086ecb82d2e5ef381 100644 (file)
@@ -723,6 +723,7 @@ struct SingleRequest {
   BIT(forbidchunk);  /* used only to explicitly forbid chunk-upload for
                         specific upload buffers. See readmoredata() in http.c
                         for details. */
+  BIT(no_body);      /* the response has no body */
 };
 
 /*
index e4e6a66c3a6d196ebca7a32fff819b7df33709a6..df644416826fdbb5d36d764e8c20e708961c1e95 100644 (file)
@@ -1416,7 +1416,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
 
     case SSH_SFTP_READDIR_INIT:
       Curl_pgrsSetDownloadSize(data, -1);
-      if(data->set.opt_no_body) {
+      if(data->req.no_body) {
         state(data, SSH_STOP);
         break;
       }
index 8dc230b59266433e06f8425d2379f1193bb1a110..2211213e3011a81a824731514f45fefb643abcbf 100644 (file)
@@ -2251,7 +2251,7 @@ static CURLcode ssh_statemach_act(struct Curl_easy *data, bool *block)
 
     case SSH_SFTP_READDIR_INIT:
       Curl_pgrsSetDownloadSize(data, -1);
-      if(data->set.opt_no_body) {
+      if(data->req.no_body) {
         state(data, SSH_STOP);
         break;
       }
index 84aecf625590d2de9c61374f3aa7329d926eeed3..25e3112d0551c15ad66aba2c3da51d0ca366e5fe 100644 (file)
@@ -837,7 +837,7 @@ static CURLcode wssh_statemach_act(struct Curl_easy *data, bool *block)
 
     case SSH_SFTP_READDIR_INIT:
       Curl_pgrsSetDownloadSize(data, -1);
-      if(data->set.opt_no_body) {
+      if(data->req.no_body) {
         state(data, SSH_STOP);
         break;
       }