mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-05 12:25:07 -05:00
rewrite some assertions for better readability
Some assertions are written as "if (x) assert(0)" to avoid having the text of a long argument compiled in the binary. Rewrite them to use a new BRIEF_ASSERT macro to make the condition easier to read in its non-negated form and make it easier to turn it back to the full-text assert if needed.
This commit is contained in:
@@ -520,8 +520,7 @@ generate_key(int index)
|
||||
ServerKey *key;
|
||||
int key_length;
|
||||
|
||||
if (index < 0 || index >= MAX_SERVER_KEYS)
|
||||
assert(0);
|
||||
BRIEF_ASSERT(index >= 0 && index < MAX_SERVER_KEYS);
|
||||
|
||||
/* Prefer AES-128-GCM-SIV if available. Note that if older keys loaded
|
||||
from ntsdumpdir use a different algorithm, responding to NTP requests
|
||||
@@ -534,8 +533,7 @@ generate_key(int index)
|
||||
key = &server_keys[index];
|
||||
|
||||
key_length = SIV_GetKeyLength(algorithm);
|
||||
if (key_length > sizeof (key->key))
|
||||
assert(0);
|
||||
BRIEF_ASSERT(key_length <= sizeof (key->key));
|
||||
|
||||
UTI_GetRandomBytesUrandom(key->key, key_length);
|
||||
memset(key->key + key_length, 0, sizeof (key->key) - key_length);
|
||||
@@ -961,8 +959,7 @@ NKS_GenerateCookie(NKE_Context *context, NKE_Cookie *cookie)
|
||||
header->key_id = htonl(key->id);
|
||||
|
||||
nonce = cookie->cookie + sizeof (*header);
|
||||
if (key->nonce_length > sizeof (cookie->cookie) - sizeof (*header))
|
||||
assert(0);
|
||||
BRIEF_ASSERT(key->nonce_length <= sizeof (cookie->cookie) - sizeof (*header));
|
||||
UTI_GetRandomBytes(nonce, key->nonce_length);
|
||||
|
||||
plaintext_length = context->c2s.length + context->s2c.length;
|
||||
|
||||
Reference in New Issue
Block a user