Skip to content
Snippets Groups Projects
Commit 0e444baa authored by Jan Včelák's avatar Jan Včelák :rocket:
Browse files

DNSSEC: review fixes, mostly coding style and parameter checks

refs #4
parent 729d653a
No related branches found
No related tags found
No related merge requests found
......@@ -16,7 +16,7 @@
/*!
* \file strtonum.h
*
* \brief Universal interface for save conversion of strings to numbers.
* \brief Universal interface for safe conversion of strings to numbers.
*
* \author Jan Vcelak <jan.vcelak@nic.cz>
*
......
......@@ -25,7 +25,7 @@
int knot_binary_from_base64(const char *base64, knot_binary_t *to)
{
if (!to) {
if (!base64 || !to) {
return KNOT_EINVAL;
}
......
......@@ -54,6 +54,10 @@ static uint16_t keytag_rsa_md5(const uint8_t *rdata, uint16_t rdata_len)
*/
uint16_t knot_keytag(const uint8_t *rdata, uint16_t rdata_len)
{
if (!rdata || rdata_len < 4) {
return 0;
}
uint32_t ac = 0; /* assumed to be 32 bits or larger */
if (rdata[3] == 1) {
......@@ -340,8 +344,9 @@ static int parse_keyfile_line(knot_key_params_t *key_params,
*/
int knot_load_key_params(const char *filename, knot_key_params_t *key_params)
{
assert(filename);
assert(key_params);
if (!filename || !key_params) {
return KNOT_EINVAL;
}
int result;
char *public_key = NULL;
......@@ -445,7 +450,9 @@ int knot_copy_key_params(const knot_key_params_t *src, knot_key_params_t *dst)
*/
int knot_free_key_params(knot_key_params_t *key_params)
{
assert(key_params);
if (!key_params) {
return KNOT_EINVAL;
}
knot_dname_free(&key_params->name);
......@@ -478,7 +485,9 @@ int knot_free_key_params(knot_key_params_t *key_params)
*/
knot_key_type_t knot_get_key_type(const knot_key_params_t *key_params)
{
assert(key_params);
if (!key_params) {
return KNOT_EINVAL;
}
if (key_params->secret.size > 0) {
return KNOT_KEY_TSIG;
......@@ -502,13 +511,15 @@ knot_key_type_t knot_get_key_type(const knot_key_params_t *key_params)
int knot_tsig_create_key(const char *name, int algorithm,
const char *b64secret, knot_tsig_key_t *key)
{
if (!name || !b64secret || !key)
if (!name || !b64secret || !key) {
return KNOT_EINVAL;
}
knot_dname_t *dname;
dname = knot_dname_from_str(name, strlen(name));
if (!dname)
if (!dname) {
return KNOT_ENOMEM;
}
knot_binary_t secret;
int result = knot_binary_from_base64(b64secret, &secret);
......@@ -530,12 +541,14 @@ int knot_tsig_create_key(const char *name, int algorithm,
int knot_tsig_key_from_params(const knot_key_params_t *params,
knot_tsig_key_t *key)
{
if (!params || !params->name || params->secret.size == 0)
if (!params || !params->name || params->secret.size == 0) {
return KNOT_EINVAL;
}
int result = knot_binary_dup(&params->secret, &key->secret);
if (result != KNOT_EOK)
if (result != KNOT_EOK) {
return result;
}
key->name = knot_dname_copy(params->name);
......@@ -549,8 +562,9 @@ int knot_tsig_key_from_params(const knot_key_params_t *params,
*/
int knot_tsig_key_free(knot_tsig_key_t *key)
{
if (!key)
if (!key) {
return KNOT_EINVAL;
}
knot_dname_free(&key->name);
knot_binary_free(&key->secret);
......
......@@ -168,6 +168,8 @@ int knot_tsig_key_from_params(const knot_key_params_t *params,
/*!
* \brief Frees TSIG key.
*
* The structure itself is not freed.
*
* \param key TSIG key structure to be freed.
*
* \return Error code, KNOT_EOK when succeeded.
......
......@@ -60,16 +60,18 @@ inline static void bitmap_add_type(bitmap_t *bitmap, uint16_t type)
int win = type / BITMAP_WINDOW_SIZE;
int bit = type % BITMAP_WINDOW_SIZE;
if (bitmap->used <= win)
if (bitmap->used <= win) {
bitmap->used = win + 1;
}
int win_byte = bit / CHAR_BIT;
int win_bit = bit % CHAR_BIT;
bitmap_window_t *window = &bitmap->windows[win];
window->data[win_byte] |= 0x80 >> win_bit;
if (window->used <= win_byte)
if (window->used <= win_byte) {
window->used = win_byte + 1;
}
}
/*!
......@@ -93,8 +95,9 @@ inline static size_t bitmap_size(const bitmap_t *bitmap)
for (int i = 0; i < bitmap->used; i++) {
int used = bitmap->windows[i].used;
if (used == 0)
if (used == 0) {
continue;
}
result += 2 + used; // windows number, window size, data
}
......@@ -110,8 +113,9 @@ inline static void bitmap_write(const bitmap_t *bitmap, uint8_t *output)
uint8_t *write_ptr = output;
for (int win = 0; win < bitmap->used; win++) {
int used = bitmap->windows[win].used;
if (used == 0)
if (used == 0) {
continue;
}
*write_ptr = (uint8_t)win;
write_ptr += 1;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment