summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Markwalder <tmark@isc.org>2014-12-05 16:04:49 -0500
committerThomas Markwalder <tmark@isc.org>2014-12-05 16:04:49 -0500
commit3c13b2d9ddbb6f3a69ce1906d9c4295fd810c777 (patch)
tree536562377a57dc1e3ddf06e7999e00c1da3e0fb2
parent9a857ecd40df17474f2d4e08d6fc3a0a0c74cddc (diff)
downloadisc-dhcp-3c13b2d9ddbb6f3a69ce1906d9c4295fd810c777.tar.gz
[rt20558_b] Added concat_dclists unit tests, fixed coverity leak
- Minor updates, excluding Makefile changes.
-rw-r--r--common/options.c3
-rw-r--r--common/tests/ns_name_test.c96
-rw-r--r--common/tree.c4
3 files changed, 100 insertions, 3 deletions
diff --git a/common/options.c b/common/options.c
index 757beae1..2e51bd42 100644
--- a/common/options.c
+++ b/common/options.c
@@ -2217,9 +2217,10 @@ void set_option (universe, options, option, op)
(memcmp(oc->option->format, "Dc", 2) == 0))) {
case 1:
/* Only one is "Dc", this won't work
- * Not sure if you make this occur, but just
+ * Not sure if you can make this occur, but just
* in case. */
log_error ("Both options must be Dc format");
+ option_cache_dereference (&noc, MDL);
return;
case 2:
/* Both are "Dc", change the code */
diff --git a/common/tests/ns_name_test.c b/common/tests/ns_name_test.c
index adbae602..93ffa761 100644
--- a/common/tests/ns_name_test.c
+++ b/common/tests/ns_name_test.c
@@ -20,6 +20,9 @@ ATF_TC_HEAD(MRns_name_list_funcs, tc) {
"compress from text, decompress to text");
}
+void concat_lists (const char* label, struct data_string* list1,
+ struct data_string* list2, const char *refbuf, size_t reflen);
+
ATF_TC_BODY(MRns_name_list_funcs, tc) {
const char text_list[] = "one.two.com,three.two.com,four.two.com";
@@ -56,9 +59,102 @@ ATF_TC_BODY(MRns_name_list_funcs, tc) {
"uncompressed buffer content wrong");
}
+ATF_TC(concat_dclists);
+
+ATF_TC_HEAD(concat_dclists, tc) {
+ atf_tc_set_md_var(tc, "descr", "concat_dclists function test, "
+ "permutate concating empty and non-empty lists");
+}
+
+ATF_TC_BODY(concat_dclists, tc) {
+ /* Compressed list version of "booya.com" */
+ const char data[] =
+ {0x05, 0x62, 0x6f, 0x6f, 0x79, 0x61, 0x03, 0x63, 0x6f, 0x6d, 0x00 };
+
+ /* Concatenation of data with itself */
+ const char data2[] =
+ {0x05, 0x62, 0x6f, 0x6f, 0x79, 0x61, 0x03, 0x63, 0x6f, 0x6d, 0x00,
+ 0xc0, 0x00 };
+
+ struct data_string nonempty;
+ struct data_string empty;
+
+ /* Make a non-empty compressed list from data[] */
+ nonempty.len = sizeof(data);
+ buffer_allocate(&(nonempty.buffer), nonempty.len, MDL);
+ memcpy(nonempty.buffer->data, data, nonempty.len);
+ nonempty.data = nonempty.buffer->data;
+
+ /* Permutate NULL with non-empty list */
+ concat_lists("null + null", NULL, NULL, "", 1);
+ concat_lists("null + nonempty", NULL, &nonempty, data, sizeof(data));
+ concat_lists("nonempty + null", &nonempty, NULL, data, sizeof(data));
+
+ /* Permutate zeroed-out list with non-empty list */
+ memset (&empty, 0x00, sizeof(struct data_string));
+ concat_lists("zero-list + zero-list", &empty, &empty, "", 1);
+ concat_lists("zero-list + nonempty", &empty, &nonempty, data, sizeof(data));
+ concat_lists("nonempty + zero-list", &nonempty, &empty, data, sizeof(data));
+
+ /* Create an empty list which is a buffer with 1 null in it */
+ /* Make sure those work the same as zeroed out data_strings */
+ buffer_allocate (&empty.buffer, 1, MDL);
+ empty.len = 1;
+ empty.data = empty.buffer->data;
+
+ /* Permutate with empty list */
+ concat_lists("empty + empty", &empty, &empty, "", 1);
+ concat_lists("empty + nonempty", &empty, &nonempty, data, sizeof(data));
+ concat_lists("nonempty + empty", &nonempty, &empty, data, sizeof(data));
+
+ /* Permutate with list len of 0 */
+ empty.len = 0;
+ concat_lists("zero-len + zero-len", &empty, &empty, "", 1);
+ concat_lists("zero-len + nonempty", &empty, &nonempty, data, sizeof(data));
+ concat_lists("nonempty + zero-len", &nonempty, &empty, data, sizeof(data));
+
+ /* Lastly, make sure two non-empty lists concat correctly */
+ concat_lists("nonempty + nonempty", &nonempty, &nonempty,
+ data2, sizeof(data2));
+
+ data_string_forget(&empty, MDL);
+ data_string_forget(&nonempty, MDL);
+}
+
+/* Helper function which tests concatenating two compressed lists
+*
+* \param label text to print in error message
+* \param list1 data_string containing first list
+* \param list2 data_string containing second list
+* \param refbuf buffer containing the expected concatentated data
+* \param reflen length of the expected data
+*/
+void concat_lists (const char* label, struct data_string* list1,
+ struct data_string* list2, const char *refbuf, size_t reflen)
+{
+ struct data_string result;
+ int rc;
+
+ memset (&result, 0x00, sizeof(struct data_string));
+ rc = concat_dclists (&result, list1, list2);
+ ATF_REQUIRE_MSG((rc >= 0), "%s concat_dclists call failed %d",
+ label, rc);
+
+ ATF_REQUIRE_MSG(result.len == reflen, "%s result len: %d incorrect",
+ label, result.len);
+
+ if (refbuf != NULL) {
+ ATF_REQUIRE_MSG((memcmp(result.data, refbuf, reflen) == 0),
+ "%s content is incorrect", label);
+ }
+
+ data_string_forget(&result, MDL);
+}
+
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, MRns_name_list_funcs);
+ ATF_TP_ADD_TC(tp, concat_dclists);
return (atf_no_error());
}
diff --git a/common/tree.c b/common/tree.c
index 4c2e5872..23e86faf 100644
--- a/common/tree.c
+++ b/common/tree.c
@@ -4556,7 +4556,7 @@ int concat_dclists (struct data_string* result,
int i;
/* If not empty, uncompress first list into the uncompressed buffer */
- if ((list1->data) && (list1->len)) {
+ if (list1 && (list1->data) && (list1->len)) {
list_len = MRns_name_uncompress_list(list1->data,
list1->len, uncomp,
sizeof(uncompbuf));
@@ -4571,7 +4571,7 @@ int concat_dclists (struct data_string* result,
}
/* If not empty, uncompress second list into the uncompressed buffer */
- if ((list2->data) && (list2->len)) {
+ if (list2 && (list2->data) && (list2->len)) {
/* If first list wasn't empty, add a comma */
if (uncomp_len > 0) {
*uncomp++ = ',';