From 4dcb71c5c252c4997e55303420f72eb15bc58892 Mon Sep 17 00:00:00 2001 From: Ben Kibbey Date: Sat, 28 Mar 2015 19:13:38 -0400 Subject: [PATCH] More non-existant element path fixes for LIST. Somehow these got missed in commit d871f40. Add a test case as well. --- src/xml.c | 28 ++++++++++++++-------------- tests/Makefile.am | 2 +- tests/acl.result18 | 1 + tests/acl.test | 11 +++++++++++ 4 files changed, 27 insertions(+), 15 deletions(-) create mode 100644 tests/acl.result18 diff --git a/src/xml.c b/src/xml.c index d2bdb4a2..1e32ba26 100644 --- a/src/xml.c +++ b/src/xml.c @@ -1026,10 +1026,6 @@ find_elements (struct client_s *client, xmlDocPtr doc, xmlNodePtr node, literal = is_literal_element (&t); n = find_element (client, last, t, NULL, rc); xfree (t); - - if (*rc && *rc != GPG_ERR_ELEMENT_NOT_FOUND) - return NULL; - if (!n) { if (!*rc) @@ -1103,7 +1099,6 @@ find_elements (struct client_s *client, xmlDocPtr doc, xmlNodePtr node, return NULL; } - if (found_fn) { found_fn (client, tmp, nreq, rc, p + 1, data); @@ -1127,22 +1122,26 @@ find_elements (struct client_s *client, xmlDocPtr doc, xmlNodePtr node, // FIXME ENOMEM if (!nnreq || !*nnreq) { - if (nnreq) - strv_free (nnreq); - + strv_free (nnreq); return tmp; } if (tmp->children) - n = find_elements (client, doc, tmp->children, nnreq, rc, NULL, - found_fn, not_found_fn, is_list_command, - recursion_depth, data, stop); + { + n = find_elements (client, doc, tmp->children, nnreq, rc, NULL, + found_fn, not_found_fn, is_list_command, + recursion_depth, data, stop); + if (!n) + { + strv_free (nnreq); + return NULL; + } + } else { strv_free (nnreq); - if (not_found_fn) - return not_found_fn (client, 0, tmp, p + 1, rc, data); + return not_found_fn (client, 0, tmp, p, rc, data); *rc = GPG_ERR_ELEMENT_NOT_FOUND; return NULL; @@ -1515,7 +1514,7 @@ list_not_found_cb (struct client_s *client, int i, xmlNodePtr node, if (*rc != GPG_ERR_EACCES) return NULL; - elements->data = req; + elements->data = strv_dup (req); return NULL; } @@ -1619,6 +1618,7 @@ done: elements->prefix = strv_join ("\t", tmp); strv_free (tmp); + strv_free (elements->data); elements->data = NULL; } else diff --git a/tests/Makefile.am b/tests/Makefile.am index 48b43401..c9b8e630 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -13,7 +13,7 @@ EXTRA_DIST= common.sh datafile.key \ import.result5 import.result6 import.result7 xpath.result3 \ xpath.result4 xpath.test \ acl.test acl.xml acl.key acl.result1 acl.result11 move.result9 \ - list.result6 acl.result13 acl.result16 + list.result6 acl.result13 acl.result16 acl.result18 tests: $(MAKE) -C $(top_srcdir)/src diff --git a/tests/acl.result18 b/tests/acl.result18 new file mode 100644 index 00000000..0cad1aae --- /dev/null +++ b/tests/acl.result18 @@ -0,0 +1 @@ +new a P \ No newline at end of file diff --git a/tests/acl.test b/tests/acl.test index 708fce89..65b093a9 100755 --- a/tests/acl.test +++ b/tests/acl.test @@ -133,4 +133,15 @@ if [ ${PIPESTATUS[1]} == 0 ]; then fi set -e +echo +echo "Test 18. List non-existant child of un-owned parent." +echo -ne 'new\ta\tb\tvalue' | pwmc $PWMC_ARGS --inquire STORE -S acl +echo -ne 'new2\ta\tb\tvalue' | pwmc $PWMC_ARGS --inquire STORE -S acl +echo -ne 'ATTR SET target new\ta new2\ta' | pwmc $PWMC_ARGS -S acl +echo -ne 'ATTR SET _acl new2\ta nobody' | pwmc $PWMC_ARGS -S acl +echo -ne 'LIST --all --with-target --verbose new\ta\tnon-existant' | pwmc $PWMC_ARGS acl > result +cmp acl.result18 result +rm -f result + +set -e test_success -- 2.11.4.GIT