~ubuntu-branches/ubuntu/natty/curl/natty-security

« back to all changes in this revision

Viewing changes to lib/socks.c

  • Committer: Bazaar Package Importer
  • Author(s): Bhavani Shankar
  • Date: 2010-06-20 13:56:28 UTC
  • mfrom: (3.4.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100620135628-e30tp9jldq6hq985
Tags: 7.21.0-1ubuntu1
* Merge from debian unstable.  Remaining changes: LP: #596334
  - Keep build deps in main:
    - Drop build dependencies: stunnel, libssh2-1-dev
    - Add build-dependency on openssh-server
    - Drop libssh2-1-dev from libcurl4-openssl-dev's Depends.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 *                            | (__| |_| |  _ <| |___
6
6
 *                             \___|\___/|_| \_\_____|
7
7
 *
8
 
 * Copyright (C) 1998 - 2009, Daniel Stenberg, <daniel@haxx.se>, et al.
 
8
 * Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
9
9
 *
10
10
 * This software is licensed as described in the file COPYING, which
11
11
 * you should have received as part of this distribution. The terms
18
18
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
19
 * KIND, either express or implied.
20
20
 *
21
 
 * $Id: socks.c,v 1.33 2009-08-29 03:57:28 gknauf Exp $
22
21
 ***************************************************************************/
23
22
 
24
23
#include "setup.h"
72
71
  struct timeval tvnow;
73
72
  long conntime;
74
73
  *n = 0;
75
 
  do {
 
74
  for(;;) {
76
75
    tvnow = Curl_tvnow();
77
76
    /* calculating how long connection is establishing */
78
77
    conntime = Curl_tvdiff(tvnow, conn->created);
79
78
    if(conntime > conn_timeout) {
80
79
      /* we already got the timeout */
81
 
      result = ~CURLE_OK;
 
80
      result = CURLE_OPERATION_TIMEDOUT;
82
81
      break;
83
82
    }
84
83
    if(Curl_socket_ready(sockfd, CURL_SOCKET_BAD,
87
86
      break;
88
87
    }
89
88
    result = Curl_read_plain(sockfd, buf, buffersize, &nread);
90
 
    if(result)
 
89
    if(CURLE_AGAIN == result)
 
90
      continue;
 
91
    else if(result)
91
92
      break;
92
93
 
93
94
    if(buffersize == nread) {
104
105
    buffersize -= nread;
105
106
    buf += nread;
106
107
    allread += nread;
107
 
  } while(1);
 
108
  }
108
109
  return result;
109
110
}
110
111
 
173
174
      return CURLE_COULDNT_RESOLVE_PROXY;
174
175
 
175
176
    if(rc == CURLRESOLV_PENDING)
176
 
      /* this requires that we're in "wait for resolve" state */
177
 
      rc = Curl_wait_for_resolv(conn, &dns);
 
177
      /* ignores the return code, but 'dns' remains NULL on failure */
 
178
      (void)Curl_wait_for_resolv(conn, &dns);
178
179
 
179
180
    /*
180
181
     * We cannot use 'hostent' as a struct that Curl_resolv() returns.  It
393
394
  if(!socks5_resolve_local && hostname_len > 255)
394
395
  {
395
396
    infof(conn->data,"SOCKS5: server resolving disabled for hostnames of "
396
 
          "length > 255 [actual len=%d]\n", hostname_len);
 
397
          "length > 255 [actual len=%zu]\n", hostname_len);
397
398
    socks5_resolve_local = TRUE;
398
399
  }
399
400
 
512
513
     */
513
514
    len = 0;
514
515
    socksreq[len++] = 1;    /* username/pw subnegotiation version */
515
 
    socksreq[len++] = (char) userlen;
516
 
    memcpy(socksreq + len, proxy_name, userlen);
 
516
    socksreq[len++] = (unsigned char) userlen;
 
517
    if(proxy_name && userlen)
 
518
      memcpy(socksreq + len, proxy_name, userlen);
517
519
    len += (int)userlen;
518
 
    socksreq[len++] = (char) pwlen;
519
 
    memcpy(socksreq + len, proxy_password, pwlen);
 
520
    socksreq[len++] = (unsigned char) pwlen;
 
521
    if(proxy_password && pwlen)
 
522
      memcpy(socksreq + len, proxy_password, pwlen);
520
523
    len += (int)pwlen;
521
524
 
522
525
    code = Curl_write_plain(conn, sock, (char *)socksreq, len, &written);
598
601
    if(rc == CURLRESOLV_ERROR)
599
602
      return CURLE_COULDNT_RESOLVE_HOST;
600
603
 
601
 
    if(rc == CURLRESOLV_PENDING)
 
604
    if(rc == CURLRESOLV_PENDING) {
602
605
      /* this requires that we're in "wait for resolve" state */
603
 
      rc = Curl_wait_for_resolv(conn, &dns);
 
606
      code = Curl_wait_for_resolv(conn, &dns);
 
607
      if(code != CURLE_OK)
 
608
        return code;
 
609
    }
604
610
 
605
611
    /*
606
612
     * We cannot use 'hostent' as a struct that Curl_resolv() returns.  It