]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug 5417: An empty annotation value does not match (#1896)
authorAlex Rousskov <rousskov@measurement-factory.com>
Thu, 5 Sep 2024 17:46:20 +0000 (17:46 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Mon, 9 Sep 2024 12:52:22 +0000 (12:52 +0000)
Helpers may return annotations with empty values:

    OK team_=""

A note ACL may be configured to match an annotation with an empty value:

    configuration_includes_quoted_values on
    acl emptyTeam note team_ ""

However, that emptyTeam ACL did not match the above helper annotation:

* AppendTokens() split an empty annotation value into an empty vector
  instead of a vector with a single empty entry. That "never match an
  empty value received from the helper" bug was probably introduced in
  2017 commit 75d47340 when it replaced an "always try to match an empty
  value, even when it was not received from the helper" bug in
  ACLNoteStrategy::matchNotes().

* ACLStringData::match(SBuf v) never matched an empty value v. That bug
  was probably introduced in 2015 commit 76ee67ac that mistook a nil
  c-string pointer for an empty c-string.

src/Notes.cc
src/acl/StringData.cc

index 57c54a1a3a0dc82b435cad58b4ce5119b2f5e095..ce97b177f61e5136abd96aaecc0a8628bb37c6cb 100644 (file)
@@ -339,12 +339,12 @@ static void
 AppendTokens(NotePairs::Entries &entries, const SBuf &key, const SBuf &val, const CharacterSet &delimiters)
 {
     Parser::Tokenizer tok(val);
-    SBuf v;
-    while (tok.token(v, delimiters))
-        entries.push_back(new NotePairs::Entry(key, v));
-    v = tok.remaining();
-    if (!v.isEmpty())
-        entries.push_back(new NotePairs::Entry(key, v));
+    const auto tokenCharacters = delimiters.complement("non-delimiters");
+    do {
+        SBuf token;
+        (void)tok.prefix(token, tokenCharacters);
+        entries.push_back(new NotePairs::Entry(key, token)); // token may be empty
+    } while (tok.skipOne(delimiters));
 }
 
 const NotePairs::Entries &
index fb318663973fee8a83f3db1445b1e56a3b4101b5..cd5f1af9f36e27c983faa7dfc4745f04cb0b89af 100644 (file)
@@ -23,7 +23,7 @@ ACLStringData::insert(const char *value)
 bool
 ACLStringData::match(const SBuf &tf)
 {
-    if (stringValues.empty() || tf.isEmpty())
+    if (stringValues.empty())
         return 0;
 
     debugs(28, 3, "aclMatchStringList: checking '" << tf << "'");
@@ -38,6 +38,11 @@ ACLStringData::match(const SBuf &tf)
 bool
 ACLStringData::match(char const *toFind)
 {
+    if (!toFind) {
+        // TODO: Check whether we can Assure(toFind) instead.
+        debugs(28, 3, "not matching a nil c-string");
+        return false;
+    }
     return match(SBuf(toFind));
 }