Commit d91bb752e for imagemagick.org

commit d91bb752ecfcfee1b3c8f2e3c8d50310e708c26f
Author: vjgroup <vjgroup@users.noreply.github.com>
Date:   Mon Nov 30 16:38:02 2026 -0800

    Include unnamed policies in GetPolicyInfoList wildcard queries (#9164)

    Commit a499f141ee added a non-NULL check on policy->name in
    GetPolicyInfoList(). Because delegate, filter, coder, module, and path
    policies do not have a name attribute, magick -list policy (which calls
    GetPolicyInfoList("*")) stopped printing them.

    Allow policy->name == NULL to match when pattern is NULL, empty, or "*",
    while keeping the non-NULL check for specific patterns and in
    GetPolicyList(). Add a TAP regression test in tests/cli-policy.tap.

    Co-authored-by: Victor Group <vjgroup@gmail.com>

diff --git a/MagickCore/policy.c b/MagickCore/policy.c
index 2fcc91785..9514467ec 100644
--- a/MagickCore/policy.c
+++ b/MagickCore/policy.c
@@ -444,8 +444,11 @@ MagickExport const PolicyInfo **GetPolicyInfoList(const char *pattern,

     policy=(const PolicyInfo *) p->value;
     if ((policy->stealth == MagickFalse) &&
-        (policy->name != (char *) NULL) &&
-        (GlobExpression(policy->name,pattern,MagickFalse) != MagickFalse))
+        (((policy->name == (char *) NULL) &&
+          ((pattern == (const char *) NULL) || (*pattern == '\0') ||
+           (LocaleCompare(pattern,"*") == 0))) ||
+         ((policy->name != (char *) NULL) &&
+          (GlobExpression(policy->name,pattern,MagickFalse) != MagickFalse))))
       policies[i++]=policy;
     p=p->next;
   }
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 2b6d8c42d..367582fbf 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -50,6 +50,7 @@ TESTS_TESTS = \
   tests/cli-mogrify.tap \
   tests/cli-pcx.tap \
   tests/cli-pipe.tap \
+  tests/cli-policy.tap \
   tests/cli-svg.tap \
   tests/cli-statistic.tap \
   tests/cli-tiff.tap \
diff --git a/tests/cli-policy.tap b/tests/cli-policy.tap
new file mode 100755
index 000000000..9ef14ef26
--- /dev/null
+++ b/tests/cli-policy.tap
@@ -0,0 +1,82 @@
+#!/bin/sh
+#
+#  Copyright 1999 ImageMagick Studio LLC, a non-profit organization
+#  dedicated to making software imaging solutions freely available.
+#
+#  You may not use this file except in compliance with the License.  You may
+#  obtain a copy of the License at
+#
+#    https://imagemagick.org/license/
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+#
+#  Regression tests for policy listing.
+#
+. ./common.shi
+. ${srcdir}/tests/common.shi
+echo "1..3"
+
+policy_dir=`mktemp -d "${TMPDIR:-/tmp}/magick-cli-policy.XXXXXX"` || exit 1
+trap 'rm -rf "$policy_dir"' EXIT
+
+has_policies() {
+  out="$1"
+  shift
+  for expected in "$@"; do
+    case "$out" in
+      *"$expected"*) ;;
+      *) return 1 ;;
+    esac
+  done
+  return 0
+}
+
+# Policy file with only unnamed rules (delegate, filter, coder, path).
+rm -f "$policy_dir/policy.xml"
+cat > "$policy_dir/policy.xml" <<'EOF'
+<?xml version="1.0" encoding="UTF-8"?>
+<policymap>
+  <policy domain="delegate" rights="none" pattern="*" />
+  <policy domain="filter" rights="none" pattern="*" />
+  <policy domain="coder" rights="none" pattern="*" />
+  <policy domain="path" rights="none" pattern="@*" />
+</policymap>
+EOF
+out=`MAGICK_CONFIGURE_PATH="$policy_dir" ${MAGICK} -list policy 2>/dev/null`
+if has_policies "$out" "Policy: Delegate" "Policy: Filter" "Policy: Coder" "Policy: Path"; then
+  echo "ok 1"
+else
+  echo "not ok 1"
+fi
+
+# Policy file mixing named (resource) and unnamed (delegate/coder) rules.
+rm -f "$policy_dir/policy.xml"
+cat > "$policy_dir/policy.xml" <<'EOF'
+<?xml version="1.0" encoding="UTF-8"?>
+<policymap>
+  <policy domain="resource" name="thread" value="1" />
+  <policy domain="delegate" rights="none" pattern="*" />
+  <policy domain="coder" rights="none" pattern="*" />
+</policymap>
+EOF
+out=`MAGICK_CONFIGURE_PATH="$policy_dir" ${MAGICK} -list policy 2>/dev/null`
+if has_policies "$out" "Policy: Resource" "Policy: Delegate" "Policy: Coder"; then
+  echo "ok 2"
+else
+  echo "not ok 2"
+fi
+
+# Shipped policy-websafe.xml lists both named and unnamed rules.
+rm -f "$policy_dir/policy.xml"
+cp "${TOPSRCDIR}/config/policy-websafe.xml" "$policy_dir/policy.xml" || { echo "not ok 3"; exit 1; }
+out=`MAGICK_CONFIGURE_PATH="$policy_dir" ${MAGICK} -list policy 2>/dev/null`
+if has_policies "$out" "Policy: Resource" "Policy: Delegate" "Policy: Coder"; then
+  echo "ok 3"
+else
+  echo "not ok 3"
+fi
+: