From 2c664e73fe7a1b51d0306c8feede6b5d2ab07ea4 Mon Sep 17 00:00:00 2001 From: Neel Goyal Date: Fri, 10 Jan 2014 09:58:33 -0500 Subject: [PATCH 1/6] Add the INVALID_PARAMETER return type --- src/getdns/getdns.h | 4 +++- src/getdns_error.c | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/getdns/getdns.h b/src/getdns/getdns.h index 2ce5ba54..8e0fcd30 100644 --- a/src/getdns/getdns.h +++ b/src/getdns/getdns.h @@ -9,7 +9,7 @@ /* * Copyright (c) 2013, NLNet Labs, Versign, Inc. * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright @@ -74,6 +74,8 @@ struct event_base; #define GETDNS_RETURN_DNSSEC_WITH_STUB_DISALLOWED_TEXT "A query was made with a context that is using stub resolution and a DNSSEC extension specified." #define GETDNS_RETURN_MEMORY_ERROR 310 #define GETDNS_RETURN_MEMORY_ERROR_TEXT "Unable to allocate the memory required." +#define GETDNS_RETURN_INVALID_PARAMETER 311 +#define GETDNS_RETURN_INVALID_PARAMETER_TEXT "A required parameter had an invalid value." /** @} */ diff --git a/src/getdns_error.c b/src/getdns_error.c index c3282dc8..638e1c96 100644 --- a/src/getdns_error.c +++ b/src/getdns_error.c @@ -61,8 +61,11 @@ getdns_lookup_table getdns_error_str[] = { {GETDNS_RETURN_DNSSEC_WITH_STUB_DISALLOWED, "A query was made with a context that is using stub resolution and a DNSSEC extension specified."} , - {GETDNS_RETURN_MEMORY_ERROR, + {GETDNS_RETURN_MEMORY_ERROR, "Unable to allocate the memory required."} + , + {GETDNS_RETURN_INVALID_PARAMETER, + GETDNS_RETURN_INVALID_PARAMETER_TEXT } , {0, ""} }; From 34d3f1f938abab1d003a9b01c123e7701746a7cf Mon Sep 17 00:00:00 2001 From: Neel Goyal Date: Fri, 10 Jan 2014 10:09:07 -0500 Subject: [PATCH 2/6] Fix for issue #67. return INVALID_PARAMETER if name, dict, or child dict are NULL --- src/dict.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/dict.c b/src/dict.c index d2667ce0..75e3a73e 100644 --- a/src/dict.c +++ b/src/dict.c @@ -1,9 +1,9 @@ /** * - * getdns list management functions, note that the internal storage is + * getdns list management functions, note that the internal storage is * accomplished via the libc binary search tree implementation so your * pointer foo needs to be keen to digest some of the internal semantics - * + * * Interfaces originally taken from the getdns API description pseudo implementation. * */ @@ -11,7 +11,7 @@ /* * Copyright (c) 2013, Versign, Inc. * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright @@ -370,8 +370,8 @@ getdns_dict_set_dict(struct getdns_dict * dict, char *name, struct getdns_dict *newdict; getdns_return_t retval; - if (!dict || !name) - return GETDNS_RETURN_NO_SUCH_DICT_NAME; + if (!dict || !name || !child_dict) + return GETDNS_RETURN_INVALID_PARAMETER; retval = getdns_dict_copy(child_dict, &newdict); if (retval != GETDNS_RETURN_GOOD) @@ -459,7 +459,7 @@ getdns_dict_set_int(struct getdns_dict * dict, char *name, /*---------------------------------------- getdns_pp_dict */ /** - * private function to help with indenting. + * private function to help with indenting. * @param indent number of spaces to return * @return a character string containing min(80, indent) spaces */ From 722a27bfefb278dec879505e0f067bbdc6482c2c Mon Sep 17 00:00:00 2001 From: Neel Goyal Date: Fri, 10 Jan 2014 10:28:28 -0500 Subject: [PATCH 3/6] fix for issue #49 --- src/general.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/general.c b/src/general.c index 58b632d7..5ea272bb 100644 --- a/src/general.c +++ b/src/general.c @@ -10,7 +10,7 @@ /* * Copyright (c) 2013, Versign, Inc. * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright @@ -196,7 +196,7 @@ ub_resolve_callback(void *arg, int err, ldns_buffer * result, int sec, */ if (netreq->state == NET_REQ_NOT_SENT) { /* just do a very short timer since this was called immediately. - * we can make this less hacky, but it gets interesting when multiple + * we can make this less hacky, but it gets interesting when multiple * netreqs need to be issued and some resolve immediately vs. not. */ struct timeval tv; @@ -329,13 +329,18 @@ getdns_general(struct getdns_context *context, { int extcheck = GETDNS_RETURN_GOOD; - if (!context || !context->event_base_async || callback == NULL) { + if (!context || !context->event_base_async) { /* Can't do async without an event loop * or callback */ return GETDNS_RETURN_BAD_CONTEXT; } + /* ensure callback is not NULL */ + if (!callback) { + return GETDNS_RETURN_INVALID_PARAMETER; + } + extcheck = validate_extensions(extensions); if (extcheck != GETDNS_RETURN_GOOD) return extcheck; From a08a4130c0bc4471f839b80ccc315dbb456a617e Mon Sep 17 00:00:00 2001 From: Neel Goyal Date: Fri, 10 Jan 2014 10:35:03 -0500 Subject: [PATCH 4/6] Fix for issue #50. --- src/dict.c | 8 ++++---- src/list.c | 34 +++++++++++++++++++++++----------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/dict.c b/src/dict.c index 75e3a73e..3fce8bd4 100644 --- a/src/dict.c +++ b/src/dict.c @@ -396,8 +396,8 @@ getdns_dict_set_list(struct getdns_dict * dict, char *name, struct getdns_list *newlist; getdns_return_t retval; - if (!dict || !name) - return GETDNS_RETURN_NO_SUCH_DICT_NAME; + if (!dict || !name || !child_list) + return GETDNS_RETURN_INVALID_PARAMETER; retval = getdns_list_copy(child_list, &newlist); if (retval != GETDNS_RETURN_GOOD) @@ -422,7 +422,7 @@ getdns_dict_set_bindata(struct getdns_dict * dict, char *name, struct getdns_bindata *newbindata; if (!dict || !name || !child_bindata) - return GETDNS_RETURN_NO_SUCH_DICT_NAME; + return GETDNS_RETURN_INVALID_PARAMETER; newbindata = getdns_bindata_copy(&dict->mf, child_bindata); if (!newbindata) @@ -446,7 +446,7 @@ getdns_dict_set_int(struct getdns_dict * dict, char *name, struct getdns_dict_item *item; if (!dict || !name) - return GETDNS_RETURN_NO_SUCH_DICT_NAME; + return GETDNS_RETURN_INVALID_PARAMETER; item = getdns_dict_find(dict, name, 1); if (!item) diff --git a/src/list.c b/src/list.c index 5cf7d24e..f71bf5c3 100644 --- a/src/list.c +++ b/src/list.c @@ -59,8 +59,8 @@ getdns_list_get_data_type(struct getdns_list * list, size_t index, return GETDNS_RETURN_NO_SUCH_LIST_ITEM; if (!answer) - return GETDNS_RETURN_WRONG_TYPE_REQUESTED; - + return GETDNS_RETURN_INVALID_PARAMETER; + *answer = list->items[index].dtype; return GETDNS_RETURN_GOOD; } /* getdns_list_get_data_type */ @@ -73,7 +73,10 @@ getdns_list_get_dict(struct getdns_list * list, size_t index, if (!list || index >= list->numinuse) return GETDNS_RETURN_NO_SUCH_LIST_ITEM; - if (!answer || list->items[index].dtype != t_dict) + if (!answer) + return GETDNS_RETURN_INVALID_PARAMETER; + + if (list->items[index].dtype != t_dict) return GETDNS_RETURN_WRONG_TYPE_REQUESTED; *answer = list->items[index].data.dict; @@ -89,7 +92,10 @@ getdns_list_get_list(struct getdns_list * list, size_t index, if (!list || index >= list->numinuse) return GETDNS_RETURN_NO_SUCH_LIST_ITEM; - if (!answer || list->items[index].dtype != t_list) + if (!answer) + return GETDNS_RETURN_INVALID_PARAMETER; + + if (list->items[index].dtype != t_list) return GETDNS_RETURN_WRONG_TYPE_REQUESTED; *answer = list->items[index].data.list; @@ -104,7 +110,10 @@ getdns_list_get_bindata(struct getdns_list * list, size_t index, if (!list || index >= list->numinuse) return GETDNS_RETURN_NO_SUCH_LIST_ITEM; - if (!answer || list->items[index].dtype != t_bindata) + if (!answer) + return GETDNS_RETURN_INVALID_PARAMETER; + + if (list->items[index].dtype != t_bindata) return GETDNS_RETURN_WRONG_TYPE_REQUESTED; *answer = list->items[index].data.bindata; @@ -118,7 +127,10 @@ getdns_list_get_int(struct getdns_list * list, size_t index, uint32_t * answer) if (!list || index >= list->numinuse) return GETDNS_RETURN_NO_SUCH_LIST_ITEM; - if (!answer || list->items[index].dtype != t_int) + if (!answer) + return GETDNS_RETURN_INVALID_PARAMETER; + + if (list->items[index].dtype != t_int) return GETDNS_RETURN_WRONG_TYPE_REQUESTED; *answer = list->items[index].data.n; @@ -332,7 +344,7 @@ getdns_list_add_item(struct getdns_list *list, size_t * index) getdns_return_t retval; if (!list || !index) - return GETDNS_RETURN_NO_SUCH_LIST_ITEM; + return GETDNS_RETURN_INVALID_PARAMETER; if (list->numalloc == list->numinuse) { retval = getdns_list_realloc(list); @@ -355,7 +367,7 @@ getdns_list_set_dict(struct getdns_list * list, size_t index, getdns_return_t retval; if (!list || !child_dict) - return GETDNS_RETURN_NO_SUCH_LIST_ITEM; + return GETDNS_RETURN_INVALID_PARAMETER; if (index > list->numinuse) return GETDNS_RETURN_NO_SUCH_LIST_ITEM; @@ -387,7 +399,7 @@ getdns_list_set_list(struct getdns_list * list, size_t index, getdns_return_t retval; if (!list || !child_list) - return GETDNS_RETURN_NO_SUCH_LIST_ITEM; + return GETDNS_RETURN_INVALID_PARAMETER; if (index > list->numinuse) return GETDNS_RETURN_NO_SUCH_LIST_ITEM; @@ -419,7 +431,7 @@ getdns_list_set_bindata(struct getdns_list * list, size_t index, getdns_return_t retval; if (!list || !child_bindata) - return GETDNS_RETURN_NO_SUCH_LIST_ITEM; + return GETDNS_RETURN_INVALID_PARAMETER; if (index > list->numinuse) return GETDNS_RETURN_NO_SUCH_LIST_ITEM; @@ -450,7 +462,7 @@ getdns_list_set_int(struct getdns_list * list, size_t index, getdns_return_t retval; if (!list) - return GETDNS_RETURN_NO_SUCH_LIST_ITEM; + return GETDNS_RETURN_INVALID_PARAMETER; if (index > list->numinuse) return GETDNS_RETURN_NO_SUCH_LIST_ITEM; From db32337238438a230546ed256765ae8d39a26239 Mon Sep 17 00:00:00 2001 From: Neel Goyal Date: Fri, 10 Jan 2014 10:45:45 -0500 Subject: [PATCH 5/6] Fix for #62 --- src/dict.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/dict.c b/src/dict.c index 3fce8bd4..c53ce6b6 100644 --- a/src/dict.c +++ b/src/dict.c @@ -107,7 +107,7 @@ getdns_dict_get_data_type(struct getdns_dict * dict, 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, 0); if (!item) @@ -128,8 +128,11 @@ getdns_dict_get_dict(struct getdns_dict * dict, char *name, return GETDNS_RETURN_NO_SUCH_DICT_NAME; item = getdns_dict_find(dict, name, 0); - if (!item || item->dtype != t_dict) - return GETDNS_RETURN_NO_SUCH_DICT_NAME; + if (!item) + return GETDNS_RETURN_NO_SUCH_DICT_NAME; + + if (item->dtype != t_dict) + return GETDNS_RETURN_WRONG_TYPE_REQUESTED; *answer = item->data.dict; return GETDNS_RETURN_GOOD; @@ -146,7 +149,10 @@ getdns_dict_get_list(struct getdns_dict * dict, char *name, return GETDNS_RETURN_NO_SUCH_DICT_NAME; item = getdns_dict_find(dict, name, 0); - if (!item || item->dtype != t_list) + if (!item) + return GETDNS_RETURN_NO_SUCH_DICT_NAME; + + if (item->dtype != t_list) return GETDNS_RETURN_WRONG_TYPE_REQUESTED; *answer = item->data.list; @@ -164,7 +170,10 @@ getdns_dict_get_bindata(struct getdns_dict * dict, char *name, return GETDNS_RETURN_NO_SUCH_DICT_NAME; item = getdns_dict_find(dict, name, 0); - if (!item || item->dtype != t_bindata) + if (!item) + return GETDNS_RETURN_NO_SUCH_DICT_NAME; + + if (item->dtype != t_bindata) return GETDNS_RETURN_WRONG_TYPE_REQUESTED; *answer = item->data.bindata; @@ -181,7 +190,10 @@ getdns_dict_get_int(struct getdns_dict * dict, char *name, uint32_t * answer) return GETDNS_RETURN_NO_SUCH_DICT_NAME; item = getdns_dict_find(dict, name, 0); - if (!item || item->dtype != t_int) + if (!item) + return GETDNS_RETURN_NO_SUCH_DICT_NAME; + + if (item->dtype != t_int) return GETDNS_RETURN_WRONG_TYPE_REQUESTED; *answer = item->data.n; From d4db2a2e9a08e5e0db0f61da7a15e2b49b3218a9 Mon Sep 17 00:00:00 2001 From: Neel Goyal Date: Fri, 10 Jan 2014 16:32:55 -0500 Subject: [PATCH 6/6] Fix a segfault when passing a null response to the sync methods --- src/sync.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sync.c b/src/sync.c index 3600da70..5519c757 100644 --- a/src/sync.c +++ b/src/sync.c @@ -70,6 +70,7 @@ getdns_general_sync(struct getdns_context *context, { getdns_return_t response_status; RETURN_IF_NULL(context, GETDNS_RETURN_BAD_CONTEXT); + RETURN_IF_NULL(response, GETDNS_RETURN_INVALID_PARAMETER); response_status = validate_extensions(extensions); if (response_status == GETDNS_RETURN_GOOD) { response_status = getdns_general_ub(context->unbound_sync,