]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/acl/BoolOps.cc
Source Format Enforcement (#1234)
[thirdparty/squid.git] / src / acl / BoolOps.cc
index 7e48fc04d045d803a57ce56511e03d009c733d16..659d9b4fcd24f84182e581cda59de1258590e49b 100644 (file)
@@ -1,17 +1,26 @@
+/*
+ * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
 #include "squid.h"
 #include "acl/BoolOps.h"
 #include "acl/Checklist.h"
-#include "Debug.h"
-#include "wordlist.h"
-
+#include "debug/Stream.h"
+#include "sbuf/SBuf.h"
 
 /* Acl::NotNode */
 
 Acl::NotNode::NotNode(ACL *acl)
 {
     assert(acl);
+    Must(strlen(acl->name) <= sizeof(name)-2);
     name[0] = '!';
-    strncat(&name[1], acl->name, sizeof(name)-1-1);
+    name[1] = '\0';
+    xstrncpy(&name[1], acl->name, sizeof(name)-1); // -1 for '!'
     add(acl);
 }
 
@@ -20,7 +29,7 @@ Acl::NotNode::parse()
 {
     // Not implemented: by the time an upper level parser discovers
     // an '!' operator, there is nothing left for us to parse.
-    assert(false);    
+    assert(false);
 }
 
 int
@@ -43,25 +52,14 @@ Acl::NotNode::typeString() const
     return "!";
 }
 
-ACL *
-Acl::NotNode::clone() const
-{
-    // Not implemented: we are not a named ACL type in squid.conf so nobody
-    // should try to create a NotNode instance by ACL type name (which is
-    // what clone() API is for -- it does not really clone anything).
-    assert(false);
-    return NULL;
-}
-
-wordlist*
+SBufList
 Acl::NotNode::dump() const
 {
-    wordlist *text = NULL;
-    wordlistAdd(&text, name);
+    SBufList text;
+    text.push_back(SBuf(name));
     return text;
 }
 
-
 /* Acl::AndNode */
 
 char const *
@@ -70,12 +68,6 @@ Acl::AndNode::typeString() const
     return "and";
 }
 
-ACL *
-Acl::AndNode::clone() const
-{
-    return new AndNode;
-}
-
 int
 Acl::AndNode::doMatch(ACLChecklist *checklist, Nodes::const_iterator start) const
 {
@@ -93,10 +85,9 @@ void
 Acl::AndNode::parse()
 {
     // Not implemented: AndNode cannot be configured directly. See Acl::AllOf.
-    assert(false);    
+    assert(false);
 }
 
-
 /* Acl::OrNode */
 
 char const *
@@ -105,10 +96,10 @@ Acl::OrNode::typeString() const
     return "any-of";
 }
 
-ACL *
-Acl::OrNode::clone() const
+bool
+Acl::OrNode::bannedAction(ACLChecklist *, Nodes::const_iterator) const
 {
-    return new OrNode;
+    return false;
 }
 
 int
@@ -118,6 +109,8 @@ Acl::OrNode::doMatch(ACLChecklist *checklist, Nodes::const_iterator start) const
 
     // find the first node that matches, but stop if things go wrong
     for (Nodes::const_iterator i = start; i != nodes.end(); ++i) {
+        if (bannedAction(checklist, i))
+            continue;
         if (checklist->matchChild(this, i, *i)) {
             lastMatch_ = i;
             return 1;
@@ -137,3 +130,4 @@ Acl::OrNode::parse()
     // Not implemented: OrNode cannot be configured directly. See Acl::AnyOf.
     assert(false);
 }
+