Git fork

Merge branch 'js/curl-off-t-fixes'

A few places where an size_t value was cast to curl_off_t without
checking has been updated to use the existing helper function.

* js/curl-off-t-fixes:
http-push: avoid new compile error
imap-send: be more careful when casting to `curl_off_t`
http: offer to cast `size_t` to `curl_off_t` safely

+16 -13
+2 -1
http-push.c
··· 208 curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); 209 curl_easy_setopt(curl, CURLOPT_URL, url); 210 curl_easy_setopt(curl, CURLOPT_INFILE, buffer); 211 - curl_easy_setopt(curl, CURLOPT_INFILESIZE, buffer->buf.len); 212 curl_easy_setopt(curl, CURLOPT_READFUNCTION, fread_buffer); 213 curl_easy_setopt(curl, CURLOPT_SEEKFUNCTION, seek_buffer); 214 curl_easy_setopt(curl, CURLOPT_SEEKDATA, buffer);
··· 208 curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); 209 curl_easy_setopt(curl, CURLOPT_URL, url); 210 curl_easy_setopt(curl, CURLOPT_INFILE, buffer); 211 + curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, 212 + cast_size_t_to_curl_off_t(buffer->buf.len)); 213 curl_easy_setopt(curl, CURLOPT_READFUNCTION, fread_buffer); 214 curl_easy_setopt(curl, CURLOPT_SEEKFUNCTION, seek_buffer); 215 curl_easy_setopt(curl, CURLOPT_SEEKDATA, buffer);
+10
http.h
··· 8 #include <curl/curl.h> 9 #include <curl/easy.h> 10 11 #include "strbuf.h" 12 #include "remote.h" 13 ··· 94 } 95 96 #define missing_target(a) missing__target((a)->http_code, (a)->curl_result) 97 98 /* 99 * Normalize curl results to handle CURL_FAILONERROR (or lack thereof). Failing
··· 8 #include <curl/curl.h> 9 #include <curl/easy.h> 10 11 + #include "gettext.h" 12 #include "strbuf.h" 13 #include "remote.h" 14 ··· 95 } 96 97 #define missing_target(a) missing__target((a)->http_code, (a)->curl_result) 98 + 99 + static inline curl_off_t cast_size_t_to_curl_off_t(size_t a) 100 + { 101 + uintmax_t size = a; 102 + if (size > maximum_signed_value_of_type(curl_off_t)) 103 + die(_("number too large to represent as curl_off_t " 104 + "on this platform: %"PRIuMAX), (uintmax_t)a); 105 + return (curl_off_t)a; 106 + } 107 108 /* 109 * Normalize curl results to handle CURL_FAILONERROR (or lack thereof). Failing
+1 -1
imap-send.c
··· 1721 lf_to_crlf(&msgbuf.buf); 1722 1723 curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, 1724 - (curl_off_t)(msgbuf.buf.len-prev_len)); 1725 1726 res = curl_easy_perform(curl); 1727
··· 1721 lf_to_crlf(&msgbuf.buf); 1722 1723 curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, 1724 + cast_size_t_to_curl_off_t(msgbuf.buf.len-prev_len)); 1725 1726 res = curl_easy_perform(curl); 1727
+3 -11
remote-curl.c
··· 894 return err; 895 } 896 897 - static curl_off_t xcurl_off_t(size_t len) 898 - { 899 - uintmax_t size = len; 900 - if (size > maximum_signed_value_of_type(curl_off_t)) 901 - die(_("cannot handle pushes this big")); 902 - return (curl_off_t)size; 903 - } 904 - 905 /* 906 * If flush_received is true, do not attempt to read any more; just use what's 907 * in rpc->buf. ··· 999 * and we just need to send it. 1000 */ 1001 curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, gzip_body); 1002 - curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE_LARGE, xcurl_off_t(gzip_size)); 1003 1004 } else if (use_gzip && 1024 < rpc->len) { 1005 /* The client backend isn't giving us compressed data so ··· 1030 1031 headers = curl_slist_append(headers, "Content-Encoding: gzip"); 1032 curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, gzip_body); 1033 - curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE_LARGE, xcurl_off_t(gzip_size)); 1034 1035 if (options.verbosity > 1) { 1036 fprintf(stderr, "POST %s (gzip %lu to %lu bytes)\n", ··· 1043 * more normal Content-Length approach. 1044 */ 1045 curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, rpc->buf); 1046 - curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE_LARGE, xcurl_off_t(rpc->len)); 1047 if (options.verbosity > 1) { 1048 fprintf(stderr, "POST %s (%lu bytes)\n", 1049 rpc->service_name, (unsigned long)rpc->len);
··· 894 return err; 895 } 896 897 /* 898 * If flush_received is true, do not attempt to read any more; just use what's 899 * in rpc->buf. ··· 991 * and we just need to send it. 992 */ 993 curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, gzip_body); 994 + curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE_LARGE, cast_size_t_to_curl_off_t(gzip_size)); 995 996 } else if (use_gzip && 1024 < rpc->len) { 997 /* The client backend isn't giving us compressed data so ··· 1022 1023 headers = curl_slist_append(headers, "Content-Encoding: gzip"); 1024 curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, gzip_body); 1025 + curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE_LARGE, cast_size_t_to_curl_off_t(gzip_size)); 1026 1027 if (options.verbosity > 1) { 1028 fprintf(stderr, "POST %s (gzip %lu to %lu bytes)\n", ··· 1035 * more normal Content-Length approach. 1036 */ 1037 curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, rpc->buf); 1038 + curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE_LARGE, cast_size_t_to_curl_off_t(rpc->len)); 1039 if (options.verbosity > 1) { 1040 fprintf(stderr, "POST %s (%lu bytes)\n", 1041 rpc->service_name, (unsigned long)rpc->len);