Skip to content

Commit

Permalink
lib vtls x509asn1
Browse files Browse the repository at this point in the history
temp:
```
C:/projects/curl/lib/vtls/x509asn1.c:961:12: error: cast from function call of type 'CURLcode' to non-matching type 'int' [-Werror=bad-function-cast]
  961 |     return (int)do_pubkey_field(data, certnum, "ecPublicKey", pubkey);
      |            ^
```
Ref: https://ci.appveyor.com/project/curlorg/curl/builds/49704256/job/hcietrd5e7qbu73c#L326
  • Loading branch information
vszakats committed Apr 29, 2024
1 parent 69ea5a8 commit 0defcc3
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions lib/vtls/x509asn1.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ static CURLcode int2str(struct dynbuf *store,
const char *beg, const char *end)
{
unsigned int val = 0;
size_t n = end - beg;
size_t n = (size_t)(end - beg);

if(!n)
return CURLE_BAD_FUNCTION_ARGUMENT;
Expand Down Expand Up @@ -337,8 +337,8 @@ static CURLcode int2str(struct dynbuf *store,
static CURLcode
utf8asn1str(struct dynbuf *to, int type, const char *from, const char *end)
{
size_t inlength = end - from;
int size = 1;
size_t inlength = (size_t)(end - from);
size_t size = 1;
CURLcode result = CURLE_OK;

switch(type) {
Expand Down Expand Up @@ -371,7 +371,7 @@ utf8asn1str(struct dynbuf *to, int type, const char *from, const char *end)
else {
while(!result && (from < end)) {
char buf[4]; /* decode buffer */
int charsize = 1;
size_t charsize = 1;
unsigned int wc = 0;

switch(size) {
Expand Down Expand Up @@ -517,7 +517,9 @@ static CURLcode GTime2str(struct dynbuf *store,
tzp++;
while(tzp < end && *tzp >= '0' && *tzp <= '9');
/* Strip leading zeroes in fractional seconds. */
for(fracl = tzp - fracp - 1; fracl && fracp[fracl - 1] == '0'; fracl--)
for(fracl = (size_t)(tzp - fracp) - 1;
fracl && fracp[fracl - 1] == '0';
fracl--)
;
}

Expand All @@ -533,7 +535,7 @@ static CURLcode GTime2str(struct dynbuf *store,
tzp++;
}

tzl = end - tzp;
tzl = (size_t)(end - tzp);
return Curl_dyn_addf(store,
"%.4s-%.2s-%.2s %.2s:%.2s:%c%c%s%.*s%s%.*s",
beg, beg + 4, beg + 6,
Expand Down Expand Up @@ -578,7 +580,7 @@ static CURLcode UTime2str(struct dynbuf *store,
else
tzp++;

tzl = end - tzp;
tzl = (size_t)(end - tzp);
return Curl_dyn_addf(store, "%u%.2s-%.2s-%.2s %.2s:%.2s:%.2s %.*s",
20 - (*beg >= '5'), beg, beg + 2, beg + 4,
beg + 6, beg + 8, sec,
Expand Down Expand Up @@ -947,7 +949,7 @@ static int do_pubkey(struct Curl_easy *data, int certnum,
* ECC public key is all the data, a value of type BIT STRING mapped to
* OCTET STRING and should not be parsed as an ASN.1 value.
*/
const size_t len = ((pubkey->end - pubkey->beg - 2) * 4);
const size_t len = (((size_t)(pubkey->end - pubkey->beg) - 2) * 4);
if(!certnum)
infof(data, " ECC Public Key (%zu bits)", len);
if(data->set.ssl.certinfo) {
Expand All @@ -956,7 +958,8 @@ static int do_pubkey(struct Curl_easy *data, int certnum,
if(ssl_push_certinfo(data, certnum, "ECC Public Key", q))
return 1;
}
return (int)do_pubkey_field(data, certnum, "ecPublicKey", pubkey);
return do_pubkey_field(data, certnum, "ecPublicKey", pubkey) == CURLE_OK
? 0 : 1;
}

/* Get the public key (single element). */
Expand All @@ -974,7 +977,7 @@ static int do_pubkey(struct Curl_easy *data, int certnum,
/* Compute key length. */
for(q = elem.beg; !*q && q < elem.end; q++)
;
len = ((elem.end - q) * 8);
len = (size_t)(elem.end - q) * 8;
if(len) {
unsigned int i;
for(i = *(unsigned char *) q; !(i & 0x80); i <<= 1)
Expand Down Expand Up @@ -1183,7 +1186,8 @@ CURLcode Curl_extract_certinfo(struct Curl_easy *data,

/* Generate PEM certificate. */
result = Curl_base64_encode(cert.certificate.beg,
cert.certificate.end - cert.certificate.beg,
(size_t)(cert.certificate.end -
cert.certificate.beg),
&certptr, &clen);
if(result)
goto done;
Expand Down

0 comments on commit 0defcc3

Please sign in to comment.