~ubuntu-branches/ubuntu/jaunty/curl/jaunty-security

« back to all changes in this revision

Viewing changes to lib/tftp.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-08-01 12:22:30 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20070801122230-uaarmp6lo65py9t6
Tags: 7.16.4-1ubuntu1
* Merge with Debian.
  - Drop debian/patches/gnutls-verifications, applied upstream.
  - Remove all stuff which should be reverted according to 7.16.2-6ubuntu4.
  - Remaining change: drop stunnel build dependency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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: tftp.c,v 1.42 2007-04-11 00:25:41 danf Exp $
 
21
 * $Id: tftp.c,v 1.48 2007-06-12 08:15:02 bagder Exp $
22
22
 ***************************************************************************/
23
23
 
24
24
#include "setup.h"
136
136
  time_t          max_time;
137
137
  unsigned short  block;
138
138
  struct Curl_sockaddr_storage   local_addr;
139
 
  socklen_t       local_addrlen;
140
139
  struct Curl_sockaddr_storage   remote_addr;
141
140
  socklen_t       remote_addrlen;
142
141
  int             rbytes;
180
179
    /* Average restart after 5 seconds */
181
180
    state->retry_max = timeout/5;
182
181
 
 
182
    if(state->retry_max < 1)
 
183
      /* avoid division by zero below */
 
184
      state->retry_max = 1;
 
185
 
183
186
    /* Compute the re-start interval to suit the timeout */
184
187
    state->retry_time = timeout/state->retry_max;
185
188
    if(state->retry_time<1)
367
370
                    state->remote_addrlen);
368
371
    if(sbytes < 0) {
369
372
      failf(data, "%s\n", Curl_strerror(state->conn, SOCKERRNO));
 
373
      return CURLE_SEND_ERROR;
370
374
    }
371
375
 
372
376
    /* Check if completed (That is, a less than full packet is received) */
396
400
      /* Check all sbytes were sent */
397
401
      if(sbytes<0) {
398
402
        failf(data, "%s\n", Curl_strerror(state->conn, SOCKERRNO));
 
403
        return CURLE_SEND_ERROR;
399
404
      }
400
405
    }
401
406
    break;
406
411
 
407
412
  default:
408
413
    failf(data, "%s\n", "tftp_rx: internal error");
409
 
    break;
 
414
    return CURLE_TFTP_ILLEGAL; /* not really the perfect return code for
 
415
                                  this */
410
416
  }
411
 
  Curl_pgrsSetDownloadCounter(data,
412
 
                              (curl_off_t) state->block*TFTP_BLOCKSIZE);
413
417
  return CURLE_OK;
414
418
}
415
419
 
426
430
  int sbytes;
427
431
  int rblock;
428
432
  CURLcode res = CURLE_OK;
 
433
  struct Curl_transfer_keeper *k = &data->reqdata.keep;
429
434
 
430
435
  switch(event) {
431
436
 
478
483
    /* Check all sbytes were sent */
479
484
    if(sbytes<0) {
480
485
      failf(data, "%s\n", Curl_strerror(state->conn, SOCKERRNO));
 
486
      return CURLE_SEND_ERROR;
481
487
    }
 
488
    /* Update the progress meter */
 
489
    k->writebytecount += state->sbytes;
 
490
    Curl_pgrsSetUploadCounter(data, k->writebytecount);
482
491
    break;
483
492
 
484
493
  case TFTP_EVENT_TIMEOUT:
490
499
    if(state->retries > state->retry_max) {
491
500
      state->error = TFTP_ERR_TIMEOUT;
492
501
      state->state = TFTP_STATE_FIN;
493
 
    } else {
 
502
    }
 
503
    else {
494
504
      /* Re-send the data packet */
495
505
      sbytes = sendto(state->sockfd, (void *)&state->spacket,
496
506
                      4+state->sbytes, SEND_4TH_ARG,
499
509
      /* Check all sbytes were sent */
500
510
      if(sbytes<0) {
501
511
        failf(data, "%s\n", Curl_strerror(state->conn, SOCKERRNO));
 
512
        return CURLE_SEND_ERROR;
502
513
      }
 
514
      /* since this was a re-send, we remain at the still byte position */
 
515
      Curl_pgrsSetUploadCounter(data, k->writebytecount);
503
516
    }
504
517
    break;
505
518
 
512
525
    break;
513
526
  }
514
527
 
515
 
  /* Update the progress meter */
516
 
  Curl_pgrsSetUploadCounter(data, (curl_off_t) state->block*TFTP_BLOCKSIZE);
517
 
 
518
528
  return res;
519
529
}
520
530
 
659
669
  struct Curl_sockaddr_storage fromaddr;
660
670
  socklen_t             fromlen;
661
671
  int                   check_time = 0;
 
672
  struct Curl_transfer_keeper *k = &data->reqdata.keep;
662
673
 
663
674
  *done = TRUE;
664
675
 
675
686
    state = (tftp_state_data_t *)conn->data->reqdata.proto.tftp;
676
687
  }
677
688
 
 
689
  code = Curl_readwrite_init(conn);
 
690
  if(code)
 
691
    return code;
 
692
 
678
693
  /* Run the TFTP State Machine */
679
694
  for(code=tftp_state_machine(state, TFTP_EVENT_INIT);
680
695
      (state->state != TFTP_STATE_FIN) && (code == CURLE_OK);
681
696
      code=tftp_state_machine(state, event) ) {
682
697
 
683
698
    /* Wait until ready to read or timeout occurs */
684
 
    rc=Curl_socket_ready(state->sockfd, CURL_SOCKET_BAD, state->retry_time * 1000);
 
699
    rc=Curl_socket_ready(state->sockfd, CURL_SOCKET_BAD,
 
700
                         state->retry_time * 1000);
685
701
 
686
702
    if(rc == -1) {
687
703
      /* bail out */
730
746
                                     state->rbytes-4);
731
747
            if(code)
732
748
              return code;
 
749
            k->bytecount += state->rbytes-4;
 
750
            Curl_pgrsSetDownloadCounter(data, (curl_off_t) k->bytecount);
733
751
          }
734
752
          break;
735
753
        case TFTP_EVENT_ERROR: