2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 06:25:31 +00:00

Use clang-tidy to add curly braces around one-line statements

The command used to reformat the files in this commit was:

./util/run-clang-tidy \
	-clang-tidy-binary clang-tidy-11
	-clang-apply-replacements-binary clang-apply-replacements-11 \
	-checks=-*,readability-braces-around-statements \
	-j 9 \
	-fix \
	-format \
	-style=file \
	-quiet
clang-format -i --style=format $(git ls-files '*.c' '*.h')
uncrustify -c .uncrustify.cfg --replace --no-backup $(git ls-files '*.c' '*.h')
clang-format -i --style=format $(git ls-files '*.c' '*.h')
This commit is contained in:
Ondřej Surý
2020-02-13 21:48:23 +01:00
parent d14bb71319
commit 056e133c4c
637 changed files with 28926 additions and 16901 deletions

View File

@@ -31,14 +31,14 @@
#include <pk11/site.h>
#if !defined(OPENSSL_NO_ENGINE)
#include <openssl/engine.h>
#endif
#endif /* if !defined(OPENSSL_NO_ENGINE) */
/*
* Limit the size of public exponents.
*/
#ifndef RSA_MAX_PUBEXP_BITS
#define RSA_MAX_PUBEXP_BITS 35
#endif
#endif /* ifndef RSA_MAX_PUBEXP_BITS */
/*
* We don't use configure for windows so enforce the OpenSSL version
@@ -46,7 +46,7 @@
*/
#if defined(WIN32) && (OPENSSL_VERSION_NUMBER < 0x10000000L)
#error Please upgrade OpenSSL to 1.0.0 or greater.
#endif
#endif /* if defined(WIN32) && (OPENSSL_VERSION_NUMBER < 0x10000000L) */
#define DST_RET(a) \
{ \
@@ -65,7 +65,7 @@ RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d)
* left NULL (in case only the public key is used).
*/
if ((r->n == NULL && n == NULL) || (r->e == NULL && e == NULL)) {
return 0;
return (0);
}
if (n != NULL) {
@@ -81,7 +81,7 @@ RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d)
r->d = d;
}
return 1;
return (1);
}
static int
@@ -92,7 +92,7 @@ RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q)
* parameters MUST be non-NULL.
*/
if ((r->p == NULL && p == NULL) || (r->q == NULL && q == NULL)) {
return 0;
return (0);
}
if (p != NULL) {
@@ -104,7 +104,7 @@ RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q)
r->q = q;
}
return 1;
return (1);
}
static int
@@ -117,7 +117,7 @@ RSA_set0_crt_params(RSA *r, BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp)
if ((r->dmp1 == NULL && dmp1 == NULL) ||
(r->dmq1 == NULL && dmq1 == NULL) ||
(r->iqmp == NULL && iqmp == NULL)) {
return 0;
return (0);
}
if (dmp1 != NULL) {
@@ -133,7 +133,7 @@ RSA_set0_crt_params(RSA *r, BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp)
r->iqmp = iqmp;
}
return 1;
return (1);
}
static void
@@ -206,19 +206,23 @@ opensslrsa_createctx(dst_key_t *key, dst_context_t *dctx)
case DST_ALG_RSASHA1:
case DST_ALG_NSEC3RSASHA1:
/* From RFC 3110 */
if (dctx->key->key_size > 4096)
if (dctx->key->key_size > 4096) {
return (ISC_R_FAILURE);
}
break;
case DST_ALG_RSASHA256:
/* From RFC 5702 */
if ((dctx->key->key_size < 512) || (dctx->key->key_size > 4096))
if ((dctx->key->key_size < 512) ||
(dctx->key->key_size > 4096)) {
return (ISC_R_FAILURE);
}
break;
case DST_ALG_RSASHA512:
/* From RFC 5702 */
if ((dctx->key->key_size < 1024) ||
(dctx->key->key_size > 4096))
(dctx->key->key_size > 4096)) {
return (ISC_R_FAILURE);
}
break;
default:
INSIST(0);
@@ -226,8 +230,9 @@ opensslrsa_createctx(dst_key_t *key, dst_context_t *dctx)
}
evp_md_ctx = EVP_MD_CTX_create();
if (evp_md_ctx == NULL)
if (evp_md_ctx == NULL) {
return (ISC_R_NOMEMORY);
}
switch (dctx->key->key_alg) {
case DST_ALG_RSASHA1:
@@ -304,8 +309,9 @@ opensslrsa_sign(dst_context_t *dctx, isc_buffer_t *sig)
isc_buffer_availableregion(sig, &r);
if (r.length < (unsigned int)EVP_PKEY_size(pkey))
if (r.length < (unsigned int)EVP_PKEY_size(pkey)) {
return (ISC_R_NOSPACE);
}
if (!EVP_SignFinal(evp_md_ctx, r.base, &siglen, pkey)) {
return (dst__openssl_toresult3(dctx->category, "EVP_SignFinal",
@@ -334,13 +340,15 @@ opensslrsa_verify2(dst_context_t *dctx, int maxbits, const isc_region_t *sig)
dctx->key->key_alg == DST_ALG_RSASHA512);
rsa = EVP_PKEY_get1_RSA(pkey);
if (rsa == NULL)
if (rsa == NULL) {
return (dst__openssl_toresult(DST_R_OPENSSLFAILURE));
}
RSA_get0_key(rsa, NULL, &e, NULL);
bits = BN_num_bits(e);
RSA_free(rsa);
if (bits > maxbits && maxbits != 0)
if (bits > maxbits && maxbits != 0) {
return (DST_R_VERIFYFAILURE);
}
status = EVP_VerifyFinal(evp_md_ctx, sig->base, sig->length, pkey);
switch (status) {
@@ -388,23 +396,26 @@ opensslrsa_compare(const dst_key_t *key1, const dst_key_t *key2)
RSA_free(rsa2);
}
if (rsa1 == NULL && rsa2 == NULL)
if (rsa1 == NULL && rsa2 == NULL) {
return (true);
else if (rsa1 == NULL || rsa2 == NULL)
} else if (rsa1 == NULL || rsa2 == NULL) {
return (false);
}
RSA_get0_key(rsa1, &n1, &e1, &d1);
RSA_get0_key(rsa2, &n2, &e2, &d2);
status = BN_cmp(n1, n2) || BN_cmp(e1, e2);
if (status != 0)
if (status != 0) {
return (false);
}
if (RSA_test_flags(rsa1, RSA_FLAG_EXT_PKEY) != 0 ||
RSA_test_flags(rsa2, RSA_FLAG_EXT_PKEY) != 0) {
if (RSA_test_flags(rsa1, RSA_FLAG_EXT_PKEY) == 0 ||
RSA_test_flags(rsa2, RSA_FLAG_EXT_PKEY) == 0)
RSA_test_flags(rsa2, RSA_FLAG_EXT_PKEY) == 0) {
return (false);
}
/*
* Can't compare private parameters, BTW does it make sense?
*/
@@ -412,14 +423,16 @@ opensslrsa_compare(const dst_key_t *key1, const dst_key_t *key2)
}
if (d1 != NULL || d2 != NULL) {
if (d1 == NULL || d2 == NULL)
if (d1 == NULL || d2 == NULL) {
return (false);
}
RSA_get0_factors(rsa1, &p1, &q1);
RSA_get0_factors(rsa2, &p2, &q2);
status = BN_cmp(d1, d2) || BN_cmp(p1, p1) || BN_cmp(q1, q2);
if (status != 0)
if (status != 0) {
return (false);
}
}
return (true);
}
@@ -435,8 +448,9 @@ progress_cb(int p, int n, BN_GENCB *cb)
UNUSED(n);
u.dptr = BN_GENCB_get_arg(cb);
if (u.fptr != NULL)
if (u.fptr != NULL) {
u.fptr(p);
}
return (1);
}
@@ -452,7 +466,8 @@ opensslrsa_generate(dst_key_t *key, int exp, void (*callback)(int))
BIGNUM *e = BN_new();
#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
BN_GENCB _cb;
#endif
#endif /* if OPENSSL_VERSION_NUMBER < 0x10100000L || \
* defined(LIBRESSL_VERSION_NUMBER) */
BN_GENCB *cb = BN_GENCB_new();
EVP_PKEY *pkey = EVP_PKEY_new();
@@ -463,30 +478,36 @@ opensslrsa_generate(dst_key_t *key, int exp, void (*callback)(int))
case DST_ALG_RSASHA1:
case DST_ALG_NSEC3RSASHA1:
/* From RFC 3110 */
if (key->key_size > 4096)
if (key->key_size > 4096) {
goto err;
}
break;
case DST_ALG_RSASHA256:
/* From RFC 5702 */
if ((key->key_size < 512) || (key->key_size > 4096))
if ((key->key_size < 512) || (key->key_size > 4096)) {
goto err;
}
break;
case DST_ALG_RSASHA512:
/* From RFC 5702 */
if ((key->key_size < 1024) || (key->key_size > 4096))
if ((key->key_size < 1024) || (key->key_size > 4096)) {
goto err;
}
break;
default:
INSIST(0);
ISC_UNREACHABLE();
}
if (rsa == NULL || e == NULL || cb == NULL)
if (rsa == NULL || e == NULL || cb == NULL) {
goto err;
if (pkey == NULL)
}
if (pkey == NULL) {
goto err;
if (!EVP_PKEY_set1_RSA(pkey, rsa))
}
if (!EVP_PKEY_set1_RSA(pkey, rsa)) {
goto err;
}
if (exp == 0) {
/* RSA_F4 0x10001 */
@@ -545,8 +566,9 @@ opensslrsa_isprivate(const dst_key_t *key)
INSIST(rsa != NULL);
RSA_free(rsa);
/* key->keydata.pkey still has a reference so rsa is still valid. */
if (rsa != NULL && RSA_test_flags(rsa, RSA_FLAG_EXT_PKEY) != 0)
if (rsa != NULL && RSA_test_flags(rsa, RSA_FLAG_EXT_PKEY) != 0) {
return (true);
}
RSA_get0_key(rsa, NULL, NULL, &d);
return (rsa != NULL && d != NULL);
}
@@ -574,8 +596,9 @@ opensslrsa_todns(const dst_key_t *key, isc_buffer_t *data)
pkey = key->keydata.pkey;
rsa = EVP_PKEY_get1_RSA(pkey);
if (rsa == NULL)
if (rsa == NULL) {
return (dst__openssl_toresult(DST_R_OPENSSLFAILURE));
}
isc_buffer_availableregion(data, &r);
@@ -584,20 +607,23 @@ opensslrsa_todns(const dst_key_t *key, isc_buffer_t *data)
e_bytes = BN_num_bytes(e);
if (e_bytes < 256) { /*%< key exponent is <= 2040 bits */
if (r.length < 1)
if (r.length < 1) {
DST_RET(ISC_R_NOSPACE);
}
isc_buffer_putuint8(data, (uint8_t)e_bytes);
isc_region_consume(&r, 1);
} else {
if (r.length < 3)
if (r.length < 3) {
DST_RET(ISC_R_NOSPACE);
}
isc_buffer_putuint8(data, 0);
isc_buffer_putuint16(data, (uint16_t)e_bytes);
isc_region_consume(&r, 3);
}
if (r.length < e_bytes + mod_bytes)
if (r.length < e_bytes + mod_bytes) {
DST_RET(ISC_R_NOSPACE);
}
RSA_get0_key(rsa, &n, &e, NULL);
BN_bn2bin(e, r.base);
@@ -623,13 +649,15 @@ opensslrsa_fromdns(dst_key_t *key, isc_buffer_t *data)
BIGNUM * e = NULL, *n = NULL;
isc_buffer_remainingregion(data, &r);
if (r.length == 0)
if (r.length == 0) {
return (ISC_R_SUCCESS);
}
length = r.length;
rsa = RSA_new();
if (rsa == NULL)
if (rsa == NULL) {
return (dst__openssl_toresult(ISC_R_NOMEMORY));
}
if (r.length < 1) {
RSA_free(rsa);
@@ -657,10 +685,12 @@ opensslrsa_fromdns(dst_key_t *key, isc_buffer_t *data)
isc_region_consume(&r, e_bytes);
n = BN_bin2bn(r.base, r.length, NULL);
if (RSA_set0_key(rsa, n, e, NULL) == 0) {
if (n != NULL)
if (n != NULL) {
BN_free(n);
if (e != NULL)
}
if (e != NULL) {
BN_free(e);
}
RSA_free(rsa);
return (ISC_R_NOMEMORY);
}
@@ -696,11 +726,13 @@ opensslrsa_tofile(const dst_key_t *key, const char *directory)
const BIGNUM * p = NULL, *q = NULL;
const BIGNUM * dmp1 = NULL, *dmq1 = NULL, *iqmp = NULL;
if (key->keydata.pkey == NULL)
if (key->keydata.pkey == NULL) {
return (DST_R_NULLKEY);
}
rsa = EVP_PKEY_get1_RSA(key->keydata.pkey);
if (rsa == NULL)
if (rsa == NULL) {
return (dst__openssl_toresult(DST_R_OPENSSLFAILURE));
}
memset(bufs, 0, sizeof(bufs));
RSA_get0_key(rsa, &n, &e, &d);
@@ -800,8 +832,9 @@ opensslrsa_tofile(const dst_key_t *key, const char *directory)
fail:
RSA_free(rsa);
for (i = 0; i < 8; i++) {
if (bufs[i] == NULL)
if (bufs[i] == NULL) {
break;
}
isc_mem_put(key->mctx, bufs[i], BN_num_bytes(n));
}
return (result);
@@ -822,27 +855,32 @@ rsa_check(RSA *rsa, RSA *pub)
if (pub != NULL) {
RSA_get0_key(pub, &n2, &e2, NULL);
if (n1 != NULL) {
if (BN_cmp(n1, n2) != 0)
if (BN_cmp(n1, n2) != 0) {
return (DST_R_INVALIDPRIVATEKEY);
}
} else {
n = BN_dup(n2);
}
if (e1 != NULL) {
if (BN_cmp(e1, e2) != 0)
if (BN_cmp(e1, e2) != 0) {
return (DST_R_INVALIDPRIVATEKEY);
}
} else {
e = BN_dup(e2);
}
if (RSA_set0_key(rsa, n, e, NULL) == 0) {
if (n != NULL)
if (n != NULL) {
BN_free(n);
if (e != NULL)
}
if (e != NULL) {
BN_free(e);
}
}
}
RSA_get0_key(rsa, &n1, &e1, NULL);
if (n1 == NULL || e1 == NULL)
if (n1 == NULL || e1 == NULL) {
return (DST_R_INVALIDPRIVATEKEY);
}
return (ISC_R_SUCCESS);
}
@@ -856,7 +894,7 @@ opensslrsa_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub)
#if !defined(OPENSSL_NO_ENGINE)
ENGINE * ep = NULL;
const BIGNUM *ex = NULL;
#endif
#endif /* if !defined(OPENSSL_NO_ENGINE) */
isc_mem_t * mctx = key->mctx;
const char *engine = NULL, *label = NULL;
EVP_PKEY * pkey = NULL;
@@ -866,14 +904,17 @@ opensslrsa_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub)
/* read private key file */
ret = dst__privstruct_parse(key, DST_ALG_RSA, lexer, mctx, &priv);
if (ret != ISC_R_SUCCESS)
if (ret != ISC_R_SUCCESS) {
goto err;
}
if (key->external) {
if (priv.nelements != 0)
if (priv.nelements != 0) {
DST_RET(DST_R_INVALIDPRIVATEKEY);
if (pub == NULL)
}
if (pub == NULL) {
DST_RET(DST_R_INVALIDPRIVATEKEY);
}
key->keydata.pkey = pub->keydata.pkey;
pub->keydata.pkey = NULL;
key->key_size = pub->key_size;
@@ -882,8 +923,9 @@ opensslrsa_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub)
return (ISC_R_SUCCESS);
}
if (pub != NULL && pub->keydata.pkey != NULL)
if (pub != NULL && pub->keydata.pkey != NULL) {
pubrsa = EVP_PKEY_get1_RSA(pub->keydata.pkey);
}
for (i = 0; i < priv.nelements; i++) {
switch (priv.elements[i].tag) {
@@ -904,48 +946,58 @@ opensslrsa_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub)
*/
if (label != NULL) {
#if !defined(OPENSSL_NO_ENGINE)
if (engine == NULL)
if (engine == NULL) {
DST_RET(DST_R_NOENGINE);
}
ep = dst__openssl_getengine(engine);
if (ep == NULL)
if (ep == NULL) {
DST_RET(DST_R_NOENGINE);
}
pkey = ENGINE_load_private_key(ep, label, NULL, NULL);
if (pkey == NULL)
if (pkey == NULL) {
DST_RET(dst__openssl_toresult2("ENGINE_load_private_"
"key",
ISC_R_NOTFOUND));
}
key->engine = isc_mem_strdup(key->mctx, engine);
key->label = isc_mem_strdup(key->mctx, label);
rsa = EVP_PKEY_get1_RSA(pkey);
if (rsa == NULL)
if (rsa == NULL) {
DST_RET(dst__openssl_toresult(DST_R_OPENSSLFAILURE));
if (rsa_check(rsa, pubrsa) != ISC_R_SUCCESS)
}
if (rsa_check(rsa, pubrsa) != ISC_R_SUCCESS) {
DST_RET(DST_R_INVALIDPRIVATEKEY);
}
RSA_get0_key(rsa, NULL, &ex, NULL);
if (BN_num_bits(ex) > RSA_MAX_PUBEXP_BITS)
if (BN_num_bits(ex) > RSA_MAX_PUBEXP_BITS) {
DST_RET(ISC_R_RANGE);
if (pubrsa != NULL)
}
if (pubrsa != NULL) {
RSA_free(pubrsa);
}
key->key_size = EVP_PKEY_bits(pkey);
key->keydata.pkey = pkey;
RSA_free(rsa);
dst__privstruct_free(&priv, mctx);
isc_safe_memwipe(&priv, sizeof(priv));
return (ISC_R_SUCCESS);
#else
#else /* if !defined(OPENSSL_NO_ENGINE) */
DST_RET(DST_R_NOENGINE);
#endif
#endif /* if !defined(OPENSSL_NO_ENGINE) */
}
rsa = RSA_new();
if (rsa == NULL)
if (rsa == NULL) {
DST_RET(ISC_R_NOMEMORY);
}
pkey = EVP_PKEY_new();
if (pkey == NULL)
if (pkey == NULL) {
DST_RET(ISC_R_NOMEMORY);
if (!EVP_PKEY_set1_RSA(pkey, rsa))
}
if (!EVP_PKEY_set1_RSA(pkey, rsa)) {
DST_RET(ISC_R_FAILURE);
}
key->keydata.pkey = pkey;
for (i = 0; i < priv.nelements; i++) {
@@ -958,8 +1010,9 @@ opensslrsa_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub)
default:
bn = BN_bin2bn(priv.elements[i].data,
priv.elements[i].length, NULL);
if (bn == NULL)
if (bn == NULL) {
DST_RET(ISC_R_NOMEMORY);
}
switch (priv.elements[i].tag) {
case TAG_RSA_MODULUS:
n = bn;
@@ -992,46 +1045,60 @@ opensslrsa_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub)
isc_safe_memwipe(&priv, sizeof(priv));
if (RSA_set0_key(rsa, n, e, d) == 0) {
if (n != NULL)
if (n != NULL) {
BN_free(n);
if (e != NULL)
}
if (e != NULL) {
BN_free(e);
if (d != NULL)
}
if (d != NULL) {
BN_free(d);
}
}
if (RSA_set0_factors(rsa, p, q) == 0) {
if (p != NULL)
if (p != NULL) {
BN_free(p);
if (q != NULL)
}
if (q != NULL) {
BN_free(q);
}
}
if (RSA_set0_crt_params(rsa, dmp1, dmq1, iqmp) == 0) {
if (dmp1 != NULL)
if (dmp1 != NULL) {
BN_free(dmp1);
if (dmq1 != NULL)
}
if (dmq1 != NULL) {
BN_free(dmq1);
if (iqmp != NULL)
}
if (iqmp != NULL) {
BN_free(iqmp);
}
}
if (rsa_check(rsa, pubrsa) != ISC_R_SUCCESS)
if (rsa_check(rsa, pubrsa) != ISC_R_SUCCESS) {
DST_RET(DST_R_INVALIDPRIVATEKEY);
if (BN_num_bits(e) > RSA_MAX_PUBEXP_BITS)
}
if (BN_num_bits(e) > RSA_MAX_PUBEXP_BITS) {
DST_RET(ISC_R_RANGE);
}
key->key_size = BN_num_bits(n);
if (pubrsa != NULL)
if (pubrsa != NULL) {
RSA_free(pubrsa);
}
RSA_free(rsa);
return (ISC_R_SUCCESS);
err:
if (pkey != NULL)
if (pkey != NULL) {
EVP_PKEY_free(pkey);
if (rsa != NULL)
}
if (rsa != NULL) {
RSA_free(rsa);
if (pubrsa != NULL)
}
if (pubrsa != NULL) {
RSA_free(pubrsa);
}
key->keydata.generic = NULL;
dst__privstruct_free(&priv, mctx);
isc_safe_memwipe(&priv, sizeof(priv));
@@ -1093,20 +1160,23 @@ opensslrsa_fromlabel(dst_key_t *key, const char *engine, const char *label,
return (ISC_R_SUCCESS);
err:
if (rsa != NULL)
if (rsa != NULL) {
RSA_free(rsa);
if (pubrsa != NULL)
}
if (pubrsa != NULL) {
RSA_free(pubrsa);
if (pkey != NULL)
}
if (pkey != NULL) {
EVP_PKEY_free(pkey);
}
return (ret);
#else
#else /* if !defined(OPENSSL_NO_ENGINE) */
UNUSED(key);
UNUSED(engine);
UNUSED(label);
UNUSED(pin);
return (DST_R_NOENGINE);
#endif
#endif /* if !defined(OPENSSL_NO_ENGINE) */
}
static dst_func_t opensslrsa_functions = {