forked from git/git
-
Notifications
You must be signed in to change notification settings - Fork 157
Fix curl_easy_setopt()
parameter type problem, again
#1974
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ struct packed_git; | |
#include <curl/curl.h> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this): "Johannes Schindelin via GitGitGadget" <[email protected]>
writes:
> From: Johannes Schindelin <[email protected]>
>
> This commit moves the `xcurl_off_t()` function, which validates that a
> given value fits within the `curl_off_t` data type and then casts it, to
> a more central place so that it can be used outside of `remote-curl.c`,
> too.
>
> At the same time, this function is renamed to conform better with the
> naming convention of the helper functions that safely cast from one data
> type to another which has been well established in `git-compat-util.h`.
OK. The code inside the renamed function is the same with an
updated message to show the value.
> With this move, the error message can unfortunately no longer be renamed
> because the `_(...)` function is not available at the time of
> definition.
It is not clear to me what change (or lack thereof?) in this patch
this paragraph refers to. Who wants to rename what error message
and why?
> Signed-off-by: Johannes Schindelin <[email protected]>
> ---
> http.h | 10 ++++++++++
> remote-curl.c | 14 +++-----------
> 2 files changed, 13 insertions(+), 11 deletions(-)
Thanks; will queue.
> +static inline curl_off_t cast_size_t_to_curl_off_t(size_t a)
> +{
> + uintmax_t size = a;
> + if (size > maximum_signed_value_of_type(curl_off_t))
> + die(_("number too large to represent as curl_off_t "
> + "on this platform: %"PRIuMAX), (uintmax_t)a);
> + return (curl_off_t)a;
> +}
> +
> -static curl_off_t xcurl_off_t(size_t len)
> -{
> - uintmax_t size = len;
> - if (size > maximum_signed_value_of_type(curl_off_t))
> - die(_("cannot handle pushes this big"));
> - return (curl_off_t)size;
> -}
|
||
#include <curl/easy.h> | ||
|
||
#include "gettext.h" | ||
#include "strbuf.h" | ||
#include "remote.h" | ||
|
||
|
@@ -95,6 +96,15 @@ static inline int missing__target(int code, int result) | |
|
||
#define missing_target(a) missing__target((a)->http_code, (a)->curl_result) | ||
|
||
static inline curl_off_t cast_size_t_to_curl_off_t(size_t a) | ||
{ | ||
uintmax_t size = a; | ||
if (size > maximum_signed_value_of_type(curl_off_t)) | ||
die(_("number too large to represent as curl_off_t " | ||
"on this platform: %"PRIuMAX), (uintmax_t)a); | ||
return (curl_off_t)a; | ||
} | ||
|
||
/* | ||
* Normalize curl results to handle CURL_FAILONERROR (or lack thereof). Failing | ||
* http codes have their "result" converted to CURLE_HTTP_RETURNED_ERROR, and | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1721,7 +1721,7 @@ static int curl_append_msgs_to_imap(struct imap_server_conf *server, | |
lf_to_crlf(&msgbuf.buf); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this): "Johannes Schindelin via GitGitGadget" <[email protected]>
writes:
> From: Johannes Schindelin <[email protected]>
>
> When casting a `size_t` to `curl_off_t`, there is a currently uncommon
> chance that the value can be cut off (`curl_off_t` is supposed to be
> guaranteed to be 64-bit).
"64-bit" -> "signed 64-bit", per what <curl/system.h> says,
i.e. "curl_off_t MUST be typedef'ed to a 64-bit * wide signed
integral data type.", perhaps?
msgbuf.buf is a strbuf, so its .len member is of size_t (so is
prev_len); prev_len is how big the msgbuf.buf was before the code
added some stuff taken from all_msgs, possibly wrapping the result
in html, and converting lf to crlf, all only enlarging the buffer.
We are computing how much we bloated the msgbuf.buf relative to the
original here, so this subtraction should not suffer unsigned
wraparound. Now thanks to the previous step, we can consistently
and safely cast size_t values to curl_off_t easily, which is nice.
Looking good. Will queue. Thanks.
> diff --git a/imap-send.c b/imap-send.c
> index 4bd5b8aa0d..26dda7f328 100644
> --- a/imap-send.c
> +++ b/imap-send.c
> @@ -1721,7 +1721,7 @@ static int curl_append_msgs_to_imap(struct imap_server_conf *server,
> lf_to_crlf(&msgbuf.buf);
>
> curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE,
> - (curl_off_t)(msgbuf.buf.len-prev_len));
> + cast_size_t_to_curl_off_t(msgbuf.buf.len-prev_len));
>
> res = curl_easy_perform(curl); |
||
|
||
curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, | ||
(curl_off_t)(msgbuf.buf.len-prev_len)); | ||
cast_size_t_to_curl_off_t(msgbuf.buf.len-prev_len)); | ||
|
||
res = curl_easy_perform(curl); | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the Git mailing list, Junio C Hamano wrote (reply to this):