Commit 796333bc authored by Steve Holme's avatar Steve Holme
Browse files

smtp: Fixed processing of more than one response when sent in same packet

Added a loop to smtp_statemach_act() in which Curl_pp_readresp() is
called until the cache is drained. Without this multiple responses
received in a single packet could result in a hang or delay.
parent f16c0de4
Loading
Loading
Loading
Loading
+12 −9
Original line number Original line Diff line number Diff line
@@ -1352,16 +1352,19 @@ static CURLcode smtp_statemach_act(struct connectdata *conn)
  if(pp->sendleft)
  if(pp->sendleft)
    return Curl_pp_flushsend(pp);
    return Curl_pp_flushsend(pp);


  do {
    /* Read the response from the server */
    /* Read the response from the server */
    result = Curl_pp_readresp(sock, pp, &smtpcode, &nread);
    result = Curl_pp_readresp(sock, pp, &smtpcode, &nread);
    if(result)
    if(result)
      return result;
      return result;


  /* Store the latest response for later retrieval */
    /* Store the latest response for later retrieval if necessary */
    if(smtpc->state != SMTP_QUIT && smtpcode != 1)
    if(smtpc->state != SMTP_QUIT && smtpcode != 1)
      data->info.httpcode = smtpcode;
      data->info.httpcode = smtpcode;


  if(smtpcode) {
    if(!smtpcode)
      break;

    /* We have now received a full SMTP server response */
    /* We have now received a full SMTP server response */
    switch(smtpc->state) {
    switch(smtpc->state) {
    case SMTP_SERVERGREET:
    case SMTP_SERVERGREET:
@@ -1453,7 +1456,7 @@ static CURLcode smtp_statemach_act(struct connectdata *conn)
      state(conn, SMTP_STOP);
      state(conn, SMTP_STOP);
      break;
      break;
    }
    }
  }
  } while(!result && smtpc->state != SMTP_STOP && Curl_pp_moredata(pp));


  return result;
  return result;
}
}