The attached patch fixes two problems:

1)  Error codes were not properly returned to the main curl code (and on to 
apps using libcurl).

2)  tftp was crapping out when tsize == 0 on upload..but I see no reason to 
fail to upload
  just because the remote file is zero-length.  Ignore tsize option on upload.

This applies on top of my previous patch to fix tftp rate limiting.

Thanks,
Ben

--
Ben Greear <[email protected]>
Candela Technologies Inc  http://www.candelatech.com

diff --git a/lib/tftp.c b/lib/tftp.c
index a286077..6084ebc 100644
--- a/lib/tftp.c
+++ b/lib/tftp.c
@@ -398,12 +398,16 @@ static CURLcode tftp_parse_option_ack(tftp_state_data_t 
*state,
       long tsize = 0;
 
       tsize = strtol( value, NULL, 10 );
-      if(!tsize) {
-        failf(data, "invalid tsize -:%s:- value in OACK packet", value);
-        return CURLE_TFTP_ILLEGAL;
-      }
-      Curl_pgrsSetDownloadSize(data, tsize);
       infof(data, "%s (%ld)\n", "tsize parsed from OACK", tsize);
+
+      /* tsize should be ignored on upload:  Who cares the size of the remote 
file? */
+      if (!data->set.upload) {
+        if(!tsize) {
+          failf(data, "invalid tsize -:%s:- value in OACK packet", value);
+          return CURLE_TFTP_ILLEGAL;
+        }
+        Curl_pgrsSetDownloadSize(data, tsize);
+      }
     }
   }
 
@@ -1462,9 +1466,12 @@ static CURLcode tftp_do(struct connectdata *conn, bool 
*done)
 
   code = tftp_perform(conn, done);
 
-  /* If we have encountered an error */
-  code = tftp_translate_code(state->error);
-
+  /* If we returned an error, just use that...otherwise, look at internal 
codes. */
+  if (code == CURLE_OK) {
+    /* If we have encountered an internal tftp error, translate it. */
+    code = tftp_translate_code(state->error);
+  }
+  
   return code;
 }
 
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html

Reply via email to