diff --git a/src/context.c b/src/context.c index a70b019c..bdb2da7b 100644 --- a/src/context.c +++ b/src/context.c @@ -253,7 +253,7 @@ getdns_context_create_with_extended_memory_functions( mf_union mf; if (!context || !malloc || !realloc || !free) - return GETDNS_RETURN_GENERIC_ERROR; + return GETDNS_RETURN_INVALID_PARAMETER; /** default init **/ mf.ext.malloc = malloc; diff --git a/src/dict.c b/src/dict.c index c1f72836..8fad5c4b 100644 --- a/src/dict.c +++ b/src/dict.c @@ -87,7 +87,7 @@ getdns_dict_get_names(const struct getdns_dict * dict, struct getdns_bindata bindata; if (!dict || !answer) - return GETDNS_RETURN_NO_SUCH_DICT_NAME; + return GETDNS_RETURN_INVALID_PARAMETER; *answer = getdns_list_create_with_extended_memory_functions( dict->mf.mf_arg, dict->mf.mf.ext.malloc, @@ -132,7 +132,7 @@ getdns_dict_get_dict(const struct getdns_dict * dict, const char *name, struct getdns_dict_item *item; if (!dict || !name || !answer) - return GETDNS_RETURN_NO_SUCH_DICT_NAME; + return GETDNS_RETURN_INVALID_PARAMETER; item = getdns_dict_find(dict, name); if (!item) @@ -153,7 +153,7 @@ getdns_dict_get_list(const struct getdns_dict * dict, const char *name, struct getdns_dict_item *item; if (!dict || !name || !answer) - return GETDNS_RETURN_NO_SUCH_DICT_NAME; + return GETDNS_RETURN_INVALID_PARAMETER; item = getdns_dict_find(dict, name); if (!item) @@ -174,7 +174,7 @@ getdns_dict_get_bindata(const struct getdns_dict * dict, const char *name, struct getdns_dict_item *item; if (!dict || !name || !answer) - return GETDNS_RETURN_NO_SUCH_DICT_NAME; + return GETDNS_RETURN_INVALID_PARAMETER; item = getdns_dict_find(dict, name); if (!item) @@ -195,7 +195,7 @@ getdns_dict_get_int(const struct getdns_dict * dict, const char *name, struct getdns_dict_item *item; if (!dict || !name || !answer) - return GETDNS_RETURN_NO_SUCH_DICT_NAME; + return GETDNS_RETURN_INVALID_PARAMETER; item = getdns_dict_find(dict, name); if (!item) @@ -289,7 +289,7 @@ getdns_dict_copy(struct getdns_dict * srcdict, struct getdns_dict ** dstdict) getdns_return_t retval; if (!dstdict) - return GETDNS_RETURN_NO_SUCH_DICT_NAME; + return GETDNS_RETURN_INVALID_PARAMETER; if (!srcdict) { *dstdict = NULL; @@ -301,7 +301,7 @@ getdns_dict_copy(struct getdns_dict * srcdict, struct getdns_dict ** dstdict) srcdict->mf.mf.ext.realloc, srcdict->mf.mf.ext.free); if (!*dstdict) - return GETDNS_RETURN_NO_SUCH_DICT_NAME; + return GETDNS_RETURN_GENERIC_ERROR; retval = GETDNS_RETURN_GOOD; LDNS_RBTREE_FOR(item, struct getdns_dict_item *, &(srcdict->root)) { @@ -741,6 +741,19 @@ getdns_pretty_print_dict(const struct getdns_dict *dict) getdns_return_t getdns_dict_remove_name(struct getdns_dict *this_dict, char *name) { + struct getdns_dict_item *item; + + if (!this_dict || !name) + return GETDNS_RETURN_INVALID_PARAMETER; + + item = getdns_dict_find(this_dict, name, 0); + if (!item) + return GETDNS_RETURN_NO_SUCH_DICT_NAME; + + /* cleanup */ + ldns_rbtree_delete(&this_dict->root, name); + getdns_dict_item_free(&item->node, this_dict); + return GETDNS_RETURN_GENERIC_ERROR; } diff --git a/src/general.c b/src/general.c index 5ea272bb..c5c80b31 100644 --- a/src/general.c +++ b/src/general.c @@ -269,7 +269,7 @@ getdns_general_ub(struct ub_ctx *unbound, int r; if (!name) { - return GETDNS_RETURN_GENERIC_ERROR; + return GETDNS_RETURN_INVALID_PARAMETER; } gr = getdns_context_prepare_for_resolution(context); @@ -337,7 +337,7 @@ getdns_general(struct getdns_context *context, } /* ensure callback is not NULL */ - if (!callback) { + if (!callback || !name) { return GETDNS_RETURN_INVALID_PARAMETER; } diff --git a/src/list.c b/src/list.c index 7508769b..8cabcc55 100644 --- a/src/list.c +++ b/src/list.c @@ -55,12 +55,12 @@ getdns_return_t getdns_list_get_data_type(const struct getdns_list * list, size_t index, getdns_data_type * answer) { - if (!list || index >= list->numinuse) - return GETDNS_RETURN_NO_SUCH_LIST_ITEM; - - if (!answer) + if (!list || !answer) return GETDNS_RETURN_INVALID_PARAMETER; + if (index >= list->numinuse) + return GETDNS_RETURN_NO_SUCH_LIST_ITEM; + *answer = list->items[index].dtype; return GETDNS_RETURN_GOOD; } /* getdns_list_get_data_type */ @@ -70,12 +70,12 @@ getdns_return_t getdns_list_get_dict(const struct getdns_list * list, size_t index, struct getdns_dict ** answer) { - if (!list || index >= list->numinuse) - return GETDNS_RETURN_NO_SUCH_LIST_ITEM; - - if (!answer) + if (!list || !answer) return GETDNS_RETURN_INVALID_PARAMETER; + if (index >= list->numinuse) + return GETDNS_RETURN_NO_SUCH_LIST_ITEM; + if (list->items[index].dtype != t_dict) return GETDNS_RETURN_WRONG_TYPE_REQUESTED; @@ -88,13 +88,12 @@ getdns_return_t getdns_list_get_list(const struct getdns_list * list, size_t index, struct getdns_list ** answer) { - - if (!list || index >= list->numinuse) - return GETDNS_RETURN_NO_SUCH_LIST_ITEM; - - if (!answer) + if (!list || !answer) return GETDNS_RETURN_INVALID_PARAMETER; + if (index >= list->numinuse) + return GETDNS_RETURN_NO_SUCH_LIST_ITEM; + if (list->items[index].dtype != t_list) return GETDNS_RETURN_WRONG_TYPE_REQUESTED; @@ -107,12 +106,13 @@ getdns_return_t getdns_list_get_bindata(const struct getdns_list * list, size_t index, struct getdns_bindata ** answer) { - if (!list || index >= list->numinuse) - return GETDNS_RETURN_NO_SUCH_LIST_ITEM; - if (!answer) + if (!list || !answer) return GETDNS_RETURN_INVALID_PARAMETER; + if (index >= list->numinuse) + return GETDNS_RETURN_NO_SUCH_LIST_ITEM; + if (list->items[index].dtype != t_bindata) return GETDNS_RETURN_WRONG_TYPE_REQUESTED; @@ -125,12 +125,12 @@ getdns_return_t getdns_list_get_int(const struct getdns_list * list, size_t index, uint32_t * answer) { - if (!list || index >= list->numinuse) - return GETDNS_RETURN_NO_SUCH_LIST_ITEM; - - if (!answer) + if (!list || !answer) return GETDNS_RETURN_INVALID_PARAMETER; + if (index >= list->numinuse) + return GETDNS_RETURN_NO_SUCH_LIST_ITEM; + if (list->items[index].dtype != t_int) return GETDNS_RETURN_WRONG_TYPE_REQUESTED; @@ -152,7 +152,7 @@ getdns_list_realloc(struct getdns_list *list) struct getdns_list_item *newlist; if (!list) - return GETDNS_RETURN_GENERIC_ERROR; + return GETDNS_RETURN_INVALID_PARAMETER; newlist = GETDNS_XREALLOC(list->mf, list->items, struct getdns_list_item, @@ -174,7 +174,7 @@ getdns_list_copy(struct getdns_list * srclist, struct getdns_list ** dstlist) getdns_return_t retval; if (!dstlist) - return GETDNS_RETURN_NO_SUCH_LIST_ITEM; + return GETDNS_RETURN_INVALID_PARAMETER; if (!srclist) { *dstlist = NULL; @@ -187,7 +187,7 @@ getdns_list_copy(struct getdns_list * srclist, struct getdns_list ** dstlist) srclist->mf.mf.ext.free ); if (!dstlist) - return GETDNS_RETURN_NO_SUCH_LIST_ITEM; + return GETDNS_RETURN_GENERIC_ERROR; for (i = 0; i < srclist->numinuse; i++) { retval = getdns_list_add_item(*dstlist, &index);