Revert "Update to 7.40.1"
[platform/upstream/curl.git] / lib / telnet.c
index 176e994..1f03a00 100644 (file)
@@ -710,6 +710,7 @@ static void printsub(struct SessionHandle *data,
                      size_t length)             /* length of suboption data */
 {
   unsigned int i = 0;
+  unsigned short *pval;
 
   if(data->set.verbose) {
     if(direction) {
@@ -762,9 +763,9 @@ static void printsub(struct SessionHandle *data,
 
     switch(pointer[0]) {
     case CURL_TELOPT_NAWS:
-      if(length > 4)
-        infof(data, "Width: %hu ; Height: %hu", (pointer[1]<<8) | pointer[2],
-              (pointer[3]<<8) | pointer[4]);
+      pval = (unsigned short*)(pointer+1);
+      infof(data, "Width: %hu ; Height: %hu",
+            ntohs(pval[0]), ntohs(pval[1]));
       break;
     default:
       switch(pointer[1]) {
@@ -1075,7 +1076,7 @@ CURLcode telrcv(struct connectdata *conn,
                                CLIENTWRITE_BODY,              \
                                (char *)&inbuf[startwrite],    \
                                in-startwrite);                \
-    if(result)                                                \
+    if(result != CURLE_OK)                                    \
       return result;                                          \
   }                                                           \
   startwrite = -1
@@ -1229,9 +1230,9 @@ static CURLcode send_telnet_data(struct connectdata *conn,
   unsigned char outbuf[2];
   ssize_t bytes_written, total_written;
   int out_count;
-  CURLcode result = CURLE_OK;
+  CURLcode rc = CURLE_OK;
 
-  while(!result && nread--) {
+  while(rc == CURLE_OK && nread--) {
     outbuf[0] = *buffer++;
     out_count = 1;
     if(outbuf[0] == CURL_IAC)
@@ -1246,20 +1247,19 @@ static CURLcode send_telnet_data(struct connectdata *conn,
       switch (Curl_poll(pfd, 1, -1)) {
         case -1:                    /* error, abort writing */
         case 0:                     /* timeout (will never happen) */
-          result = CURLE_SEND_ERROR;
+          rc = CURLE_SEND_ERROR;
           break;
         default:                    /* write! */
           bytes_written = 0;
-          result = Curl_write(conn, conn->sock[FIRSTSOCKET],
-                              outbuf+total_written, out_count-total_written,
-                              &bytes_written);
+          rc = Curl_write(conn, conn->sock[FIRSTSOCKET], outbuf+total_written,
+                          out_count-total_written, &bytes_written);
           total_written += bytes_written;
           break;
       }
-      /* handle partial write */
-    } while(!result && total_written < out_count);
+    /* handle partial write */
+    } while(rc == CURLE_OK && total_written < out_count);
   }
-  return result;
+  return rc;
 }
 
 static CURLcode telnet_done(struct connectdata *conn,