Skip to content

Commit

Permalink
Merge pull request #456 from ruby/compilation-warnings
Browse files Browse the repository at this point in the history
Suppress compilation warnings
  • Loading branch information
rhenium committed Sep 12, 2021
2 parents cf54f72 + 258e30b commit 5c85b43
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 26 deletions.
4 changes: 2 additions & 2 deletions ext/openssl/ossl.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* Data Conversion
*/
#define OSSL_IMPL_ARY2SK(name, type, expected_class, dup) \
STACK_OF(type) * \
VALUE \
ossl_##name##_ary2sk0(VALUE ary) \
{ \
STACK_OF(type) *sk; \
Expand All @@ -43,7 +43,7 @@ ossl_##name##_ary2sk0(VALUE ary) \
x = dup(val); /* NEED TO DUP */ \
sk_##type##_push(sk, x); \
} \
return sk; \
return (VALUE)sk; \
} \
\
STACK_OF(type) * \
Expand Down
18 changes: 15 additions & 3 deletions ext/openssl/ossl_asn1.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ asn1time_to_time(const ASN1_TIME *time)
return rb_funcall2(rb_cTime, rb_intern("utc"), 6, argv);
}

static VALUE
asn1time_to_time_i(VALUE arg)
{
return asn1time_to_time((ASN1_TIME *)arg);
}

void
ossl_time_split(VALUE time, time_t *sec, int *days)
{
Expand Down Expand Up @@ -136,6 +142,12 @@ num_to_asn1integer(VALUE obj, ASN1_INTEGER *ai)
return ai;
}

static VALUE
asn1integer_to_num_i(VALUE arg)
{
return asn1integer_to_num((ASN1_INTEGER *)arg);
}

/********/
/*
* ASN1 module
Expand Down Expand Up @@ -325,7 +337,7 @@ decode_int(unsigned char* der, long length)
p = der;
if(!(ai = d2i_ASN1_INTEGER(NULL, &p, length)))
ossl_raise(eASN1Error, NULL);
ret = rb_protect((VALUE (*)(VALUE))asn1integer_to_num,
ret = rb_protect(asn1integer_to_num_i,
(VALUE)ai, &status);
ASN1_INTEGER_free(ai);
if(status) rb_jump_tag(status);
Expand Down Expand Up @@ -365,7 +377,7 @@ decode_enum(unsigned char* der, long length)
p = der;
if(!(ai = d2i_ASN1_ENUMERATED(NULL, &p, length)))
ossl_raise(eASN1Error, NULL);
ret = rb_protect((VALUE (*)(VALUE))asn1integer_to_num,
ret = rb_protect(asn1integer_to_num_i,
(VALUE)ai, &status);
ASN1_ENUMERATED_free(ai);
if(status) rb_jump_tag(status);
Expand Down Expand Up @@ -427,7 +439,7 @@ decode_time(unsigned char* der, long length)
p = der;
if(!(time = d2i_ASN1_TIME(NULL, &p, length)))
ossl_raise(eASN1Error, NULL);
ret = rb_protect((VALUE (*)(VALUE))asn1time_to_time,
ret = rb_protect(asn1time_to_time_i,
(VALUE)time, &status);
ASN1_TIME_free(time);
if(status) rb_jump_tag(status);
Expand Down
8 changes: 4 additions & 4 deletions ext/openssl/ossl_cipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ ossl_cipher_copy(VALUE self, VALUE other)
return self;
}

static void*
add_cipher_name_to_ary(const OBJ_NAME *name, VALUE ary)
static void
add_cipher_name_to_ary(const OBJ_NAME *name, void *arg)
{
VALUE ary = (VALUE)arg;
rb_ary_push(ary, rb_str_new2(name->name));
return NULL;
}

/*
Expand All @@ -169,7 +169,7 @@ ossl_s_ciphers(VALUE self)

ary = rb_ary_new();
OBJ_NAME_do_all_sorted(OBJ_NAME_TYPE_CIPHER_METH,
(void(*)(const OBJ_NAME*,void*))add_cipher_name_to_ary,
add_cipher_name_to_ary,
(void*)ary);

return ary;
Expand Down
24 changes: 21 additions & 3 deletions ext/openssl/ossl_pkcs12.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,24 @@ ossl_pkcs12_s_create(int argc, VALUE *argv, VALUE self)
return obj;
}

static VALUE
ossl_pkey_new_i(VALUE arg)
{
return ossl_pkey_new((EVP_PKEY *)arg);
}

static VALUE
ossl_x509_new_i(VALUE arg)
{
return ossl_x509_new((X509 *)arg);
}

static VALUE
ossl_x509_sk2ary_i(VALUE arg)
{
return ossl_x509_sk2ary((STACK_OF(X509) *)arg);
}

/*
* call-seq:
* PKCS12.new -> pkcs12
Expand Down Expand Up @@ -186,15 +204,15 @@ ossl_pkcs12_initialize(int argc, VALUE *argv, VALUE self)
ossl_raise(ePKCS12Error, "PKCS12_parse");
ERR_pop_to_mark();
if (key) {
pkey = rb_protect((VALUE (*)(VALUE))ossl_pkey_new, (VALUE)key, &st);
pkey = rb_protect(ossl_pkey_new_i, (VALUE)key, &st);
if (st) goto err;
}
if (x509) {
cert = rb_protect((VALUE (*)(VALUE))ossl_x509_new, (VALUE)x509, &st);
cert = rb_protect(ossl_x509_new_i, (VALUE)x509, &st);
if (st) goto err;
}
if (x509s) {
ca = rb_protect((VALUE (*)(VALUE))ossl_x509_sk2ary, (VALUE)x509s, &st);
ca = rb_protect(ossl_x509_sk2ary_i, (VALUE)x509s, &st);
if (st) goto err;
}

Expand Down
5 changes: 3 additions & 2 deletions ext/openssl/ossl_pkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ const rb_data_type_t ossl_evp_pkey_type = {
};

static VALUE
pkey_new0(EVP_PKEY *pkey)
pkey_new0(VALUE arg)
{
EVP_PKEY *pkey = (EVP_PKEY *)arg;
VALUE klass, obj;
int type;

Expand Down Expand Up @@ -69,7 +70,7 @@ ossl_pkey_new(EVP_PKEY *pkey)
VALUE obj;
int status;

obj = rb_protect((VALUE (*)(VALUE))pkey_new0, (VALUE)pkey, &status);
obj = rb_protect(pkey_new0, (VALUE)pkey, &status);
if (status) {
EVP_PKEY_free(pkey);
rb_jump_tag(status);
Expand Down
2 changes: 2 additions & 0 deletions ext/openssl/ossl_pkey_ec.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ static VALUE ossl_ec_key_set_private_key(VALUE self, VALUE private_key)
case 0:
if (bn == NULL)
break;
/* fallthrough */
default:
ossl_raise(eECError, "EC_KEY_set_private_key");
}
Expand Down Expand Up @@ -334,6 +335,7 @@ static VALUE ossl_ec_key_set_public_key(VALUE self, VALUE public_key)
case 0:
if (point == NULL)
break;
/* fallthrough */
default:
ossl_raise(eECError, "EC_KEY_set_public_key");
}
Expand Down
15 changes: 9 additions & 6 deletions ext/openssl/ossl_ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,22 +239,23 @@ struct tmp_dh_callback_args {
int keylength;
};

static EVP_PKEY *
ossl_call_tmp_dh_callback(struct tmp_dh_callback_args *args)
static VALUE
ossl_call_tmp_dh_callback(VALUE arg)
{
struct tmp_dh_callback_args *args = (struct tmp_dh_callback_args *)arg;
VALUE cb, dh;
EVP_PKEY *pkey;

cb = rb_funcall(args->ssl_obj, args->id, 0);
if (NIL_P(cb))
return NULL;
return (VALUE)NULL;
dh = rb_funcall(cb, id_call, 3, args->ssl_obj, INT2NUM(args->is_export),
INT2NUM(args->keylength));
pkey = GetPKeyPtr(dh);
if (EVP_PKEY_base_id(pkey) != args->type)
return NULL;
return (VALUE)NULL;

return pkey;
return (VALUE)pkey;
}
#endif

Expand All @@ -274,7 +275,7 @@ ossl_tmp_dh_callback(SSL *ssl, int is_export, int keylength)
args.keylength = keylength;
args.type = EVP_PKEY_DH;

pkey = (EVP_PKEY *)rb_protect((VALUE (*)(VALUE))ossl_call_tmp_dh_callback,
pkey = (EVP_PKEY *)rb_protect(ossl_call_tmp_dh_callback,
(VALUE)&args, &state);
if (state) {
rb_ivar_set(rb_ssl, ID_callback_state, INT2NUM(state));
Expand Down Expand Up @@ -1620,6 +1621,7 @@ ossl_start_ssl(VALUE self, int (*func)(), const char *funcname, VALUE opts)
err_msg, verify_msg);
}
#endif
/* fallthrough */
default:
ossl_raise(eSSLError, "%s returned=%d errno=%d peeraddr=%"PRIsVALUE" state=%s",
funcname, ret2, errno, peeraddr_ip_str(self), SSL_state_string_long(ssl));
Expand Down Expand Up @@ -1904,6 +1906,7 @@ ossl_ssl_write_internal(VALUE self, VALUE str, VALUE opts)
continue;
#endif
if (errno) rb_sys_fail(0);
/* fallthrough */
default:
ossl_raise(eSSLError, "SSL_write");
}
Expand Down
24 changes: 21 additions & 3 deletions ext/openssl/ossl_ts.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ obj_to_asn1obj(VALUE obj)
return a1obj;
}

static VALUE
obj_to_asn1obj_i(VALUE obj)
{
return (VALUE)obj_to_asn1obj(obj);
}

static VALUE
get_asn1obj(ASN1_OBJECT *obj)
{
Expand Down Expand Up @@ -1078,6 +1084,18 @@ ossl_tsfac_time_cb(struct TS_resp_ctx *ctx, void *data, long *sec, long *usec)
return 1;
}

static VALUE
ossl_evp_get_digestbyname_i(VALUE arg)
{
return (VALUE)ossl_evp_get_digestbyname(arg);
}

static VALUE
ossl_obj2bio_i(VALUE arg)
{
return (VALUE)ossl_obj2bio((VALUE *)arg);
}

/*
* Creates a Response with the help of an OpenSSL::PKey, an
* OpenSSL::X509::Certificate and a Request.
Expand Down Expand Up @@ -1146,7 +1164,7 @@ ossl_tsfac_create_ts(VALUE self, VALUE key, VALUE certificate, VALUE request)
goto end;
}
if (!NIL_P(def_policy_id) && !TS_REQ_get_policy_id(req)) {
def_policy_id_obj = (ASN1_OBJECT*)rb_protect((VALUE (*)(VALUE))obj_to_asn1obj, (VALUE)def_policy_id, &status);
def_policy_id_obj = (ASN1_OBJECT*)rb_protect(obj_to_asn1obj_i, (VALUE)def_policy_id, &status);
if (status)
goto end;
}
Expand Down Expand Up @@ -1188,7 +1206,7 @@ ossl_tsfac_create_ts(VALUE self, VALUE key, VALUE certificate, VALUE request)

for (i = 0; i < RARRAY_LEN(allowed_digests); i++) {
rbmd = rb_ary_entry(allowed_digests, i);
md = (const EVP_MD *)rb_protect((VALUE (*)(VALUE))ossl_evp_get_digestbyname, rbmd, &status);
md = (const EVP_MD *)rb_protect(ossl_evp_get_digestbyname_i, rbmd, &status);
if (status)
goto end;
TS_RESP_CTX_add_md(ctx, md);
Expand All @@ -1199,7 +1217,7 @@ ossl_tsfac_create_ts(VALUE self, VALUE key, VALUE certificate, VALUE request)
if (status)
goto end;

req_bio = (BIO*)rb_protect((VALUE (*)(VALUE))ossl_obj2bio, (VALUE)&str, &status);
req_bio = (BIO*)rb_protect(ossl_obj2bio_i, (VALUE)&str, &status);
if (status)
goto end;

Expand Down
13 changes: 10 additions & 3 deletions ext/openssl/ossl_x509store.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,15 @@ struct ossl_verify_cb_args {
};

static VALUE
call_verify_cb_proc(struct ossl_verify_cb_args *args)
ossl_x509stctx_new_i(VALUE arg)
{
return ossl_x509stctx_new((X509_STORE_CTX *)arg);
}

static VALUE
call_verify_cb_proc(VALUE arg)
{
struct ossl_verify_cb_args *args = (struct ossl_verify_cb_args *)arg;
return rb_funcall(args->proc, rb_intern("call"), 2,
args->preverify_ok, args->store_ctx);
}
Expand All @@ -69,7 +76,7 @@ ossl_verify_cb_call(VALUE proc, int ok, X509_STORE_CTX *ctx)
return ok;

ret = Qfalse;
rctx = rb_protect((VALUE(*)(VALUE))ossl_x509stctx_new, (VALUE)ctx, &state);
rctx = rb_protect(ossl_x509stctx_new_i, (VALUE)ctx, &state);
if (state) {
rb_set_errinfo(Qnil);
rb_warn("StoreContext initialization failure");
Expand All @@ -78,7 +85,7 @@ ossl_verify_cb_call(VALUE proc, int ok, X509_STORE_CTX *ctx)
args.proc = proc;
args.preverify_ok = ok ? Qtrue : Qfalse;
args.store_ctx = rctx;
ret = rb_protect((VALUE(*)(VALUE))call_verify_cb_proc, (VALUE)&args, &state);
ret = rb_protect(call_verify_cb_proc, (VALUE)&args, &state);
if (state) {
rb_set_errinfo(Qnil);
rb_warn("exception in verify_callback is ignored");
Expand Down

0 comments on commit 5c85b43

Please sign in to comment.