From 90c6eb91bb24e4e26cfc3447725850c11c1ff7bc Mon Sep 17 00:00:00 2001 From: aschackmull <28296824+aschackmull@users.noreply.github.com> Date: Fri, 20 Nov 2026 08:14:23 +0000 Subject: [PATCH 1/3] QL: Replace string matching workarounds Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> --- actions/ql/lib/codeql/actions/PowerShell.qll | 2 +- .../lib/codeql/actions/ast/internal/Ast.qll | 24 ++++----- .../ql/lib/codeql/actions/config/Config.qll | 2 +- .../codeql/actions/dataflow/ExternalFlow.qll | 12 ++--- .../codeql/actions/dataflow/FlowSources.qll | 12 ++--- .../codeql/actions/dataflow/TaintSteps.qll | 4 +- .../security/ArtifactPoisoningQuery.qll | 8 +-- .../codeql/actions/security/ControlChecks.qll | 6 +-- .../security/OutputClobberingQuery.qll | 2 +- .../actions/security/PoisonableSteps.qll | 2 +- .../security/UntrustedCheckoutQuery.qll | 2 +- actions/ql/lib/codeql/files/FileSystem.qll | 2 +- .../CWE-312/ExcessiveSecretsExposure.ql | 6 +-- .../CWE-571/ExpressionIsAlwaysTrueCritical.ql | 6 +-- .../CWE-571/ExpressionIsAlwaysTrueHigh.ql | 6 +-- .../Security/CWE-829/UnpinnedActionsTag.ql | 2 +- cpp/ql/examples/snippets/todocomment.ql | 2 +- .../utils/OpenSSL/CryptoFunction.qll | 14 ++--- .../utils/OpenSSL/DataBuilders.qll | 12 ++--- .../utils/OpenSSL/LibraryFunction.qll | 2 +- .../AlgorithmInstances/AlgToAVCFlow.qll | 2 +- .../CipherAlgorithmInstance.qll | 42 +++++++-------- .../HashAlgorithmInstance.qll | 4 +- .../KnownAlgorithmConstants.qll | 4 +- .../SignatureAlgorithmInstance.qll | 10 ++-- .../quantum/OpenSSL/LibraryDetector.qll | 2 +- .../OpenSSL/Operations/CipherOperation.qll | 10 ++-- .../Operations/OpenSSLOperationBase.qll | 4 +- .../OpenSSL/Operations/SignatureOperation.qll | 4 +- cpp/ql/lib/semmle/code/cpp/Comments.qll | 4 +- .../semmle/code/cpp/ConfigurationTestFile.qll | 4 +- cpp/ql/lib/semmle/code/cpp/UserType.qll | 2 +- .../semmle/code/cpp/commons/Assertions.qll | 2 +- cpp/ql/lib/semmle/code/cpp/commons/Printf.qll | 14 ++--- .../code/cpp/commons/StructLikeClass.qll | 4 +- .../semmle/code/cpp/dataflow/ExternalFlow.qll | 2 +- .../cpp/models/implementations/Allocation.qll | 2 +- .../cpp/rangeanalysis/SimpleRangeAnalysis.qll | 2 +- .../cpp/security/boostorg/asio/protocols.qll | 18 +++---- .../Exceptions/AccidentalRethrow.ql | 2 +- .../Best Practices/Exceptions/LeakyCatch.ql | 2 +- .../Unused Entities/UnusedIncludes.ql | 2 +- cpp/ql/src/Critical/ReturnValueIgnored.ql | 2 +- cpp/ql/src/Documentation/CommentedOutCode.qll | 2 +- .../LOC-2/Rule 03/ExitNonterminatingLoop.ql | 2 +- cpp/ql/src/JPL_C/LOC-2/Rule 03/LoopBounds.ql | 2 +- cpp/ql/src/JPL_C/LOC-2/Rule 05/HeapMemory.ql | 2 +- .../Rule 20/PreprocessorUseUndisciplined.ql | 4 +- .../Likely Bugs/InconsistentCallOnResult.ql | 6 +-- .../InconsistentCheckReturnNull.ql | 2 +- cpp/ql/src/Likely Bugs/Leap Year/LeapYear.qll | 2 +- .../UncheckedLeapYearAfterYearModification.ql | 22 ++++---- .../Files/ConditionalSegmentConditions.ql | 4 +- cpp/ql/src/Metrics/Files/FTodoComments.ql | 4 +- .../Rule 3/DynamicAllocAfterInit.ql | 2 +- .../src/Power of 10/Rule 4/FunctionTooLong.ql | 2 +- .../Power of 10/Rule 5/AssertionDensity.ql | 2 +- .../Power of 10/Rule 8/UndisciplinedMacro.ql | 4 +- .../src/Security/CWE/CWE-022/TaintedPath.ql | 2 +- .../CWE/CWE-313/CleartextSqliteDatabase.ql | 2 +- .../Security/CWE/CWE-327/OpenSslHeartbleed.ql | 2 +- .../CWE/CWE-704/WcharCharConversion.ql | 4 +- ...erousWorksWithMultibyteOrWideCharacters.ql | 4 +- .../CWE-266/IncorrectPrivilegeAssignment.ql | 4 +- .../CWE-273/PrivilegeDroppingOutoforder.ql | 2 +- .../CWE/CWE-416/UseAfterExpiredLifetime.ql | 6 +-- .../example_alerts/WeakEncryption.ql | 2 +- .../examples/filters/ExcludeGeneratedCode.ql | 2 +- cpp/ql/src/jsf/4.05 Libraries/AV Rule 17.ql | 2 +- cpp/ql/src/jsf/4.05 Libraries/AV Rule 18.ql | 2 +- cpp/ql/src/jsf/4.05 Libraries/AV Rule 19.ql | 2 +- cpp/ql/src/jsf/4.05 Libraries/AV Rule 20.ql | 4 +- cpp/ql/src/jsf/4.05 Libraries/AV Rule 21.ql | 2 +- cpp/ql/src/jsf/4.05 Libraries/AV Rule 22.ql | 2 +- cpp/ql/src/jsf/4.05 Libraries/AV Rule 23.ql | 2 +- cpp/ql/src/jsf/4.05 Libraries/AV Rule 24.ql | 2 +- cpp/ql/src/jsf/4.05 Libraries/AV Rule 25.ql | 2 +- .../AV Rule 29.ql | 2 +- .../AV Rule 30.ql | 6 +-- .../src/jsf/4.07 Header Files/AV Rule 33.ql | 2 +- .../4.20 Unions and Bit Fields/AV Rule 156.ql | 2 +- .../modelgenerator/internal/CaptureModels.qll | 4 +- .../library-tests/constants/constants/ints.ql | 2 +- .../controlflow/guards/GuardsInline.ql | 2 +- .../dataflow/asDefinition/test.ql | 2 +- .../dataflow/asExpr/test-indirect.ql | 2 +- .../library-tests/dataflow/asExpr/test.ql | 2 +- .../library-tests/dataflow/certain/test.ql | 2 +- .../dataflow/dataflow-tests/TestBase.qll | 4 +- .../guard-condition-regression-test.ql | 2 +- .../library-tests/dataflow/forwarding/test.ql | 2 +- .../dataflow/taint-tests/taint.ql | 4 +- .../library-tests/fields/fields/Fields.ql | 2 +- .../library-tests/friends/friends/nesting.ql | 2 +- .../ir/range-analysis/RangeAnalysis.ql | 2 +- cpp/ql/test/library-tests/odasa2646/cfi.ql | 2 +- .../test/library-tests/type_strings/exprs.ql | 2 +- .../library-tests/types/__wchar_t/wchar_t.ql | 2 +- .../types/wchar_t_typedef/wchar_t.ql | 2 +- .../variables/variables/variable.ql | 4 +- .../standalone_dependency_dir/Assemblies.ql | 2 +- .../standalone_resx/CompilationInfo.ql | 2 +- .../CompilationInfo.ql | 2 +- .../CompilationInfo.ql | 2 +- .../CompilationInfo.ql | 2 +- .../CompilationInfo.ql | 2 +- .../integration-tests/windows/subst/file.ql | 2 +- csharp/ql/lib/Linq/Helpers.qll | 2 +- csharp/ql/lib/semmle/code/asp/WebConfig.qll | 4 +- csharp/ql/lib/semmle/code/csharp/Comments.qll | 2 +- csharp/ql/lib/semmle/code/csharp/File.qll | 2 +- .../code/csharp/commons/GeneratedCode.qll | 8 +-- .../csharp/dataflow/internal/ExternalFlow.qll | 2 +- .../csharp/frameworks/EntityFramework.qll | 4 +- .../semmle/code/csharp/frameworks/JsonNET.qll | 4 +- .../semmle/code/csharp/frameworks/Razor.qll | 6 +-- .../frameworks/microsoft/AspNetCore.qll | 10 ++-- .../code/csharp/frameworks/microsoft/Owin.qll | 2 +- .../code/csharp/frameworks/system/IO.qll | 4 +- .../code/csharp/frameworks/system/web/Mvc.qll | 2 +- .../csharp/frameworks/system/xml/XPath.qll | 2 +- .../code/csharp/security/SensitiveActions.qll | 12 ++--- .../csharp/security/auth/ActionMethods.qll | 2 +- ...MissingFunctionLevelAccessControlQuery.qll | 6 +-- .../HardcodedSymmetricEncryptionKey.qll | 2 +- .../security/dataflow/CodeInjectionQuery.qll | 2 +- .../dataflow/HardcodedCredentialsQuery.qll | 6 +-- .../security/dataflow/UrlRedirectQuery.qll | 6 +-- .../csharp/security/dataflow/XSSSinks.qll | 2 +- .../dataflow/flowsinks/ParallelSink.qll | 2 +- csharp/ql/src/ASP/BlockCodeResponseWrite.ql | 2 +- .../Dependencies/MutualDependency.ql | 8 +-- .../Naming Conventions/DefaultControlNames.ql | 2 +- .../VariableNameTooShort.ql | 2 +- .../Bad Practices/UseOfSystemOutputStream.ql | 2 +- csharp/ql/src/Concurrency/Concurrency.qll | 2 +- .../Concurrency/UnsynchronizedStaticAccess.ql | 2 +- .../CWE-327/InsecureSQLConnection.ql | 4 +- .../CookieWithOverlyBroadDomain.ql | 2 +- .../src/Security Features/PersistentCookie.ql | 2 +- .../ql/src/Telemetry/ExtractorInformation.ql | 8 +-- .../Serialization/DataSetSerialization.qll | 2 +- .../backdoor/DangerousNativeFunctionCall.ql | 12 ++--- .../backdoor/ProcessNameToHashTaintFlow.ql | 2 +- .../ql/src/utils/modeleditor/ModelEditor.qll | 2 +- .../controlflow/graph/Common.qll | 2 +- .../csharp10/fileScopedNamespace.ql | 2 +- .../test/library-tests/csharp11/fileScoped.ql | 2 +- .../csharp8/switchexprcontrolflow.ql | 2 +- .../expressions/ObjectCreation8.ql | 2 +- .../test/library-tests/fields/Constants5.ql | 2 +- .../frameworks/NHibernate/SqlExprs.ql | 2 +- .../NHibernate/StoredFlowSources.ql | 2 +- .../ServiceStack/codeInjectionSinks.ql | 2 +- .../ServiceStack/externalLocationSink.ql | 2 +- .../ServiceStack/remoteFlowSource.ql | 2 +- .../frameworks/ServiceStack/sqlSink.ql | 2 +- .../frameworks/ServiceStack/xssSink.ql | 2 +- .../test/library-tests/generics/Generics.ql | 6 +-- .../root-internal-tests/test.ql | 2 +- go/ql/lib/semmle/go/Concepts.qll | 2 +- go/ql/lib/semmle/go/frameworks/Gqlgen.qll | 2 +- go/ql/lib/semmle/go/frameworks/Logrus.qll | 6 +-- go/ql/lib/semmle/go/frameworks/Protobuf.qll | 2 +- go/ql/lib/semmle/go/frameworks/Spew.qll | 2 +- .../go/frameworks/SystemCommandExecutors.qll | 2 +- go/ql/lib/semmle/go/frameworks/Zap.qll | 2 +- .../semmle/go/frameworks/stdlib/Regexp.qll | 2 +- .../go/frameworks/stdlib/TextTemplate.qll | 6 +-- .../go/security/HardcodedCredentials.qll | 4 +- .../InsecureRandomnessCustomizations.qll | 4 +- .../MistypedExponentiation.ql | 2 +- .../CWE-020/IncompleteUrlSchemeCheck.ql | 6 +-- .../Security/CWE-352/ConstantOauth2State.ql | 4 +- go/ql/src/experimental/CWE-203/Timing.ql | 2 +- .../src/experimental/CWE-285/PamAuthBypass.ql | 4 +- .../CWE-525/WebCacheDeceptionLib.qll | 8 +-- .../CWE-807/SensitiveConditionBypass.qll | 6 +-- go/ql/src/filters/ClassifyFiles.ql | 2 +- .../test/extractor-tests/go1.14/interfaces.ql | 2 +- .../semmle/go/Packages/PackagePath.ql | 4 +- .../library-tests/semmle/go/Types/Aliases.ql | 2 +- .../semmle/go/Types/ImplementsComparable.ql | 2 +- .../dataflow/InterProceduralDataFlow/Test.ql | 4 +- .../go/frameworks/ElazarlGoproxy/test.ql | 2 +- java/ql/consistency-queries/visibility.ql | 2 +- java/ql/integration-tests/java/subst/file.ql | 6 +-- .../all-platforms/raw_generic_types/test.ql | 4 +- .../recursive_interfaces/types.ql | 2 +- .../kotlin/linux/custom_plugin/diag.ql | 2 +- .../linux/use_java_library/parameterTypes.ql | 2 +- java/ql/lib/experimental/quantum/JCA.qll | 28 +++++----- java/ql/lib/experimental/quantum/Language.qll | 2 +- java/ql/lib/semmle/code/java/Concurrency.qll | 2 +- .../semmle/code/java/ConflictingAccess.qll | 4 +- java/ql/lib/semmle/code/java/Element.qll | 2 +- java/ql/lib/semmle/code/java/JMX.qll | 4 +- java/ql/lib/semmle/code/java/Type.qll | 2 +- java/ql/lib/semmle/code/java/UnitTests.qll | 18 +++---- .../code/java/dataflow/ExternalFlow.qll | 2 +- .../dataflow/internal/ModelExclusions.qll | 30 +++++------ .../dataflow/internal/TaintTrackingUtil.qll | 6 +-- .../semmle/code/java/deadcode/EntryPoints.qll | 8 +-- .../code/java/deadcode/StrutsEntryPoints.qll | 4 +- .../code/java/deadcode/WebEntryPoints.qll | 2 +- .../code/java/dispatch/WrappedInvocation.qll | 2 +- .../lib/semmle/code/java/frameworks/Camel.qll | 2 +- .../semmle/code/java/frameworks/Cucumber.qll | 2 +- .../code/java/frameworks/IoJsonWebToken.qll | 2 +- .../lib/semmle/code/java/frameworks/JAXB.qll | 2 +- .../lib/semmle/code/java/frameworks/JaxWS.qll | 2 +- .../semmle/code/java/frameworks/JoddJson.qll | 2 +- .../semmle/code/java/frameworks/Lombok.qll | 2 +- .../semmle/code/java/frameworks/Mockito.qll | 4 +- .../code/java/frameworks/Networking.qll | 2 +- .../code/java/frameworks/Properties.qll | 2 +- .../code/java/frameworks/android/Compose.qll | 2 +- .../code/java/frameworks/android/Intent.qll | 2 +- .../frameworks/android/SharedPreferences.qll | 2 +- .../java/frameworks/android/XmlParsing.qll | 4 +- .../java/frameworks/gigaspaces/GigaSpaces.qll | 6 +-- .../semmle/code/java/frameworks/gwt/GWT.qll | 4 +- .../java/frameworks/gwt/GwtUiBinderXml.qll | 2 +- .../code/java/frameworks/gwt/GwtXml.qll | 2 +- .../code/java/frameworks/j2objc/J2ObjC.qll | 4 +- .../jackson/JacksonSerializability.qll | 2 +- .../code/java/frameworks/javaee/ejb/EJB.qll | 4 +- .../frameworks/javaee/ejb/EJBRestrictions.qll | 6 +-- .../java/frameworks/spring/SpringAutowire.qll | 2 +- .../java/frameworks/spring/SpringProfile.qll | 2 +- .../code/java/frameworks/stapler/Stapler.qll | 2 +- .../java/frameworks/struts/StrutsActions.qll | 2 +- .../frameworks/struts/StrutsConventions.qll | 2 +- .../AndroidCertificatePinningQuery.qll | 2 +- .../security/ArbitraryApkInstallation.qll | 2 +- .../code/java/security/CommandArguments.qll | 4 +- .../code/java/security/ControlledString.qll | 2 +- .../code/java/security/ExternalAPIs.qll | 2 +- .../semmle/code/java/security/HttpsUrls.qll | 2 +- .../code/java/security/InsecureBasicAuth.qll | 2 +- .../java/security/InsecureRandomnessQuery.qll | 2 +- .../java/security/InsufficientKeySize.qll | 6 +-- .../ql/lib/semmle/code/java/security/Mail.qll | 6 +-- .../java/security/PartialPathTraversal.qll | 2 +- .../code/java/security/PathSanitizer.qll | 8 +-- .../code/java/security/RandomDataSource.qll | 6 +-- .../semmle/code/java/security/RandomQuery.qll | 6 +-- .../java/security/RsaWithoutOaepQuery.qll | 4 +- .../code/java/security/SecurityTests.qll | 6 +-- .../code/java/security/SensitiveActions.qll | 2 +- .../security/SensitiveKeyboardCacheQuery.qll | 6 +-- .../SpringBootActuatorsConfigQuery.qll | 4 +- .../StaticInitializationVectorQuery.qll | 2 +- .../security/TaintedPermissionsCheckQuery.qll | 2 +- java/ql/lib/semmle/code/java/security/XSS.qll | 2 +- .../security/regexp/PolynomialReDoSQuery.qll | 6 +-- .../lib/semmle/code/xml/AndroidManifest.qll | 4 +- java/ql/lib/semmle/code/xml/MavenPom.qll | 4 +- .../Dependencies/MutualDependency.ql | 8 +-- .../Likely Bugs/Comparison/HashedButNoHash.ql | 2 +- .../Comparison/IncomparableEquals.ql | 2 +- .../src/Likely Bugs/Concurrency/BusyWait.ql | 2 +- .../Concurrency/SynchSetUnsynchGet.ql | 2 +- .../Swing/BadlyOverriddenAdapter.ql | 2 +- .../Likely Typos/SuspiciousDateFormat.ql | 4 +- .../Likely Bugs/Resource Leaks/CloseType.qll | 2 +- .../Statements/InconsistentCallOnResult.ql | 8 +-- .../CWE-1004/SensitiveCookieNotHttpOnly.ql | 2 +- .../CWE/CWE-1104/MavenPomDependsOnBintray.ql | 2 +- .../CWE/CWE-338/JHipsterGeneratedPRNG.ql | 2 +- .../Comments/CommentedCode.qll | 12 ++--- .../Comments/TodoComments.ql | 4 +- .../Dead Code/DeadRefTypes.ql | 2 +- .../Naming Conventions/Shadowing.qll | 4 +- .../Security/CWE/CWE-073/JFinalController.qll | 2 +- .../CWE/CWE-094/InsecureDexLoading.qll | 2 +- .../Security/CWE/CWE-094/JythonInjection.ql | 2 +- .../CWE/CWE-094/SpringViewManipulationLib.qll | 2 +- .../CWE/CWE-297/InsecureLdapEndpoint.ql | 4 +- .../CWE-555/PasswordInConfigurationFile.ql | 2 +- .../Security/CWE/CWE-598/SensitiveGetQuery.ql | 2 +- .../Security/CWE/CWE-759/HashWithoutSalt.ql | 2 +- .../quantum/Examples/BrokenCrypto.ql | 2 +- .../CredentialsInPropertiesFile.qll | 6 +-- .../utils/modelconverter/ExtractNeutrals.ql | 2 +- .../src/utils/modelconverter/ExtractSinks.ql | 2 +- .../utils/modelconverter/ExtractSources.ql | 2 +- .../utils/modelconverter/ExtractSummaries.ql | 2 +- .../modelgenerator/internal/CaptureModels.qll | 4 +- .../annotation-accessor-result-type/test.ql | 2 +- .../library-tests/compilation-units/cus.ql | 2 +- .../library-tests/instances/classes.ql | 2 +- .../java-list-kotlin-user/test.ql | 2 +- .../library-tests/methods/diagnostics.ql | 2 +- .../parameter-defaults/erasure.ql | 2 +- .../parameter-defaults/flowTest.ql | 4 +- .../type_equivalences/type_equivalences.ql | 2 +- .../annotation-accessor-result-type/test.ql | 2 +- .../library-tests/compilation-units/cus.ql | 2 +- .../test-kotlin2/library-tests/enum/test.ql | 2 +- .../library-tests/instances/classes.ql | 2 +- .../java-list-kotlin-user/test.ql | 2 +- .../library-tests/methods/diagnostics.ql | 2 +- .../library-tests/nested_types/types.ql | 2 +- .../parameter-defaults/erasure.ql | 2 +- .../parameter-defaults/flowTest.ql | 4 +- .../type_equivalences/type_equivalences.ql | 2 +- .../library-tests/dispatch/viableCallable.ql | 2 +- .../errortype-with-params/Diags.ql | 2 +- java/ql/test/library-tests/errortype/Diags.ql | 2 +- .../module-info-wrong-name/Diags.ql | 2 +- .../unknown-method-reference-lhs/Diags.ql | 2 +- .../wildcards-and-captured-types/test.ql | 2 +- .../security/CWE-730/ExpRedos/ReDoS.ql | 2 +- .../DecodingAfterSanitization.ql | 2 +- .../DecodingAfterSanitizationGeneralized.ql | 2 +- javascript/ql/integration-tests/subst/file.ql | 2 +- javascript/ql/lib/semmle/javascript/AST.qll | 2 +- javascript/ql/lib/semmle/javascript/DOM.qll | 6 +-- javascript/ql/lib/semmle/javascript/Files.qll | 2 +- .../semmle/javascript/GlobalAccessPaths.qll | 2 +- javascript/ql/lib/semmle/javascript/HTML.qll | 2 +- javascript/ql/lib/semmle/javascript/JSDoc.qll | 2 +- .../ql/lib/semmle/javascript/JsonSchema.qll | 2 +- .../ql/lib/semmle/javascript/Modules.qll | 2 +- javascript/ql/lib/semmle/javascript/NPM.qll | 4 +- .../ql/lib/semmle/javascript/NodeJS.qll | 2 +- .../javascript/NodeModuleResolutionImpl.qll | 2 +- .../ql/lib/semmle/javascript/Regexp.qll | 10 ++-- .../ql/lib/semmle/javascript/TSConfig.qll | 2 +- .../javascript/dataflow/TaintTracking.qll | 2 +- .../dependencies/FrameworkLibraries.qll | 2 +- .../javascript/filters/ClassifyFiles.qll | 2 +- .../semmle/javascript/frameworks/Angular2.qll | 4 +- .../AngularJS/AngularJSExpressions.qll | 2 +- .../javascript/frameworks/AsyncPackage.qll | 2 +- .../semmle/javascript/frameworks/Babel.qll | 2 +- .../semmle/javascript/frameworks/Bundling.qll | 4 +- .../javascript/frameworks/ClientRequests.qll | 7 ++- .../semmle/javascript/frameworks/Firebase.qll | 6 +-- .../semmle/javascript/frameworks/Markdown.qll | 2 +- .../semmle/javascript/frameworks/NoSQL.qll | 4 +- .../javascript/frameworks/NodeJSLib.qll | 10 ++-- .../semmle/javascript/frameworks/ShellJS.qll | 2 +- .../semmle/javascript/frameworks/Spife.qll | 2 +- .../frameworks/SystemCommandExecutors.qll | 2 +- .../javascript/frameworks/UriLibraries.qll | 2 +- .../javascript/frameworks/XmlParsers.qll | 6 +-- .../heuristics/AdditionalFrameworks.qll | 2 +- .../internal/paths/PackageJsonEx.qll | 6 +-- .../lib/semmle/javascript/linters/JSLint.qll | 2 +- .../javascript/security/UselessUseOfCat.qll | 2 +- .../InsecureTemporaryFileCustomizations.qll | 2 +- .../security/dataflow/MissingRateLimiting.qll | 2 +- .../PrototypePollutionCustomizations.qll | 2 +- .../security/dataflow/UrlConcatenation.qll | 2 +- .../dataflow/XssThroughDomCustomizations.qll | 4 +- .../ql/lib/utils/test/ConsistencyChecking.qll | 2 +- .../ql/src/AngularJS/IncompatibleService.ql | 2 +- .../ql/src/AngularJS/InsecureUrlWhitelist.ql | 4 +- javascript/ql/src/DOM/TargetBlank.ql | 2 +- .../ql/src/Declarations/UnusedParameter.qll | 2 +- .../ql/src/Declarations/UnusedProperty.ql | 2 +- .../src/Expressions/CompareIdenticalValues.ql | 2 +- .../ql/src/Expressions/UnknownDirective.ql | 2 +- .../ql/src/NodeJS/UnresolvableImport.ql | 2 +- javascript/ql/src/NodeJS/UnusedDependency.ql | 2 +- .../CWE-020/IncompleteUrlSchemeCheck.ql | 2 +- .../src/Security/CWE-384/SessionFixation.ql | 2 +- .../ql/src/Security/CWE-730/ServerCrash.ql | 2 +- .../ql/src/Statements/ImplicitReturn.ql | 2 +- .../Security/CWE-444/InsecureHttpParser.ql | 2 +- .../SsrfIpv6TransitionIncompleteGuard.ql | 8 +-- .../ql/test/experimental/TypeOrm/tests.ql | 2 +- .../ql/test/library-tests/Classes/tests.ql | 2 +- .../InterProceduralFlow/DataFlowConfig.qll | 6 +-- .../InterProceduralFlow/tests.ql | 12 ++--- .../library-tests/RangeAnalysis/DeadBranch.ql | 4 +- .../MissingUnicodeFlag/MissingUnicodeFlag.ql | 2 +- .../StringConcatenation/ClassContainsTwo.ql | 2 +- .../StringConcatenation/ContainsTwo.ql | 2 +- .../TypeScript/Namespaces/CheckGlobals.ql | 4 +- .../dependencies/DependencyCustomizations.qll | 2 +- .../frameworks/Restify2/tests.ql | 4 +- .../frameworks/Shelljs/ShellJS.ql | 2 +- .../library-tests/frameworks/Spife/tests.ql | 4 +- .../Validating RAML-based APIs/RAML.qll | 2 +- .../Validating RAML-based APIs/query2.ql | 2 +- .../Validating RAML-based APIs/query3.ql | 2 +- .../Validating RAML-based APIs/query4.ql | 2 +- .../TypeTrackingConsistency.ql | 2 +- python/ql/examples/snippets/raw_string.ql | 2 +- .../modules/CryptographyModule.qll | 10 ++-- .../modules/stdlib/HashlibModule.qll | 2 +- python/ql/lib/modeling/Util.qll | 2 +- python/ql/lib/semmle/python/ApiGraphs.qll | 8 +-- python/ql/lib/semmle/python/Class.qll | 6 +-- python/ql/lib/semmle/python/Files.qll | 4 +- python/ql/lib/semmle/python/Import.qll | 2 +- python/ql/lib/semmle/python/Module.qll | 8 +-- .../new/internal/DataFlowDispatch.qll | 2 +- python/ql/lib/semmle/python/filters/Tests.qll | 10 ++-- .../lib/semmle/python/frameworks/Peewee.qll | 4 +- .../semmle/python/frameworks/ServerLess.qll | 2 +- .../frameworks/internal/SubclassFinder.qll | 2 +- .../ql/lib/semmle/python/objects/TObject.qll | 2 +- .../dataflow/TarSlipCustomizations.qll | 4 +- .../lib/semmle/python/types/ModuleObject.qll | 2 +- .../utils/test/dataflow/MaximalFlowTest.qll | 2 +- python/ql/src/Classes/ClassAttributes.qll | 2 +- .../IncorrectRaiseInSpecialMethod.ql | 2 +- python/ql/src/Imports/UnusedImport.ql | 2 +- python/ql/src/Lexical/CommentedOutCode.qll | 6 +-- python/ql/src/Lexical/ToDoComment.ql | 2 +- .../CWE-352/CSRFProtectionDisabled.ql | 2 +- .../Security/CWE-798/HardcodedCredentials.ql | 8 +-- .../ql/src/Statements/RedundantAssignment.ql | 2 +- .../src/Statements/UnusedExceptionObject.ql | 6 +-- python/ql/src/Variables/Definition.qll | 4 +- python/ql/src/Variables/UnusedParameter.ql | 2 +- python/ql/src/analysis/ImportFailure.ql | 12 ++--- .../WebAppConstantSecretKey.ql | 2 +- .../WebAppConstantSecretKeyFlask.qll | 4 +- .../example_alerts/WeakBlockMode.ql | 2 +- .../semmle/python/libraries/PyJWT.qll | 2 +- .../semmle/python/libraries/PythonJose.qll | 2 +- .../python/security/DecompressionBomb.qll | 10 ++-- python/ql/src/external/Thrift.qll | 2 +- python/ql/src/meta/debug/SimpleClassDebug.ql | 2 +- python/ql/test/extractor-tests/flags/Flags.ql | 4 +- .../library-tests/PointsTo/functions/Calls.ql | 2 +- .../PointsTo/general/interesting.qll | 2 +- .../library-tests/PointsTo/new/Consistency.ql | 2 +- .../PointsTo/new/PointsToMissing.ql | 2 +- .../ql/lib/RecordedCalls.qll | 4 +- ql/ql/src/codeql_ql/ast/Ast.qll | 2 +- ql/ql/src/codeql_ql/ast/Yaml.qll | 4 +- .../codeql_ql/bugs/PathProblemQueryQuery.qll | 4 +- ql/ql/src/codeql_ql/style/DeadCodeQuery.qll | 8 +-- ql/ql/src/queries/bugs/PathProblemQuery.ql | 2 +- .../performance/AbstractClassImport.ql | 6 +-- .../performance/VarUnusedInDisjunct.ql | 2 +- ql/ql/src/queries/style/AlertMessage.ql | 12 ++--- ql/ql/src/queries/style/AndroidIdPrefix.ql | 6 +-- .../queries/style/ConsistentAlertMessage.ql | 2 +- ql/ql/src/queries/style/DBTypeInNonLib.ql | 6 +-- .../style/DataFlowConfigModuleNaming.ql | 2 +- ql/ql/src/queries/style/NonDocBlock.ql | 2 +- .../src/queries/style/ToStringInQueryLogic.ql | 2 +- .../performance/VarUnusedInDisjunct/Test.qll | 54 +++++++++---------- ruby/ql/lib/codeql/ruby/ApiGraphs.qll | 2 +- .../lib/codeql/ruby/ast/internal/Constant.qll | 4 +- .../lib/codeql/ruby/ast/internal/Literal.qll | 6 +-- .../dataflow/internal/FlowSummaryImpl.qll | 2 +- .../ruby/frameworks/ActionController.qll | 2 +- .../ql/lib/codeql/ruby/frameworks/GraphQL.qll | 2 +- ruby/ql/lib/codeql/ruby/frameworks/Rails.qll | 2 +- .../ql/lib/codeql/ruby/frameworks/Sinatra.qll | 2 +- .../actiondispatch/internal/Routing.qll | 2 +- .../codeql/ruby/security/SensitiveActions.qll | 2 +- .../security/internal/CleartextSources.qll | 2 +- .../ql/src/queries/modeling/internal/Util.qll | 2 +- .../security/cwe-798/HardcodedCredentials.ql | 4 +- .../ql/src/queries/summary/LinesOfUserCode.ql | 2 +- .../snippets/simple_constant_password.ql | 2 +- rust/ql/integration-tests/subst/file.ql | 2 +- .../rust/frameworks/rustcrypto/RustCrypto.qll | 2 +- .../rust/frameworks/stdlib/Builtins.qll | 2 +- .../codeql/rust/internal/PathResolution.qll | 2 +- .../internal/typeinference/TypeInference.qll | 2 +- rust/ql/lib/utils/test/InlineFlowTest.qll | 2 +- .../PathResolutionInlineExpectationsTest.qll | 2 +- rust/ql/test/TestUtils.qll | 2 +- .../codeql/dataflow/internal/DataFlowImpl.qll | 2 +- .../codeql/regex/OverlyLargeRangeQuery.qll | 2 +- shared/util/codeql/util/FilePath.qll | 2 +- shared/util/codeql/util/FileSystem.qll | 4 +- shared/yaml/codeql/serverless/ServerLess.qll | 2 +- shared/yaml/codeql/yaml/Yaml.qll | 4 +- .../consistency-queries/UnresolvedAstNodes.ql | 2 +- .../RegexLiteralExpr/RegexLiteralExpr.ql | 2 +- .../posix/deduplication/BuiltinTypes.ql | 4 +- swift/ql/lib/codeql/swift/StringFormat.qll | 2 +- .../ql/lib/codeql/swift/elements/Comments.qll | 8 +-- .../swift/elements/internal/FileImpl.qll | 2 +- .../frameworks/StandardLibrary/Array.qll | 2 +- .../frameworks/StandardLibrary/Dictionary.qll | 2 +- .../StandardLibrary/PointerTypes.qll | 6 +-- swift/ql/lib/codeql/swift/regex/Regex.qll | 2 +- .../file_is_successfully_extracted.ql | 2 +- swift/ql/lib/utils/test/InlineFlowTest.qll | 2 +- .../internal/UnresolvedAstNodes.ql | 2 +- swift/ql/test/TestUtils.qll | 2 +- .../test/extractor-tests/declarations/all.ql | 2 +- .../test/extractor-tests/expressions/all.ql | 2 +- .../extractor-tests/expressions/semantics.ql | 2 +- swift/ql/test/extractor-tests/patterns/all.ql | 2 +- .../statements/ConditionElements.ql | 2 +- .../statements/LabeledConditionalStmts.ql | 2 +- .../statements/LabeledStmts.ql | 2 +- .../test/extractor-tests/statements/Labels.ql | 2 +- .../extractor-tests/statements/YieldStmts.ql | 2 +- .../test/extractor-tests/types/ClassDecls.ql | 2 +- .../test/extractor-tests/types/StructDecls.ql | 2 +- .../extractor-tests/types/ThrowingAndAsync.ql | 2 +- swift/ql/test/extractor-tests/types/Types.ql | 2 +- .../library-tests/controlflow/graph/Cfg.ql | 2 +- .../dataflow/dataflow/FlowConfig.qll | 2 +- .../dataflow/flowsources/FlowSourcesInline.ql | 2 +- .../dataflow/taint/core/Taint.qll | 4 +- .../elements/decl/function/function.ql | 2 +- swift/ql/test/library-tests/regex/regex.ql | 2 +- .../internal/dev/debugDataFlowGraph.ql | 2 +- .../dev/debugLocalNameBindingGraph.ql | 2 +- .../dev/debugStaticNameBindingGraph.ql | 2 +- .../codeql/unified/internal/mad/LegacyMaD.qll | 2 +- .../internal/typeinference/TypeInference.qll | 2 +- .../queries/unusedentities/UnusedVariable.ql | 2 +- 518 files changed, 925 insertions(+), 922 deletions(-) diff --git a/actions/ql/lib/codeql/actions/PowerShell.qll b/actions/ql/lib/codeql/actions/PowerShell.qll index 3ae706970fa7..a14becae9e88 100644 --- a/actions/ql/lib/codeql/actions/PowerShell.qll +++ b/actions/ql/lib/codeql/actions/PowerShell.qll @@ -4,7 +4,7 @@ class PowerShellScript extends ShellScript { PowerShellScript() { exists(Run run | this = run.getScript() and - run.getShell().matches("pwsh%") + run.getShell().startsWith("pwsh") ) } diff --git a/actions/ql/lib/codeql/actions/ast/internal/Ast.qll b/actions/ql/lib/codeql/actions/ast/internal/Ast.qll index 82d4a1186708..bf5a7b5b0caa 100644 --- a/actions/ql/lib/codeql/actions/ast/internal/Ast.qll +++ b/actions/ql/lib/codeql/actions/ast/internal/Ast.qll @@ -202,10 +202,10 @@ class ShellScriptImpl extends ScalarValueImpl { abstract string getCommand(int i); string getACommand() { - if this.getEnclosingRun().getShell().matches("bash%") + if this.getEnclosingRun().getShell().startsWith("bash") then result = this.(BashShellScript).getACommand() else - if this.getEnclosingRun().getShell().matches("pwsh%") + if this.getEnclosingRun().getShell().startsWith("pwsh") then result = this.(PowerShellScript).getACommand() else result = "NOT IMPLEMENTED" } @@ -436,7 +436,7 @@ class CompositeActionImpl extends AstNodeImpl, TCompositeAction { private predicate hasExplicitWritePermission() { // a calling job has an explicit write permission - this.getACallerJob().getPermissions().getAPermission().matches("%write") + this.getACallerJob().getPermissions().getAPermission().endsWith("write") } /** Holds if the action is privileged. */ @@ -981,12 +981,12 @@ class JobImpl extends AstNodeImpl, TJobNode { private predicate hasExplicitReadPermission() { // the job has not an explicit write permission exists(this.getPermissions().getAPermission()) and - not this.getPermissions().getAPermission().matches("%write") + not this.getPermissions().getAPermission().endsWith("write") } private predicate hasExplicitWritePermission() { // the job has an explicit write permission - this.getPermissions().getAPermission().matches("%write") + this.getPermissions().getAPermission().endsWith("write") } private predicate hasImplicitNonePermission() { @@ -1010,7 +1010,7 @@ class JobImpl extends AstNodeImpl, TJobNode { // the job has not an explicit write permission not exists(this.getPermissions()) and exists(this.getEnclosingWorkflow().getPermissions().getAPermission()) and - not this.getEnclosingWorkflow().getPermissions().getAPermission().matches("%write") + not this.getEnclosingWorkflow().getPermissions().getAPermission().endsWith("write") or not exists(this.getPermissions()) and not exists(this.getEnclosingWorkflow().getPermissions()) and @@ -1019,13 +1019,13 @@ class JobImpl extends AstNodeImpl, TJobNode { .getACaller() .getPermissions() .getAPermission() - .matches("%read") + .endsWith("read") } private predicate hasImplicitWritePermission() { // the job has an explicit write permission not exists(this.getPermissions()) and - this.getEnclosingWorkflow().getPermissions().getAPermission().matches("%write") + this.getEnclosingWorkflow().getPermissions().getAPermission().endsWith("write") or not exists(this.getPermissions()) and not exists(this.getEnclosingWorkflow().getPermissions()) and @@ -1034,7 +1034,7 @@ class JobImpl extends AstNodeImpl, TJobNode { .getACaller() .getPermissions() .getAPermission() - .matches("%write") + .endsWith("write") } private predicate hasRuntimeData() { @@ -1054,7 +1054,7 @@ class JobImpl extends AstNodeImpl, TJobNode { // We cannot trust the permissions for pull_request events since they depend on the // provenance of the head branch (local vs fork) not trigger.trim() = "pull_request" and - perms.toLowerCase().matches("%write%") + perms.toLowerCase().contains("write") ) } @@ -1400,7 +1400,7 @@ class ExternalJobImpl extends JobImpl, UsesImpl { ExternalJobImpl() { n.lookup("uses") = u } override string getCallee() { - if u.getValue().matches("./%") + if u.getValue().startsWith("./") then result = u.getValue().regexpCapture(pathUsesParser(), 1) else result = @@ -1457,7 +1457,7 @@ class RunImpl extends StepImpl { if this.getEnclosingJob().getARunsOnLabel().matches(["ubuntu%", "macos%"]) then result = "bash" else - if this.getEnclosingJob().getARunsOnLabel().matches("windows%") + if this.getEnclosingJob().getARunsOnLabel().startsWith("windows") then result = "pwsh" else result = "bash" } diff --git a/actions/ql/lib/codeql/actions/config/Config.qll b/actions/ql/lib/codeql/actions/config/Config.qll index f6b8d0c979f3..160e5d0ff665 100644 --- a/actions/ql/lib/codeql/actions/config/Config.qll +++ b/actions/ql/lib/codeql/actions/config/Config.qll @@ -138,7 +138,7 @@ predicate immutableActionsDataModel(string action) { Extensions::immutableAction */ predicate trustedActionsOwnerDataModel(string owner) { Extensions::trustedActionsOwnerDataModel(owner) and - not owner.matches("!%") and + not owner.startsWith("!") and not Extensions::trustedActionsOwnerDataModel("!" + owner) } diff --git a/actions/ql/lib/codeql/actions/dataflow/ExternalFlow.qll b/actions/ql/lib/codeql/actions/dataflow/ExternalFlow.qll index 9667c6e525ea..965d70bc418c 100644 --- a/actions/ql/lib/codeql/actions/dataflow/ExternalFlow.qll +++ b/actions/ql/lib/codeql/actions/dataflow/ExternalFlow.qll @@ -61,10 +61,10 @@ predicate madSource(DataFlow::Node source, string kind, string fieldName) { else uses.getVersion() = version.trim() ) and ( - if fieldName.trim().matches("env.%") + if fieldName.trim().startsWith("env.") then source.asExpr() = uses.getInScopeEnvVarExpr(fieldName.trim().replaceAll("env.", "")) else ( - fieldName.trim().matches("output.%") and + fieldName.trim().startsWith("output.") and source.asExpr() = uses ) ) @@ -87,10 +87,10 @@ predicate madStoreStep(DataFlow::Node pred, DataFlow::Node succ, DataFlow::Conte ) and // pred provenance ( - input.trim().matches("env.%") and + input.trim().startsWith("env.") and pred.asExpr() = uses.getInScopeEnvVarExpr(input.trim().replaceAll("env.", "")) or - input.trim().matches("input.%") and + input.trim().startsWith("input.") and pred.asExpr() = uses.getArgumentExpr(input.trim().replaceAll("input.", "")) or input.trim() = "artifact" and @@ -118,10 +118,10 @@ predicate madSink(DataFlow::Node sink, string kind) { ) and // pred provenance ( - input.trim().matches("env.%") and + input.trim().startsWith("env.") and sink.asExpr() = uses.getInScopeEnvVarExpr(input.trim().replaceAll("env.", "")) or - input.trim().matches("input.%") and + input.trim().startsWith("input.") and sink.asExpr() = uses.getArgumentExpr(input.trim().replaceAll("input.", "")) or input.trim() = "artifact" and diff --git a/actions/ql/lib/codeql/actions/dataflow/FlowSources.qll b/actions/ql/lib/codeql/actions/dataflow/FlowSources.qll index 8b0a2a33eb55..14dc018e043e 100644 --- a/actions/ql/lib/codeql/actions/dataflow/FlowSources.qll +++ b/actions/ql/lib/codeql/actions/dataflow/FlowSources.qll @@ -174,7 +174,7 @@ class GitHubEventPathSource extends RemoteFlowSource, CommandSource { GitHubEventPathSource() { this.asExpr() = run.getScript() and run.getScript().getACommand() = cmd and - cmd.matches("jq%") and + cmd.startsWith("jq") and cmd.matches("%GITHUB_EVENT_PATH%") and exists(string regexp, string access_path | untrustedEventPropertiesDataModel(regexp, flag) and @@ -371,11 +371,11 @@ class OctokitRequestActionSource extends RemoteFlowSource { route = u.getArgument("route").trim() and route.indexOf("GET") = 0 and ( - route.matches("%/commits%") or - route.matches("%/comments%") or - route.matches("%/pulls%") or - route.matches("%/issues%") or - route.matches("%/users%") or + route.contains("/commits") or + route.contains("/comments") or + route.contains("/pulls") or + route.contains("/issues") or + route.contains("/users") or route.matches("%github.event.issue.pull_request.url%") ) and this.asExpr() = u diff --git a/actions/ql/lib/codeql/actions/dataflow/TaintSteps.qll b/actions/ql/lib/codeql/actions/dataflow/TaintSteps.qll index 56e2c75123c0..0a8e331b3eaf 100644 --- a/actions/ql/lib/codeql/actions/dataflow/TaintSteps.qll +++ b/actions/ql/lib/codeql/actions/dataflow/TaintSteps.qll @@ -104,7 +104,7 @@ predicate zenteredIssueFormBodyParserSource(DataFlow::Node pred, DataFlow::Node o.getFieldName() = "data" or o instanceof JsonReferenceExpression and - o.(JsonReferenceExpression).getInnerExpression().matches("%.data") + o.(JsonReferenceExpression).getInnerExpression().endsWith(".data") ) and succ.asExpr() = o ) @@ -124,7 +124,7 @@ predicate octokitRequestActionTaintStep(DataFlow::Node pred, DataFlow::Node succ o.getFieldName() = "data" or o instanceof JsonReferenceExpression and - o.(JsonReferenceExpression).getInnerExpression().matches("%.data") and + o.(JsonReferenceExpression).getInnerExpression().endsWith(".data") and o.(JsonReferenceExpression) .getAccessPath() .matches([ diff --git a/actions/ql/lib/codeql/actions/security/ArtifactPoisoningQuery.qll b/actions/ql/lib/codeql/actions/security/ArtifactPoisoningQuery.qll index af3b9d62367c..4ab2e76f07ba 100644 --- a/actions/ql/lib/codeql/actions/security/ArtifactPoisoningQuery.qll +++ b/actions/ql/lib/codeql/actions/security/ArtifactPoisoningQuery.qll @@ -149,9 +149,9 @@ class ActionsGitHubScriptDownloadStep extends UntrustedArtifactDownloadStep, Use this.getCallee() = "actions/github-script" and exists(string script | this.getArgument("script") = script and - script.matches("%listWorkflowRunArtifacts(%") and - script.matches("%downloadArtifact(%") and - script.matches("%writeFileSync(%") and + script.contains("listWorkflowRunArtifacts(") and + script.contains("downloadArtifact(") and + script.contains("writeFileSync(") and // Filter out artifacts that were created by pull-request. not script.matches("%exclude_pull_requests: true%") ) @@ -265,7 +265,7 @@ class ArtifactPoisoningSink extends DataFlow::Node { exists(PoisonableStep poisonable | download.getAFollowingStep() = poisonable and // excluding artifacts downloaded to the temporary directory - not download.getPath().regexpMatch("^/tmp.*") and + not download.getPath().startsWith("/tmp") and not download.getPath().regexpMatch("^\\$\\{\\{\\s*runner\\.temp\\s*}}.*") and not download.getPath().regexpMatch("^\\$RUNNER_TEMP.*") | diff --git a/actions/ql/lib/codeql/actions/security/ControlChecks.qll b/actions/ql/lib/codeql/actions/security/ControlChecks.qll index 733c92559d70..434bdfca16cb 100644 --- a/actions/ql/lib/codeql/actions/security/ControlChecks.qll +++ b/actions/ql/lib/codeql/actions/security/ControlChecks.qll @@ -330,7 +330,7 @@ class ActorIfCheck extends ActorCheck instanceof If { normalizeExpr(this.getCondition()) .regexpFind(["\\bgithub\\.actor\\b", "\\bgithub\\.triggering_actor\\b",], _, _) ) and - not normalizeExpr(this.getCondition()).matches("%[bot]%") + not normalizeExpr(this.getCondition()).contains("[bot]") } } @@ -462,7 +462,7 @@ class AssociationActionCheck extends AssociationCheck instanceof UsesStep { ) or this.getCallee() = "actions/github-script" and - this.getArgument("script").splitAt("\n").matches("%getMembershipForUserInOrg%") + this.getArgument("script").splitAt("\n").contains("getMembershipForUserInOrg") or this.getCallee() = "octokit/request-action" and this.getArgument("route").regexpMatch("GET.*(memberships).*") @@ -495,7 +495,7 @@ class PermissionActionCheck extends PermissionCheck instanceof UsesStep { ) or this.getCallee() = "actions/github-script" and - this.getArgument("script").splitAt("\n").matches("%getCollaboratorPermissionLevel%") + this.getArgument("script").splitAt("\n").contains("getCollaboratorPermissionLevel") or this.getCallee() = "octokit/request-action" and this.getArgument("route").regexpMatch("GET.*(collaborators|permission).*") diff --git a/actions/ql/lib/codeql/actions/security/OutputClobberingQuery.qll b/actions/ql/lib/codeql/actions/security/OutputClobberingQuery.qll index 57f0e31a25b4..581d601a476c 100644 --- a/actions/ql/lib/codeql/actions/security/OutputClobberingQuery.qll +++ b/actions/ql/lib/codeql/actions/security/OutputClobberingQuery.qll @@ -247,7 +247,7 @@ private module OutputClobberingConfig implements DataFlow::ConfigSig { succ.asExpr() = run.getScript() and ( exists(run.getScript().getAFileReadCommand()) or - run.getScript().getAStmt().matches("%::set-output %") + run.getScript().getAStmt().contains("::set-output ") ) ) } diff --git a/actions/ql/lib/codeql/actions/security/PoisonableSteps.qll b/actions/ql/lib/codeql/actions/security/PoisonableSteps.qll index 1f3bc66bd776..a5d1956016fb 100644 --- a/actions/ql/lib/codeql/actions/security/PoisonableSteps.qll +++ b/actions/ql/lib/codeql/actions/security/PoisonableSteps.qll @@ -50,7 +50,7 @@ class LocalScriptExecutionRunStep extends PoisonableStep, Run { } class LocalActionUsesStep extends PoisonableStep, UsesStep { - LocalActionUsesStep() { this.getCallee().matches("./%") } + LocalActionUsesStep() { this.getCallee().startsWith("./") } string getPath() { result = normalizePath(this.getCallee()) } } diff --git a/actions/ql/lib/codeql/actions/security/UntrustedCheckoutQuery.qll b/actions/ql/lib/codeql/actions/security/UntrustedCheckoutQuery.qll index bd8ec6f035e9..21f0feccf223 100644 --- a/actions/ql/lib/codeql/actions/security/UntrustedCheckoutQuery.qll +++ b/actions/ql/lib/codeql/actions/security/UntrustedCheckoutQuery.qll @@ -202,7 +202,7 @@ class SimplePRHeadCheckoutStep extends Step { this = uses and uses.getCallee() = "actions/checkout" and exists(uses.getArgument("ref")) and - not uses.getArgument("ref").matches("%base%") and + not uses.getArgument("ref").contains("base") and uses.getATriggerEvent().getName() = checkoutTriggers() ) or diff --git a/actions/ql/lib/codeql/files/FileSystem.qll b/actions/ql/lib/codeql/files/FileSystem.qll index 552b85a4673f..42193ad15292 100644 --- a/actions/ql/lib/codeql/files/FileSystem.qll +++ b/actions/ql/lib/codeql/files/FileSystem.qll @@ -117,7 +117,7 @@ abstract class Container extends @container { absPath = pref and result = "" or absPath = pref.regexpReplaceAll("/$", "") + "/" + result and - not result.matches("/%") + not result.startsWith("/") ) } diff --git a/actions/ql/src/Security/CWE-312/ExcessiveSecretsExposure.ql b/actions/ql/src/Security/CWE-312/ExcessiveSecretsExposure.ql index 1a01033c5676..421d646d6d23 100644 --- a/actions/ql/src/Security/CWE-312/ExcessiveSecretsExposure.ql +++ b/actions/ql/src/Security/CWE-312/ExcessiveSecretsExposure.ql @@ -16,10 +16,10 @@ import codeql.actions.ast.internal.Ast from Expression expr where - getAToJsonReferenceExpression(expr.getExpression(), _).matches("secrets%") + getAToJsonReferenceExpression(expr.getExpression(), _).startsWith("secrets") or - expr.getExpression().matches("secrets[%") and + expr.getExpression().startsWith("secrets[") and not expr.getExpression().matches("secrets[\"%") and - not expr.getExpression().matches("secrets['%") + not expr.getExpression().startsWith("secrets['") select expr, "All organization and repository secrets are passed to the workflow runner in $@", expr, expr.getExpression() diff --git a/actions/ql/src/Security/CWE-571/ExpressionIsAlwaysTrueCritical.ql b/actions/ql/src/Security/CWE-571/ExpressionIsAlwaysTrueCritical.ql index 6eaaca6e05db..83288489c1e5 100644 --- a/actions/ql/src/Security/CWE-571/ExpressionIsAlwaysTrueCritical.ql +++ b/actions/ql/src/Security/CWE-571/ExpressionIsAlwaysTrueCritical.ql @@ -16,10 +16,10 @@ import codeql.actions.security.ControlChecks from ControlCheck i where - i.(If).getCondition().matches("%${{%") and + i.(If).getCondition().contains("${{") and ( - not i.(If).getCondition().matches("${{%") or - not i.(If).getCondition().matches("%}}") + not i.(If).getCondition().startsWith("${{") or + not i.(If).getCondition().endsWith("}}") ) or count(i.(If).getCondition().splitAt("${{")) > 2 diff --git a/actions/ql/src/Security/CWE-571/ExpressionIsAlwaysTrueHigh.ql b/actions/ql/src/Security/CWE-571/ExpressionIsAlwaysTrueHigh.ql index 6b0c69977612..6aae4e91db44 100644 --- a/actions/ql/src/Security/CWE-571/ExpressionIsAlwaysTrueHigh.ql +++ b/actions/ql/src/Security/CWE-571/ExpressionIsAlwaysTrueHigh.ql @@ -18,10 +18,10 @@ from If i where not i instanceof ControlCheck and ( - i.getCondition().matches("%${{%") and + i.getCondition().contains("${{") and ( - not i.getCondition().matches("${{%") or - not i.getCondition().matches("%}}") + not i.getCondition().startsWith("${{") or + not i.getCondition().endsWith("}}") ) or count(i.getCondition().splitAt("${{")) > 2 diff --git a/actions/ql/src/Security/CWE-829/UnpinnedActionsTag.ql b/actions/ql/src/Security/CWE-829/UnpinnedActionsTag.ql index 8a1f821d073a..6653af8f8980 100644 --- a/actions/ql/src/Security/CWE-829/UnpinnedActionsTag.ql +++ b/actions/ql/src/Security/CWE-829/UnpinnedActionsTag.ql @@ -37,7 +37,7 @@ private predicate isContainerImage(string nwo) { nwo.regexpMatch("^docker://.+") // resolved at the commit the calling workflow is running. Like `./` local (self workspace) // references, it is inherently pinned and can never be an unpinned-tag finding, so we never flag it. bindingset[nwo] -private predicate isSelfRepository(string nwo) { nwo.matches("$/%") } +private predicate isSelfRepository(string nwo) { nwo.startsWith("$/") } private predicate hasUsesContainerName(Uses uses, string name) { exists(Workflow workflow | diff --git a/cpp/ql/examples/snippets/todocomment.ql b/cpp/ql/examples/snippets/todocomment.ql index d11782bada0b..8f8f6c7f8490 100644 --- a/cpp/ql/examples/snippets/todocomment.ql +++ b/cpp/ql/examples/snippets/todocomment.ql @@ -10,5 +10,5 @@ import cpp from Comment c -where c.getContents().matches("%TODO%") +where c.getContents().contains("TODO") select c diff --git a/cpp/ql/lib/experimental/cryptography/utils/OpenSSL/CryptoFunction.qll b/cpp/ql/lib/experimental/cryptography/utils/OpenSSL/CryptoFunction.qll index 1e0f3b6dfbfb..c5d9ff5f3bee 100644 --- a/cpp/ql/lib/experimental/cryptography/utils/OpenSSL/CryptoFunction.qll +++ b/cpp/ql/lib/experimental/cryptography/utils/OpenSSL/CryptoFunction.qll @@ -80,7 +80,7 @@ private string normalizeFunctionName(Function f, string algType) { ( (result.length() <= 4 and result = "DESX") implies - (f.getName().toUpperCase().matches("%DESX%") or f.getName().toUpperCase().matches("%DES_X%")) + (f.getName().toUpperCase().contains("DESX") or f.getName().toUpperCase().matches("%DES_X%")) ) and // (result.length() <= 3 implies (not f.getName().toUpperCase().regexpMatch(".*" + result + "[a-zA-Z0-9].*|.*[a-zA-Z0-9]" + result + ".*"))) // and @@ -90,7 +90,7 @@ private string normalizeFunctionName(Function f, string algType) { implies not f.getName().toUpperCase().regexpMatch(".*DES[a-zA-Z0-9].*|.*[a-zA-Z0-9]DES.*") ) and - // ((result.matches("%DES%")) implies not exists(string s | s in ["DESCRIBE", "DESTROY", "DESCRIPTION", "DESCRIPTOR", "NODES"] | + // ((result.contains("DES")) implies not exists(string s | s in ["DESCRIBE", "DESTROY", "DESCRIPTION", "DESCRIPTOR", "NODES"] | // f.getName().toUpperCase().matches("%" + s + "%"))) and // SEED specific false positives ( @@ -106,16 +106,16 @@ private string normalizeFunctionName(Function f, string algType) { ) ) and // ARIA specific false positives - (result.matches("ARIA") implies not f.getName().toUpperCase().matches("%VARIANT%")) and + (result.matches("ARIA") implies not f.getName().toUpperCase().contains("VARIANT")) and // CTR false positives - (result.matches("CTR") implies not f.getName().toUpperCase().matches("%CTRL%")) and + (result.matches("CTR") implies not f.getName().toUpperCase().contains("CTRL")) and // ES false positives (e.g., ES256 from AES256) - (result.matches("ES%") implies not f.getName().toUpperCase().matches("%AES%")) and + (result.startsWith("ES") implies not f.getName().toUpperCase().contains("AES")) and // RSA false positives - (result.matches("RSA") implies not f.getName().toUpperCase().matches("%UNIVERSAL%")) and + (result.matches("RSA") implies not f.getName().toUpperCase().contains("UNIVERSAL")) and //rsaz functions deemed to be too low level, and can be ignored not f.getLocation().getFile().getBaseName().matches("rsaz_exp.c") and // General False positives // Functions that 'get' do not set an algorithm, and therefore are considered ignorable - not f.getName().toLowerCase().matches("%get%") + not f.getName().toLowerCase().contains("get") } diff --git a/cpp/ql/lib/experimental/cryptography/utils/OpenSSL/DataBuilders.qll b/cpp/ql/lib/experimental/cryptography/utils/OpenSSL/DataBuilders.qll index 54121c367665..cf1ad9c2d982 100644 --- a/cpp/ql/lib/experimental/cryptography/utils/OpenSSL/DataBuilders.qll +++ b/cpp/ql/lib/experimental/cryptography/utils/OpenSSL/DataBuilders.qll @@ -38,7 +38,7 @@ private string privateNormalizeFunctionName(Function f, string algType) { ( result.matches("ES256") implies - not exists(string res2 | res2 = basicNormalizeFunctionName(f, _) and res2.matches("AES%")) + not exists(string res2 | res2 = basicNormalizeFunctionName(f, _) and res2.startsWith("AES")) ) } @@ -70,7 +70,7 @@ string normalizeFunctionName(Function f, string algType) { ( (result.length() <= 4 and result = "DESX") implies - (f.getName().toUpperCase().matches("%DESX%") or f.getName().toUpperCase().matches("%DES_X%")) + (f.getName().toUpperCase().contains("DESX") or f.getName().toUpperCase().matches("%DES_X%")) ) and // (result.length() <= 3 implies (not f.getName().toUpperCase().regexpMatch(".*" + result + "[a-zA-Z0-9].*|.*[a-zA-Z0-9]" + result + ".*"))) // and @@ -80,11 +80,11 @@ string normalizeFunctionName(Function f, string algType) { implies not f.getName().toUpperCase().regexpMatch(".*DES[a-zA-Z0-9].*|.*[a-zA-Z0-9]DES.*") ) and - // ((result.matches("%DES%")) implies not exists(string s | s in ["DESCRIBE", "DESTROY", "DESCRIPTION", "DESCRIPTOR", "NODES"] | + // ((result.contains("DES")) implies not exists(string s | s in ["DESCRIBE", "DESTROY", "DESCRIPTION", "DESCRIPTOR", "NODES"] | // f.getName().toUpperCase().matches("%" + s + "%"))) and // SEED specific false positives ( - result.matches("%SEED%") + result.contains("SEED") implies not not exists(string s | s in ["NEW_SEED", "GEN_SEED", "SET_SEED", "GET_SEED", "GET0_SEED", "RESEED", "SEEDING"] @@ -93,7 +93,7 @@ string normalizeFunctionName(Function f, string algType) { ) ) and // ARIA specific false positives - (result.matches("%ARIA%") implies not f.getName().toUpperCase().matches("%VARIANT%")) + (result.contains("ARIA") implies not f.getName().toUpperCase().contains("VARIANT")) } /** @@ -148,6 +148,6 @@ string normalizeName(string name, string algType) { ( result.matches("ES256") implies - not exists(string res2 | res2 = privateNormalizeName(name, _) and res2.matches("AES%")) + not exists(string res2 | res2 = privateNormalizeName(name, _) and res2.startsWith("AES")) ) } diff --git a/cpp/ql/lib/experimental/cryptography/utils/OpenSSL/LibraryFunction.qll b/cpp/ql/lib/experimental/cryptography/utils/OpenSSL/LibraryFunction.qll index a70b91e5e9e8..1c0a11dafbc1 100644 --- a/cpp/ql/lib/experimental/cryptography/utils/OpenSSL/LibraryFunction.qll +++ b/cpp/ql/lib/experimental/cryptography/utils/OpenSSL/LibraryFunction.qll @@ -5,7 +5,7 @@ import cpp * if the function's declaration exists in a subdirectory of any directory matching 'openssl' as a substring. */ predicate isPossibleOpenSSLFunction(Function f) { - f.getADeclarationLocation().toString().toLowerCase().matches("%openssl%") + f.getADeclarationLocation().toString().toLowerCase().contains("openssl") } predicate openSSLLibraryFunc(Function f) { diff --git a/cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/AlgToAVCFlow.qll b/cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/AlgToAVCFlow.qll index eafc839fbb8a..9ed305db1fa9 100644 --- a/cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/AlgToAVCFlow.qll +++ b/cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/AlgToAVCFlow.qll @@ -40,7 +40,7 @@ module KnownOpenSslAlgorithmToAlgorithmValueConsumerConfig implements DataFlow:: or va = node.asIndirectExpr() | - v.getName().matches("%argv") + v.getName().endsWith("argv") ) } diff --git a/cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/CipherAlgorithmInstance.qll b/cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/CipherAlgorithmInstance.qll index 23efacae69b7..cde3975b9f8e 100644 --- a/cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/CipherAlgorithmInstance.qll +++ b/cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/CipherAlgorithmInstance.qll @@ -17,47 +17,47 @@ predicate knownOpenSslConstantToCipherFamilyType( exists(string name | name = e.(KnownOpenSslAlgorithmExpr).getNormalizedName() and ( - name.matches("AES%") and type = KeyOpAlg::TSymmetricCipher(KeyOpAlg::AES()) + name.startsWith("AES") and type = KeyOpAlg::TSymmetricCipher(KeyOpAlg::AES()) or - name.matches("ARIA%") and type = KeyOpAlg::TSymmetricCipher(KeyOpAlg::ARIA()) + name.startsWith("ARIA") and type = KeyOpAlg::TSymmetricCipher(KeyOpAlg::ARIA()) or - name.matches("BLOWFISH%") and type = KeyOpAlg::TSymmetricCipher(KeyOpAlg::BLOWFISH()) + name.startsWith("BLOWFISH") and type = KeyOpAlg::TSymmetricCipher(KeyOpAlg::BLOWFISH()) or - name.matches("BF%") and type = KeyOpAlg::TSymmetricCipher(KeyOpAlg::BLOWFISH()) + name.startsWith("BF") and type = KeyOpAlg::TSymmetricCipher(KeyOpAlg::BLOWFISH()) or - name.matches("CAMELLIA%") and type = KeyOpAlg::TSymmetricCipher(KeyOpAlg::CAMELLIA()) + name.startsWith("CAMELLIA") and type = KeyOpAlg::TSymmetricCipher(KeyOpAlg::CAMELLIA()) or - name.matches("CHACHA20%") and type = KeyOpAlg::TSymmetricCipher(KeyOpAlg::CHACHA20()) + name.startsWith("CHACHA20") and type = KeyOpAlg::TSymmetricCipher(KeyOpAlg::CHACHA20()) or - name.matches("CAST5%") and type = KeyOpAlg::TSymmetricCipher(KeyOpAlg::CAST5()) + name.startsWith("CAST5") and type = KeyOpAlg::TSymmetricCipher(KeyOpAlg::CAST5()) or - name.matches("2DES%") and type = KeyOpAlg::TSymmetricCipher(KeyOpAlg::DOUBLE_DES()) + name.startsWith("2DES") and type = KeyOpAlg::TSymmetricCipher(KeyOpAlg::DOUBLE_DES()) or - name.matches("3DES%") and type = KeyOpAlg::TSymmetricCipher(KeyOpAlg::TRIPLE_DES()) + name.startsWith("3DES") and type = KeyOpAlg::TSymmetricCipher(KeyOpAlg::TRIPLE_DES()) or - name.matches("DES%") and type = KeyOpAlg::TSymmetricCipher(KeyOpAlg::DES()) + name.startsWith("DES") and type = KeyOpAlg::TSymmetricCipher(KeyOpAlg::DES()) or - name.matches("DESX%") and type = KeyOpAlg::TSymmetricCipher(KeyOpAlg::DESX()) + name.startsWith("DESX") and type = KeyOpAlg::TSymmetricCipher(KeyOpAlg::DESX()) or - name.matches("GOST%") and type = KeyOpAlg::TSymmetricCipher(KeyOpAlg::GOST()) + name.startsWith("GOST") and type = KeyOpAlg::TSymmetricCipher(KeyOpAlg::GOST()) or - name.matches("IDEA%") and type = KeyOpAlg::TSymmetricCipher(KeyOpAlg::IDEA()) + name.startsWith("IDEA") and type = KeyOpAlg::TSymmetricCipher(KeyOpAlg::IDEA()) or - name.matches("KUZNYECHIK%") and type = KeyOpAlg::TSymmetricCipher(KeyOpAlg::KUZNYECHIK()) + name.startsWith("KUZNYECHIK") and type = KeyOpAlg::TSymmetricCipher(KeyOpAlg::KUZNYECHIK()) or - name.matches("MAGMA%") and type = KeyOpAlg::TSymmetricCipher(KeyOpAlg::MAGMA()) + name.startsWith("MAGMA") and type = KeyOpAlg::TSymmetricCipher(KeyOpAlg::MAGMA()) or - name.matches("RC2%") and type = KeyOpAlg::TSymmetricCipher(KeyOpAlg::RC2()) + name.startsWith("RC2") and type = KeyOpAlg::TSymmetricCipher(KeyOpAlg::RC2()) or - name.matches("RC4%") and type = KeyOpAlg::TSymmetricCipher(KeyOpAlg::RC4()) + name.startsWith("RC4") and type = KeyOpAlg::TSymmetricCipher(KeyOpAlg::RC4()) or - name.matches("RC5%") and type = KeyOpAlg::TSymmetricCipher(KeyOpAlg::RC5()) + name.startsWith("RC5") and type = KeyOpAlg::TSymmetricCipher(KeyOpAlg::RC5()) or - name.matches("RSA%") and type = KeyOpAlg::TAsymmetricCipher(KeyOpAlg::RSA()) + name.startsWith("RSA") and type = KeyOpAlg::TAsymmetricCipher(KeyOpAlg::RSA()) or - name.matches("SEED%") and type = KeyOpAlg::TSymmetricCipher(KeyOpAlg::SEED()) + name.startsWith("SEED") and type = KeyOpAlg::TSymmetricCipher(KeyOpAlg::SEED()) or - name.matches("SM4%") and type = KeyOpAlg::TSymmetricCipher(KeyOpAlg::SM4()) + name.startsWith("SM4") and type = KeyOpAlg::TSymmetricCipher(KeyOpAlg::SM4()) ) ) } diff --git a/cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/HashAlgorithmInstance.qll b/cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/HashAlgorithmInstance.qll index 0facc99519d7..4c650742dd48 100644 --- a/cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/HashAlgorithmInstance.qll +++ b/cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/HashAlgorithmInstance.qll @@ -15,7 +15,7 @@ predicate knownOpenSslConstantToHashFamilyType( or name = "BLAKE2S" and type instanceof Crypto::BLAKE2S or - name.matches("GOST%") and type instanceof Crypto::GOST_HASH + name.startsWith("GOST") and type instanceof Crypto::GOST_HASH or name = "MD2" and type instanceof Crypto::MD2 or @@ -31,7 +31,7 @@ predicate knownOpenSslConstantToHashFamilyType( or name.matches("SHA_%") and not name.matches(["SHA1", "SHA3-"]) and type instanceof Crypto::SHA2 or - name.matches("SHA3-%") and type instanceof Crypto::SHA3 + name.startsWith("SHA3-") and type instanceof Crypto::SHA3 or name = "SHAKE" and type instanceof Crypto::SHAKE or diff --git a/cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/KnownAlgorithmConstants.qll b/cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/KnownAlgorithmConstants.qll index dcc7ad08ae5a..f632cc6e02a6 100644 --- a/cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/KnownAlgorithmConstants.qll +++ b/cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/KnownAlgorithmConstants.qll @@ -97,7 +97,7 @@ class KnownOpenSslCipherAlgorithmExpr extends Expr instanceof KnownOpenSslAlgori KnownOpenSslCipherAlgorithmExpr() { algType = this.(KnownOpenSslAlgorithmExpr).getAlgType() and - algType.matches("%ENCRYPTION") + algType.endsWith("ENCRYPTION") } int getExplicitKeySize() { @@ -113,7 +113,7 @@ class KnownOpenSslPaddingAlgorithmExpr extends Expr instanceof KnownOpenSslAlgor KnownOpenSslPaddingAlgorithmExpr() { exists(string algType | resolveAlgorithmFromExpr(this, _, algType) and - algType.matches("%PADDING") + algType.endsWith("PADDING") ) } } diff --git a/cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/SignatureAlgorithmInstance.qll b/cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/SignatureAlgorithmInstance.qll index dda7aea22dcd..14c2ffe189ec 100644 --- a/cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/SignatureAlgorithmInstance.qll +++ b/cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/SignatureAlgorithmInstance.qll @@ -16,15 +16,15 @@ private predicate knownOpenSslConstantToSignatureFamilyType( exists(string name | name = e.(KnownOpenSslAlgorithmExpr).getNormalizedName() and ( - name.matches("RSA%") and type = KeyOpAlg::TAsymmetricCipher(KeyOpAlg::RSA()) + name.startsWith("RSA") and type = KeyOpAlg::TAsymmetricCipher(KeyOpAlg::RSA()) or - name.matches("DSA%") and type = KeyOpAlg::TSignature(KeyOpAlg::DSA()) + name.startsWith("DSA") and type = KeyOpAlg::TSignature(KeyOpAlg::DSA()) or - name.matches("ECDSA%") and type = KeyOpAlg::TSignature(KeyOpAlg::ECDSA()) + name.startsWith("ECDSA") and type = KeyOpAlg::TSignature(KeyOpAlg::ECDSA()) or - name.matches("ED25519%") and type = KeyOpAlg::TSignature(KeyOpAlg::EDDSA()) + name.startsWith("ED25519") and type = KeyOpAlg::TSignature(KeyOpAlg::EDDSA()) or - name.matches("ED448%") and type = KeyOpAlg::TSignature(KeyOpAlg::EDDSA()) + name.startsWith("ED448") and type = KeyOpAlg::TSignature(KeyOpAlg::EDDSA()) ) ) } diff --git a/cpp/ql/lib/experimental/quantum/OpenSSL/LibraryDetector.qll b/cpp/ql/lib/experimental/quantum/OpenSSL/LibraryDetector.qll index c7e56fab1be0..10dfb34415a2 100644 --- a/cpp/ql/lib/experimental/quantum/OpenSSL/LibraryDetector.qll +++ b/cpp/ql/lib/experimental/quantum/OpenSSL/LibraryDetector.qll @@ -4,4 +4,4 @@ predicate isPossibleOpenSslFunction(Function f) { isPossibleOpenSslLocation(f.getADeclarationLocation()) } -predicate isPossibleOpenSslLocation(Location l) { l.toString().toLowerCase().matches("%openssl%") } +predicate isPossibleOpenSslLocation(Location l) { l.toString().toLowerCase().contains("openssl") } diff --git a/cpp/ql/lib/experimental/quantum/OpenSSL/Operations/CipherOperation.qll b/cpp/ql/lib/experimental/quantum/OpenSSL/Operations/CipherOperation.qll index 13d6a4ae4574..6d1e0cb4aae3 100644 --- a/cpp/ql/lib/experimental/quantum/OpenSSL/Operations/CipherOperation.qll +++ b/cpp/ql/lib/experimental/quantum/OpenSSL/Operations/CipherOperation.qll @@ -100,7 +100,7 @@ class EvpCipherEXInitCall extends EvpEXInitializer { or // NOTE: for EncryptInit and DecryptInit there is no subtype arg // the subtype is determined automatically by the initializer based on the operation name - this.getTarget().getName().toLowerCase().matches("%cipherinit%") and + this.getTarget().getName().toLowerCase().contains("cipherinit") and result.asExpr() = this.getArgument(5) and type = KeyOperationSubtypeIO() } @@ -117,7 +117,7 @@ class Evp_Cipher_EX2_or_Simple_Init_Call extends EvpEX2Initializer { override DataFlow::Node getInput(IOType type) { result = super.getInput(type) or - this.getTarget().getName().toLowerCase().matches("%cipherinit%") and + this.getTarget().getName().toLowerCase().contains("cipherinit") and // the key op subtype is an int, use asExpr result.asExpr() = this.getArgument(4) and type = KeyOperationSubtypeIO() @@ -282,12 +282,12 @@ class OpenSslCipherOperationInstance extends Crypto::KeyOperationInstance instan override Crypto::KeyOperationSubtype getKeyOperationSubtype() { result instanceof Crypto::TEncryptMode and - super.getTarget().getName().toLowerCase().matches("%encrypt%") + super.getTarget().getName().toLowerCase().contains("encrypt") or result instanceof Crypto::TDecryptMode and - super.getTarget().getName().toLowerCase().matches("%decrypt%") + super.getTarget().getName().toLowerCase().contains("decrypt") or - super.getTarget().getName().toLowerCase().matches("%cipher%") and + super.getTarget().getName().toLowerCase().contains("cipher") and resolveKeyOperationSubTypeOperationStep(super .getDominatingInitializersToStep(KeyOperationSubtypeIO())) = result } diff --git a/cpp/ql/lib/experimental/quantum/OpenSSL/Operations/OpenSSLOperationBase.qll b/cpp/ql/lib/experimental/quantum/OpenSSL/Operations/OpenSSLOperationBase.qll index 5c0aa98dd0c5..ef00216ec0f2 100644 --- a/cpp/ql/lib/experimental/quantum/OpenSSL/Operations/OpenSSLOperationBase.qll +++ b/cpp/ql/lib/experimental/quantum/OpenSSL/Operations/OpenSSLOperationBase.qll @@ -379,7 +379,7 @@ private class CtxCopyOutArgCall extends CtxPassThroughCall { DataFlow::Node n2; CtxCopyOutArgCall() { - this.getTarget().getName().toLowerCase().matches("%copy%") and + this.getTarget().getName().toLowerCase().contains("copy") and n1.asIndirectExpr() = this.getAnArgument() and n1.getType() instanceof CtxType and n2.asDefiningArgument() = this.getAnArgument() and @@ -400,7 +400,7 @@ private class CtxCopyReturnCall extends CtxPassThroughCall, CtxPointerExpr { DataFlow::Node n1; CtxCopyReturnCall() { - this.getTarget().getName().toLowerCase().matches("%dup%") and + this.getTarget().getName().toLowerCase().contains("dup") and n1.asIndirectExpr() = this.getAnArgument() and n1.getType() instanceof CtxType } diff --git a/cpp/ql/lib/experimental/quantum/OpenSSL/Operations/SignatureOperation.qll b/cpp/ql/lib/experimental/quantum/OpenSSL/Operations/SignatureOperation.qll index f5e9ad354ada..eca3c73ce617 100644 --- a/cpp/ql/lib/experimental/quantum/OpenSSL/Operations/SignatureOperation.qll +++ b/cpp/ql/lib/experimental/quantum/OpenSSL/Operations/SignatureOperation.qll @@ -650,10 +650,10 @@ class OpenSslSignatureOperationInstance extends Crypto::SignatureOperationInstan */ override Crypto::KeyOperationSubtype getKeyOperationSubtype() { // NOTE: if this KeyOperationSubtype does not match initialization call's KeyOperationSubtype then we found a bug - if super.getTarget().getName().toLowerCase().matches("%sign%") + if super.getTarget().getName().toLowerCase().contains("sign") then result instanceof Crypto::TSignMode else - if super.getTarget().getName().toLowerCase().matches("%verify%") + if super.getTarget().getName().toLowerCase().contains("verify") then result instanceof Crypto::TVerifyMode else result instanceof Crypto::TUnknownKeyOperationMode } diff --git a/cpp/ql/lib/semmle/code/cpp/Comments.qll b/cpp/ql/lib/semmle/code/cpp/Comments.qll index 7574f0ff32c0..8a5d9338471b 100644 --- a/cpp/ql/lib/semmle/code/cpp/Comments.qll +++ b/cpp/ql/lib/semmle/code/cpp/Comments.qll @@ -40,7 +40,7 @@ class Comment extends Locatable, @comment { * A C style comment (one which starts with `/*`). */ class CStyleComment extends Comment { - CStyleComment() { this.getContents().matches("/*%") } + CStyleComment() { this.getContents().startsWith("/*") } } /** @@ -50,5 +50,5 @@ class CStyleComment extends Comment { * ``` */ class CppStyleComment extends Comment { - CppStyleComment() { this.getContents().matches("//%") } + CppStyleComment() { this.getContents().startsWith("//") } } diff --git a/cpp/ql/lib/semmle/code/cpp/ConfigurationTestFile.qll b/cpp/ql/lib/semmle/code/cpp/ConfigurationTestFile.qll index ae90caa0e637..7e59870e37b7 100644 --- a/cpp/ql/lib/semmle/code/cpp/ConfigurationTestFile.qll +++ b/cpp/ql/lib/semmle/code/cpp/ConfigurationTestFile.qll @@ -20,7 +20,7 @@ class CmakeTryCompileFile extends ConfigurationTestFile { folder = this.getParentContainer() and parent = folder.getParentContainer() | - folder.getBaseName().matches("TryCompile-%") and + folder.getBaseName().startsWith("TryCompile-") and parent.getBaseName() = "CMakeScratch" and parent.getParentContainer().getBaseName() = "CMakeFiles" ) @@ -37,7 +37,7 @@ class MesonPrivateTestFile extends ConfigurationTestFile { folder = this.getParentContainer() and parent = folder.getParentContainer() | - folder.getBaseName().matches("tmp%") and + folder.getBaseName().startsWith("tmp") and parent.getBaseName() = "meson-private" ) } diff --git a/cpp/ql/lib/semmle/code/cpp/UserType.qll b/cpp/ql/lib/semmle/code/cpp/UserType.qll index 878754657b79..e87216703b66 100644 --- a/cpp/ql/lib/semmle/code/cpp/UserType.qll +++ b/cpp/ql/lib/semmle/code/cpp/UserType.qll @@ -35,7 +35,7 @@ class UserType extends Type, Declaration, NameQualifyingElement, AccessHolder, @ override predicate hasName(string name) { usertypes(underlyingElement(this), name, _) } /** Holds if this type is anonymous. */ - predicate isAnonymous() { this.getName().matches("(unnamed%") } + predicate isAnonymous() { this.getName().startsWith("(unnamed") } override predicate hasSpecifier(string s) { Type.super.hasSpecifier(s) } diff --git a/cpp/ql/lib/semmle/code/cpp/commons/Assertions.qll b/cpp/ql/lib/semmle/code/cpp/commons/Assertions.qll index 9d466387fff6..5d39fe5b1dbc 100644 --- a/cpp/ql/lib/semmle/code/cpp/commons/Assertions.qll +++ b/cpp/ql/lib/semmle/code/cpp/commons/Assertions.qll @@ -17,7 +17,7 @@ abstract class Assertion extends Locatable { * expression which may terminate the program. */ class LibcAssert extends MacroInvocation, Assertion { - LibcAssert() { this.getMacro().getHead().matches("assert(%") } + LibcAssert() { this.getMacro().getHead().startsWith("assert(") } override Expr getAsserted() { exists(ConditionalExpr ce | this.getAGeneratedElement() = ce | result = ce.getCondition()) diff --git a/cpp/ql/lib/semmle/code/cpp/commons/Printf.qll b/cpp/ql/lib/semmle/code/cpp/commons/Printf.qll index dfda2f4796c5..a707fb8579b8 100644 --- a/cpp/ql/lib/semmle/code/cpp/commons/Printf.qll +++ b/cpp/ql/lib/semmle/code/cpp/commons/Printf.qll @@ -587,38 +587,38 @@ class FormatLiteral extends Literal instanceof StringLiteral { /** * Holds if the nth conversion specifier has alternate flag ("#"). */ - predicate hasAlternateFlag(int n) { this.getFlags(n).matches("%#%") } + predicate hasAlternateFlag(int n) { this.getFlags(n).contains("#") } /** * Holds if the nth conversion specifier has zero padding flag ("0"). */ - predicate isZeroPadded(int n) { this.getFlags(n).matches("%0%") and not this.isLeftAdjusted(n) } + predicate isZeroPadded(int n) { this.getFlags(n).contains("0") and not this.isLeftAdjusted(n) } /** * Holds if the nth conversion specifier has flag left adjustment flag * ("-"). Note that this overrides the zero padding flag. */ - predicate isLeftAdjusted(int n) { this.getFlags(n).matches("%-%") } + predicate isLeftAdjusted(int n) { this.getFlags(n).contains("-") } /** * Holds if the nth conversion specifier has the blank flag (" "). */ - predicate hasBlank(int n) { this.getFlags(n).matches("% %") } + predicate hasBlank(int n) { this.getFlags(n).contains(" ") } /** * Holds if the nth conversion specifier has the explicit sign flag ("+"). */ - predicate hasSign(int n) { this.getFlags(n).matches("%+%") } + predicate hasSign(int n) { this.getFlags(n).contains("+") } /** * Holds if the nth conversion specifier has the thousands grouping flag ("'"). */ - predicate hasThousandsGrouping(int n) { this.getFlags(n).matches("%'%") } + predicate hasThousandsGrouping(int n) { this.getFlags(n).contains("'") } /** * Holds if the nth conversion specifier has the alternative digits flag ("I"). */ - predicate hasAlternativeDigits(int n) { this.getFlags(n).matches("%I%") } + predicate hasAlternativeDigits(int n) { this.getFlags(n).contains("I") } /** * Gets the minimum field width of the nth conversion specifier diff --git a/cpp/ql/lib/semmle/code/cpp/commons/StructLikeClass.qll b/cpp/ql/lib/semmle/code/cpp/commons/StructLikeClass.qll index 48a91b75f976..8c3732093ff2 100644 --- a/cpp/ql/lib/semmle/code/cpp/commons/StructLikeClass.qll +++ b/cpp/ql/lib/semmle/code/cpp/commons/StructLikeClass.qll @@ -47,7 +47,7 @@ class StructLikeClass extends Class { predicate setter(MemberVariable v, MemberFunction f, Class c) { f.getDeclaringType() = c and v.getDeclaringType() = c and - f.getName().matches("set%") and + f.getName().startsWith("set") and v.getAnAssignedValue().getEnclosingFunction() = f and forall(MemberVariable v2 | v2.getAnAssignedValue().getEnclosingFunction() = f | v2 = v) and f.getNumberOfParameters() = 1 and @@ -61,7 +61,7 @@ predicate setter(MemberVariable v, MemberFunction f, Class c) { predicate getter(MemberVariable v, MemberFunction f, Class c) { f.getDeclaringType() = c and v.getDeclaringType() = c and - f.getName().matches("get%") and + f.getName().startsWith("get") and v.getAnAccess().getEnclosingFunction() = f and forall(MemberVariable v2 | v2.getAnAccess().getEnclosingFunction() = f | v2 = v) and f.getNumberOfParameters() = 0 and diff --git a/cpp/ql/lib/semmle/code/cpp/dataflow/ExternalFlow.qll b/cpp/ql/lib/semmle/code/cpp/dataflow/ExternalFlow.qll index 008a7c51c8e7..38068da4822f 100644 --- a/cpp/ql/lib/semmle/code/cpp/dataflow/ExternalFlow.qll +++ b/cpp/ql/lib/semmle/code/cpp/dataflow/ExternalFlow.qll @@ -263,7 +263,7 @@ module ModelValidation { type = name + "<" + any(string s) | summaryModel(namespace, type, _, name, _, _, _, output, _, _, _) and - output.matches("ReturnValue%") and + output.startsWith("ReturnValue") and result = "Constructor model for " + namespace + "." + type + " should use `Argument[this]` in the output, not `ReturnValue`." diff --git a/cpp/ql/lib/semmle/code/cpp/models/implementations/Allocation.qll b/cpp/ql/lib/semmle/code/cpp/models/implementations/Allocation.qll index df6d94917299..d7675fc2bd8d 100644 --- a/cpp/ql/lib/semmle/code/cpp/models/implementations/Allocation.qll +++ b/cpp/ql/lib/semmle/code/cpp/models/implementations/Allocation.qll @@ -375,7 +375,7 @@ private module HeuristicAllocation { override int getSizeArg() { result = sizeArg } override int getReallocPtrArg() { - Function.super.getName().matches("%realloc%") and + Function.super.getName().contains("realloc") and result = unique( | | getAPointerParameter(this)) } diff --git a/cpp/ql/lib/semmle/code/cpp/rangeanalysis/SimpleRangeAnalysis.qll b/cpp/ql/lib/semmle/code/cpp/rangeanalysis/SimpleRangeAnalysis.qll index df04aa4db5a4..ec9d6d06ab0a 100644 --- a/cpp/ql/lib/semmle/code/cpp/rangeanalysis/SimpleRangeAnalysis.qll +++ b/cpp/ql/lib/semmle/code/cpp/rangeanalysis/SimpleRangeAnalysis.qll @@ -2212,7 +2212,7 @@ private module Debug { Locatable getRelevantLocatable() { exists(string filepath, int startline | result.getLocation().hasLocationInfo(filepath, startline, _, _, _) and - filepath.matches("%/test.c") and + filepath.endsWith("/test.c") and startline = [621 .. 639] ) } diff --git a/cpp/ql/lib/semmle/code/cpp/security/boostorg/asio/protocols.qll b/cpp/ql/lib/semmle/code/cpp/security/boostorg/asio/protocols.qll index 984bd874ae51..65b1612c4659 100644 --- a/cpp/ql/lib/semmle/code/cpp/security/boostorg/asio/protocols.qll +++ b/cpp/ql/lib/semmle/code/cpp/security/boostorg/asio/protocols.qll @@ -8,7 +8,7 @@ module BoostorgAsio { class SslContextMethod extends Enum { SslContextMethod() { this.getName().toString() = "method" and - this.getQualifiedName().toString().matches("boost::asio::ssl::context%") + this.getQualifiedName().toString().startsWith("boost::asio::ssl::context") } /** @@ -196,7 +196,7 @@ module BoostorgAsio { */ ConstructorCall getAConstructorCall() { this.getAConstructor().getACallToThisFunction() = result and - not result.getLocation().getFile().toString().matches("%/boost/asio/%") and + not result.getLocation().getFile().toString().contains("/boost/asio/") and result.fromSource() } @@ -401,7 +401,7 @@ module BoostorgAsio { predicate isSource(DataFlow::Node source) { exists(Expr e | e = source.asExpr() | e.fromSource() and - not e.getLocation().getFile().toString().matches("%/boost/asio/%") + not e.getLocation().getFile().toString().contains("/boost/asio/") ) } } @@ -415,7 +415,7 @@ module BoostorgAsio { predicate isSource(DataFlow::Node source) { exists(Expr e | e = source.asExpr() | e.fromSource() and - not e.getLocation().getFile().toString().matches("%/boost/asio/%") and + not e.getLocation().getFile().toString().contains("/boost/asio/") and isExprBannedBoostProtocol(e) ) } @@ -431,7 +431,7 @@ module BoostorgAsio { predicate isSource(DataFlow::Node source) { exists(Expr e | e = source.asExpr() | e.fromSource() and - not e.getLocation().getFile().toString().matches("%/boost/asio/%") and + not e.getLocation().getFile().toString().contains("/boost/asio/") and isExprTls12BoostProtocol(e) ) } @@ -446,7 +446,7 @@ module BoostorgAsio { predicate isSource(DataFlow::Node source) { exists(Expr e | e = source.asExpr() | e.fromSource() and - not e.getLocation().getFile().toString().matches("%/boost/asio/%") and + not e.getLocation().getFile().toString().contains("/boost/asio/") and isExprTls13BoostProtocol(e) ) } @@ -461,7 +461,7 @@ module BoostorgAsio { predicate isSource(DataFlow::Node source) { exists(Expr e | e = source.asExpr() | e.fromSource() and - not e.getLocation().getFile().toString().matches("%/boost/asio/%") and + not e.getLocation().getFile().toString().contains("/boost/asio/") and isExprTlsBoostProtocol(e) ) } @@ -500,7 +500,7 @@ module BoostorgAsio { predicate isSource(DataFlow::Node source) { exists(Expr e | e = source.asExpr() | e.fromSource() and - not e.getLocation().getFile().toString().matches("%/boost/asio/%") + not e.getLocation().getFile().toString().contains("/boost/asio/") ) } @@ -508,7 +508,7 @@ module BoostorgAsio { exists(SslSetOptionsFunction f, FunctionCall call | sink.asExpr() = call.getArgument(0) and f.getACallToThisFunction() = call and - not sink.getLocation().getFile().toString().matches("%/boost/asio/%") + not sink.getLocation().getFile().toString().contains("/boost/asio/") ) } } diff --git a/cpp/ql/src/Best Practices/Exceptions/AccidentalRethrow.ql b/cpp/ql/src/Best Practices/Exceptions/AccidentalRethrow.ql index be5a04fedb96..05b3b89c4892 100644 --- a/cpp/ql/src/Best Practices/Exceptions/AccidentalRethrow.ql +++ b/cpp/ql/src/Best Practices/Exceptions/AccidentalRethrow.ql @@ -19,7 +19,7 @@ predicate isInCatch(Expr e) { or exists(Function f | f = e.getEnclosingFunction() | isInCatch(f.getACallToThisFunction()) or // as will dynamically enclosing catch blocks. - f.getName().toLowerCase().matches("%exception%") // We assume that rethrows are intended when the function is called *exception*. + f.getName().toLowerCase().contains("exception") // We assume that rethrows are intended when the function is called *exception*. ) } diff --git a/cpp/ql/src/Best Practices/Exceptions/LeakyCatch.ql b/cpp/ql/src/Best Practices/Exceptions/LeakyCatch.ql index 97ccbdc63e07..ed744aff69e2 100644 --- a/cpp/ql/src/Best Practices/Exceptions/LeakyCatch.ql +++ b/cpp/ql/src/Best Practices/Exceptions/LeakyCatch.ql @@ -30,7 +30,7 @@ predicate deletesException(Expr expr, Parameter exception) { exists(FunctionCall fc | fc = expr | // Calling a delete function on the exception will free it (MFC's CException has a Delete function). fc.getQualifier() = exception.getAnAccess() and - fc.getTarget().getName().toLowerCase().matches("%delete%") + fc.getTarget().getName().toLowerCase().contains("delete") or // Passing the exception to a function might free it. fc.getAnArgument() = exception.getAnAccess() diff --git a/cpp/ql/src/Best Practices/Unused Entities/UnusedIncludes.ql b/cpp/ql/src/Best Practices/Unused Entities/UnusedIncludes.ql index 288e4e5328b8..1ea66d2989d9 100644 --- a/cpp/ql/src/Best Practices/Unused Entities/UnusedIncludes.ql +++ b/cpp/ql/src/Best Practices/Unused Entities/UnusedIncludes.ql @@ -24,6 +24,6 @@ where unneeded = include.getIncludedFile() and not unneeded.getAnIncludedFile*() = source.getMetrics().getAFileDependency() and unneeded.fromSource() and - not unneeded.getBaseName().matches("%Debug.h") + not unneeded.getBaseName().endsWith("Debug.h") select include, "Redundant include, this file does not require $@.", unneeded, unneeded.getAbsolutePath() diff --git a/cpp/ql/src/Critical/ReturnValueIgnored.ql b/cpp/ql/src/Critical/ReturnValueIgnored.ql index b4a4a0440689..353d4ef0de51 100644 --- a/cpp/ql/src/Critical/ReturnValueIgnored.ql +++ b/cpp/ql/src/Critical/ReturnValueIgnored.ql @@ -40,5 +40,5 @@ where unused(unused) and not exists(Options opts | opts.okToIgnoreReturnValue(unused)) and (important(unused.getTarget(), message) or dubious(unused.getTarget(), message)) and - not unused.getTarget().getName().matches("operator%") // exclude user defined operators + not unused.getTarget().getName().startsWith("operator") // exclude user defined operators select unused, "Result of call to " + unused.getTarget().getName() + " is ignored; " + message diff --git a/cpp/ql/src/Documentation/CommentedOutCode.qll b/cpp/ql/src/Documentation/CommentedOutCode.qll index b3bc8bad86b6..bedac051e3b0 100644 --- a/cpp/ql/src/Documentation/CommentedOutCode.qll +++ b/cpp/ql/src/Documentation/CommentedOutCode.qll @@ -178,7 +178,7 @@ class CommentBlock extends Comment { // If a C-style comment starts each line with a *, then it's // probably documentation rather than code. this instanceof CStyleComment and - forex(int i | i in [1 .. this.numLines() - 1] | this.getLine(i).trim().matches("*%")) + forex(int i | i in [1 .. this.numLines() - 1] | this.getLine(i).trim().startsWith("*")) } /** diff --git a/cpp/ql/src/JPL_C/LOC-2/Rule 03/ExitNonterminatingLoop.ql b/cpp/ql/src/JPL_C/LOC-2/Rule 03/ExitNonterminatingLoop.ql index 9473998e6ee5..ae4a615e6c40 100644 --- a/cpp/ql/src/JPL_C/LOC-2/Rule 03/ExitNonterminatingLoop.ql +++ b/cpp/ql/src/JPL_C/LOC-2/Rule 03/ExitNonterminatingLoop.ql @@ -11,7 +11,7 @@ import cpp predicate markedAsNonterminating(Loop l) { - exists(Comment c | c.getContents().matches("%@non-terminating@%") | c.getCommentedElement() = l) + exists(Comment c | c.getContents().contains("@non-terminating@") | c.getCommentedElement() = l) } Stmt exitFrom(Loop l) { diff --git a/cpp/ql/src/JPL_C/LOC-2/Rule 03/LoopBounds.ql b/cpp/ql/src/JPL_C/LOC-2/Rule 03/LoopBounds.ql index f3e05bdc151c..da0d3497e8db 100644 --- a/cpp/ql/src/JPL_C/LOC-2/Rule 03/LoopBounds.ql +++ b/cpp/ql/src/JPL_C/LOC-2/Rule 03/LoopBounds.ql @@ -115,7 +115,7 @@ predicate hasSafeBound(Loop l) { } predicate markedAsNonterminating(Loop l) { - exists(Comment c | c.getContents().matches("%@non-terminating@%") | c.getCommentedElement() = l) + exists(Comment c | c.getContents().contains("@non-terminating@") | c.getCommentedElement() = l) } from Loop loop, string msg diff --git a/cpp/ql/src/JPL_C/LOC-2/Rule 05/HeapMemory.ql b/cpp/ql/src/JPL_C/LOC-2/Rule 05/HeapMemory.ql index 30324d8840da..80a744ee9bda 100644 --- a/cpp/ql/src/JPL_C/LOC-2/Rule 05/HeapMemory.ql +++ b/cpp/ql/src/JPL_C/LOC-2/Rule 05/HeapMemory.ql @@ -15,7 +15,7 @@ class Initialization extends Function { // TODO: This could be refined to match precisely what functions count // as "initialization", and are, hence, allowed to perform dynamic // memory allocation. - this.getName().toLowerCase().matches("init%") or + this.getName().toLowerCase().startsWith("init") or this.getName().toLowerCase().matches("%\\_init") } } diff --git a/cpp/ql/src/JPL_C/LOC-4/Rule 20/PreprocessorUseUndisciplined.ql b/cpp/ql/src/JPL_C/LOC-4/Rule 20/PreprocessorUseUndisciplined.ql index 21983ebda645..0b7ce2ad6d98 100644 --- a/cpp/ql/src/JPL_C/LOC-4/Rule 20/PreprocessorUseUndisciplined.ql +++ b/cpp/ql/src/JPL_C/LOC-4/Rule 20/PreprocessorUseUndisciplined.ql @@ -13,9 +13,9 @@ import cpp from Macro m, string msg where - m.getHead().matches("%...%") and + m.getHead().contains("...") and msg = "The macro " + m.getHead() + " is variadic, and hence not allowed." or - m.getBody().matches("%##%") and + m.getBody().contains("##") and msg = "The macro " + m.getHead() + " uses token pasting and is not allowed." select m, msg diff --git a/cpp/ql/src/Likely Bugs/InconsistentCallOnResult.ql b/cpp/ql/src/Likely Bugs/InconsistentCallOnResult.ql index 719a4cf48fa8..ce74770aeba2 100644 --- a/cpp/ql/src/Likely Bugs/InconsistentCallOnResult.ql +++ b/cpp/ql/src/Likely Bugs/InconsistentCallOnResult.ql @@ -16,8 +16,8 @@ import cpp predicate exclude(Function f) { exists(string name | name = f.getName() | - name.toLowerCase().matches("get%") or - name.matches("strto%") + name.toLowerCase().startsWith("get") or + name.startsWith("strto") ) } @@ -67,7 +67,7 @@ where not checkedFunctionCall(unchecked, operation) and functionStats(f, operation, _, _, percent) and percent >= 70 and - unchecked.getFile().getAbsolutePath().matches("%fbcode%") and + unchecked.getFile().getAbsolutePath().contains("fbcode") and not unchecked.getFile().getAbsolutePath().matches("%\\_build%") select unchecked, "After " + percent.toString() + "% of calls to " + f.getName() + " there is a call to " + diff --git a/cpp/ql/src/Likely Bugs/InconsistentCheckReturnNull.ql b/cpp/ql/src/Likely Bugs/InconsistentCheckReturnNull.ql index 63dc3cd460a5..60374ae0eb33 100644 --- a/cpp/ql/src/Likely Bugs/InconsistentCheckReturnNull.ql +++ b/cpp/ql/src/Likely Bugs/InconsistentCheckReturnNull.ql @@ -17,7 +17,7 @@ import cpp -predicate assertMacro(Macro m) { m.getHead().toLowerCase().matches("%assert%") } +predicate assertMacro(Macro m) { m.getHead().toLowerCase().contains("assert") } predicate assertInvocation(File f, int line) { exists(MacroInvocation i, Location l | assertMacro(i.getMacro()) and l = i.getLocation() | diff --git a/cpp/ql/src/Likely Bugs/Leap Year/LeapYear.qll b/cpp/ql/src/Likely Bugs/Leap Year/LeapYear.qll index 99981873d26d..f1f20b890a2f 100644 --- a/cpp/ql/src/Likely Bugs/Leap Year/LeapYear.qll +++ b/cpp/ql/src/Likely Bugs/Leap Year/LeapYear.qll @@ -329,7 +329,7 @@ class TimeConversionFunction extends Function { ] or // Matches all forms of GetDateFormat, e.g. GetDateFormatA/W/Ex - this.getName().matches("GetDateFormat%") + this.getName().startsWith("GetDateFormat") ) or autoLeapYearCorrecting = true and diff --git a/cpp/ql/src/Likely Bugs/Leap Year/UncheckedLeapYearAfterYearModification.ql b/cpp/ql/src/Likely Bugs/Leap Year/UncheckedLeapYearAfterYearModification.ql index 4bc58eb08540..25b6ce5ad4eb 100644 --- a/cpp/ql/src/Likely Bugs/Leap Year/UncheckedLeapYearAfterYearModification.ql +++ b/cpp/ql/src/Likely Bugs/Leap Year/UncheckedLeapYearAfterYearModification.ql @@ -38,13 +38,13 @@ class IgnorableFunction extends Function { this.getName() = "adjacentDay" or // Windows API function that does timezone conversions - this.getName().matches("%SystemTimeToTzSpecificLocalTime%") + this.getName().contains("SystemTimeToTzSpecificLocalTime") or // Windows APIs that do time conversions this.getName().matches("%localtime%\\_s%") or // Windows APIs that do time conversions - this.getName().matches("%SpecificLocalTimeToSystemTime%") + this.getName().contains("SpecificLocalTimeToSystemTime") or // postgres function for diffing timestamps, date for leap year // is not applicable. @@ -60,17 +60,17 @@ class IgnorableFunction extends Function { or // Indication of a calendar not applicable to // gregorian leap year, e.g., Hijri, Persian, Hebrew - this.getName().toLowerCase().matches("%hijri%") + this.getName().toLowerCase().contains("hijri") or - this.getFile().getBaseName().toLowerCase().matches("%hijri%") + this.getFile().getBaseName().toLowerCase().contains("hijri") or - this.getName().toLowerCase().matches("%persian%") + this.getName().toLowerCase().contains("persian") or - this.getFile().getBaseName().toLowerCase().matches("%persian%") + this.getFile().getBaseName().toLowerCase().contains("persian") or - this.getName().toLowerCase().matches("%hebrew%") + this.getName().toLowerCase().contains("hebrew") or - this.getFile().getBaseName().toLowerCase().matches("%hebrew%") + this.getFile().getBaseName().toLowerCase().contains("hebrew") or // misc. from string/char converters heuristic this.getName() @@ -268,7 +268,7 @@ class IgnorablePointerOrCharArithmetic extends IgnorableOperation { // Operations on calls to functions named like "strlen", "wcslen", etc // NOTE: workaround for cases where the wchar_t type is not a char, but an unsigned short // unclear if there is a best way to filter cases like these out based on type info. - op.(Call).getTarget().getName().matches("%len%") + op.(Call).getTarget().getName().contains("len") ) or exists(AssignArithmeticOperation a | a.getRValue() = this | @@ -283,7 +283,7 @@ class IgnorablePointerOrCharArithmetic extends IgnorableOperation { or // Operations on calls to functions named like "strlen", "wcslen", etc // for example `strlen(foo) + bar` - this.(BinaryArithmeticOperation).getAnOperand().(Call).getTarget().getName().matches("%len%") + this.(BinaryArithmeticOperation).getAnOperand().(Call).getTarget().getName().contains("len") ) } } @@ -347,7 +347,7 @@ module OperationToYearAssignmentConfig0 implements DataFlow::ConfigSig { n.getType().getUnspecifiedType() instanceof CharType or // If a type resembles "string" ignore flow (likely string conversion, currently ignored) - n.getType().getUnspecifiedType().stripType().getName().toLowerCase().matches("%string%") + n.getType().getUnspecifiedType().stripType().getName().toLowerCase().contains("string") or n.asExpr() instanceof IgnorableOperation or diff --git a/cpp/ql/src/Metrics/Files/ConditionalSegmentConditions.ql b/cpp/ql/src/Metrics/Files/ConditionalSegmentConditions.ql index ea2f6be5cb69..b0dcfec10d22 100644 --- a/cpp/ql/src/Metrics/Files/ConditionalSegmentConditions.ql +++ b/cpp/ql/src/Metrics/Files/ConditionalSegmentConditions.ql @@ -20,9 +20,9 @@ predicate preprocessorOpenCondition(PreprocessorDirective d) { } predicate headerGuard(PreprocessorIfndef notdef) { - notdef.getHead().regexpMatch(".*_H_.*") + notdef.getHead().contains("_H_") or - notdef.getHead().regexpMatch(".*_H") + notdef.getHead().endsWith("_H") } from File f diff --git a/cpp/ql/src/Metrics/Files/FTodoComments.ql b/cpp/ql/src/Metrics/Files/FTodoComments.ql index ef92f9f4796d..dc8e33a40f17 100644 --- a/cpp/ql/src/Metrics/Files/FTodoComments.ql +++ b/cpp/ql/src/Metrics/Files/FTodoComments.ql @@ -19,8 +19,8 @@ where count(Comment c | c.getFile() = f and ( - c.getContents().matches("%TODO%") or - c.getContents().matches("%FIXME%") + c.getContents().contains("TODO") or + c.getContents().contains("FIXME") ) ) select f, n order by n diff --git a/cpp/ql/src/Power of 10/Rule 3/DynamicAllocAfterInit.ql b/cpp/ql/src/Power of 10/Rule 3/DynamicAllocAfterInit.ql index f44ae6e3a7b8..3801ef84abf6 100644 --- a/cpp/ql/src/Power of 10/Rule 3/DynamicAllocAfterInit.ql +++ b/cpp/ql/src/Power of 10/Rule 3/DynamicAllocAfterInit.ql @@ -15,7 +15,7 @@ class Initialization extends Function { // Adapt this query to your codebase by changing this predicate to match // precisely what functions count as "initialization", and are, hence, // allowed to perform dynamic memory allocation. - this.getName().toLowerCase().matches("init%") or + this.getName().toLowerCase().startsWith("init") or this.getName().matches("%\\_init") } } diff --git a/cpp/ql/src/Power of 10/Rule 4/FunctionTooLong.ql b/cpp/ql/src/Power of 10/Rule 4/FunctionTooLong.ql index db4fc36c45ad..183e1472be92 100644 --- a/cpp/ql/src/Power of 10/Rule 4/FunctionTooLong.ql +++ b/cpp/ql/src/Power of 10/Rule 4/FunctionTooLong.ql @@ -14,7 +14,7 @@ import cpp class MacroFunctionCall extends MacroInvocation { MacroFunctionCall() { not exists(this.getParentInvocation()) and - this.getMacro().getHead().matches("%(%") + this.getMacro().getHead().contains("(") } FunctionDeclarationEntry getFunction() { diff --git a/cpp/ql/src/Power of 10/Rule 5/AssertionDensity.ql b/cpp/ql/src/Power of 10/Rule 5/AssertionDensity.ql index ff0823461472..4a4ce23a7c44 100644 --- a/cpp/ql/src/Power of 10/Rule 5/AssertionDensity.ql +++ b/cpp/ql/src/Power of 10/Rule 5/AssertionDensity.ql @@ -14,7 +14,7 @@ import semmle.code.cpp.commons.Assertions class MacroFunctionCall extends MacroInvocation { MacroFunctionCall() { not exists(this.getParentInvocation()) and - this.getMacro().getHead().matches("%(%") + this.getMacro().getHead().contains("(") } FunctionDeclarationEntry getFunction() { diff --git a/cpp/ql/src/Power of 10/Rule 8/UndisciplinedMacro.ql b/cpp/ql/src/Power of 10/Rule 8/UndisciplinedMacro.ql index 6874c4a87fb8..5965fe475b84 100644 --- a/cpp/ql/src/Power of 10/Rule 8/UndisciplinedMacro.ql +++ b/cpp/ql/src/Power of 10/Rule 8/UndisciplinedMacro.ql @@ -13,9 +13,9 @@ import cpp from Macro m, string msg where - m.getHead().matches("%...%") and + m.getHead().contains("...") and msg = "The macro " + m.getHead() + " is variadic, and hence not allowed." or - m.getBody().matches("%##%") and + m.getBody().contains("##") and msg = "The macro " + m.getHead() + " uses token pasting and is not allowed." select m, msg diff --git a/cpp/ql/src/Security/CWE/CWE-022/TaintedPath.ql b/cpp/ql/src/Security/CWE/CWE-022/TaintedPath.ql index 1a15f6c3a152..33f13b189f11 100644 --- a/cpp/ql/src/Security/CWE/CWE-022/TaintedPath.ql +++ b/cpp/ql/src/Security/CWE/CWE-022/TaintedPath.ql @@ -30,7 +30,7 @@ class FileFunction extends FunctionWithWrappers { nme = ["fopen", "_fopen", "_wfopen", "open", "_open", "_wopen"] or // create file function on windows - nme.matches("CreateFile%") + nme.startsWith("CreateFile") ) or this.hasQualifiedName("std", "fopen") diff --git a/cpp/ql/src/Security/CWE/CWE-313/CleartextSqliteDatabase.ql b/cpp/ql/src/Security/CWE/CWE-313/CleartextSqliteDatabase.ql index 7cd146e2cace..253aaf3f1d67 100644 --- a/cpp/ql/src/Security/CWE/CWE-313/CleartextSqliteDatabase.ql +++ b/cpp/ql/src/Security/CWE/CWE-313/CleartextSqliteDatabase.ql @@ -67,7 +67,7 @@ class SqliteFunctionBindCall extends SqliteFunctionCall { } predicate sqlite_encryption_used() { - any(StringLiteral l).getValue().toLowerCase().matches("pragma key%") or + any(StringLiteral l).getValue().toLowerCase().startsWith("pragma key") or any(StringLiteral l).getValue().toLowerCase().matches("%attach%database%key%") or any(FunctionCall fc).getTarget().getName().matches("sqlite%\\_key\\_%") } diff --git a/cpp/ql/src/Security/CWE/CWE-327/OpenSslHeartbleed.ql b/cpp/ql/src/Security/CWE/CWE-327/OpenSslHeartbleed.ql index 38067ae200c2..28f2ba361453 100644 --- a/cpp/ql/src/Security/CWE/CWE-327/OpenSslHeartbleed.ql +++ b/cpp/ql/src/Security/CWE/CWE-327/OpenSslHeartbleed.ql @@ -53,7 +53,7 @@ predicate varPointsInto(Variable tainted, DataVariable src) { from FunctionCall fc, Struct ssl3_record_st, Field data, Field length where - fc.getTarget().getName().matches("%memcpy%") and + fc.getTarget().getName().contains("memcpy") and ssl3_record_st.hasName("ssl3_record_st") and data = ssl3_record_st.getAField() and data.hasName("data") and diff --git a/cpp/ql/src/Security/CWE/CWE-704/WcharCharConversion.ql b/cpp/ql/src/Security/CWE/CWE-704/WcharCharConversion.ql index 6fc91c1d6699..89c72a5a1d35 100644 --- a/cpp/ql/src/Security/CWE/CWE-704/WcharCharConversion.ql +++ b/cpp/ql/src/Security/CWE/CWE-704/WcharCharConversion.ql @@ -40,7 +40,7 @@ class UnlikelyToBeAStringType extends Type { exists(Type targ | getABaseType(this) = targ | // NOTE: not using CharType isUnsigned, but rather look for any explicitly declared unsigned // char types. Assuming these are used for buffers, not strings. - targ.(CharType).getName().toLowerCase().matches("unsigned%") or + targ.(CharType).getName().toLowerCase().startsWith("unsigned") or targ.getName().toLowerCase().matches(["uint8_t", "%byte%"]) ) } @@ -64,7 +64,7 @@ class UnicodeMacroDependentWidthType extends Type { } class UnicodeMacro extends Macro { - UnicodeMacro() { this.getName().toLowerCase().matches("%unicode%") } + UnicodeMacro() { this.getName().toLowerCase().contains("unicode") } } class UnicodeMacroInvocation extends MacroInvocation { diff --git a/cpp/ql/src/experimental/Security/CWE/CWE-125/DangerousWorksWithMultibyteOrWideCharacters.ql b/cpp/ql/src/experimental/Security/CWE/CWE-125/DangerousWorksWithMultibyteOrWideCharacters.ql index c562e28326bc..f5c36c652a54 100644 --- a/cpp/ql/src/experimental/Security/CWE/CWE-125/DangerousWorksWithMultibyteOrWideCharacters.ql +++ b/cpp/ql/src/experimental/Security/CWE/CWE-125/DangerousWorksWithMultibyteOrWideCharacters.ql @@ -134,9 +134,9 @@ predicate findUseMultibyteCharacter(Expr exp, string msg) { exists(FunctionCall mbFunction | ( mbFunction.getTarget().getName().matches("_mbs%") or - mbFunction.getTarget().getName().matches("mbs%") or + mbFunction.getTarget().getName().startsWith("mbs") or mbFunction.getTarget().getName().matches("_mbc%") or - mbFunction.getTarget().getName().matches("mbc%") + mbFunction.getTarget().getName().startsWith("mbc") ) and mbFunction.getAnArgument().(VariableAccess).getTarget().getADeclarationEntry().getType() = arrayType diff --git a/cpp/ql/src/experimental/Security/CWE/CWE-266/IncorrectPrivilegeAssignment.ql b/cpp/ql/src/experimental/Security/CWE/CWE-266/IncorrectPrivilegeAssignment.ql index 6bb6a48a9ebe..58a2f9c6bd36 100644 --- a/cpp/ql/src/experimental/Security/CWE/CWE-266/IncorrectPrivilegeAssignment.ql +++ b/cpp/ql/src/experimental/Security/CWE/CWE-266/IncorrectPrivilegeAssignment.ql @@ -54,8 +54,8 @@ where fctmp.getTarget().hasGlobalOrStdName("open") ) and ( - fctmp.getArgument(1).getValue().matches("%a%") or - fctmp.getArgument(1).getValue().matches("%w%") or + fctmp.getArgument(1).getValue().contains("a") or + fctmp.getArgument(1).getValue().contains("w") or // unfortunately cannot use numeric value here because // O_CREAT is defined differently on different OSes: // https://github.com/red/red/blob/92feb0c0d5f91e087ab35fface6906afbf99b603/runtime/definitions.reds#L477-L491 // this may introduce false negatives diff --git a/cpp/ql/src/experimental/Security/CWE/CWE-273/PrivilegeDroppingOutoforder.ql b/cpp/ql/src/experimental/Security/CWE/CWE-273/PrivilegeDroppingOutoforder.ql index 67464d4b37a5..085befe021fd 100644 --- a/cpp/ql/src/experimental/Security/CWE/CWE-273/PrivilegeDroppingOutoforder.ql +++ b/cpp/ql/src/experimental/Security/CWE/CWE-273/PrivilegeDroppingOutoforder.ql @@ -17,7 +17,7 @@ import cpp predicate argumentMayBeRoot(Expr e) { e.getValue() = "0" or - e.(VariableAccess).getTarget().getName().toLowerCase().matches("%root%") + e.(VariableAccess).getTarget().getName().toLowerCase().contains("root") } class SetuidLikeFunctionCall extends FunctionCall { diff --git a/cpp/ql/src/experimental/Security/CWE/CWE-416/UseAfterExpiredLifetime.ql b/cpp/ql/src/experimental/Security/CWE/CWE-416/UseAfterExpiredLifetime.ql index fec373ce5216..f2e0186eb524 100644 --- a/cpp/ql/src/experimental/Security/CWE/CWE-416/UseAfterExpiredLifetime.ql +++ b/cpp/ql/src/experimental/Security/CWE/CWE-416/UseAfterExpiredLifetime.ql @@ -115,7 +115,7 @@ class LifetimeOwnerType extends LifetimeIndirectionType { ["stack", "queue", "priority_queue", "optional", "variant", "any", "regex"]) or // Explicit annotation on the type - this.getAnAttribute().getName().matches("gsl::Owner%") + this.getAnAttribute().getName().startsWith("gsl::Owner") } } @@ -193,7 +193,7 @@ class LifetimeSharedOwnerType extends Type { this.(Class).hasQualifiedName("std", "shared_future") or // Explicit annotation on the type - this.getAnAttribute().getName().matches("gsl::SharedOwner%") + this.getAnAttribute().getName().startsWith("gsl::SharedOwner") } } @@ -258,7 +258,7 @@ class LifetimePointerType extends LifetimeIndirectionType { ) or // Explicit annotation on the type - this.getAnAttribute().getName().matches("gsl::Pointer%") + this.getAnAttribute().getName().startsWith("gsl::Pointer") } } diff --git a/cpp/ql/src/experimental/cryptography/example_alerts/WeakEncryption.ql b/cpp/ql/src/experimental/cryptography/example_alerts/WeakEncryption.ql index d8d5c4e4a566..22bfe0a07b35 100644 --- a/cpp/ql/src/experimental/cryptography/example_alerts/WeakEncryption.ql +++ b/cpp/ql/src/experimental/cryptography/example_alerts/WeakEncryption.ql @@ -25,7 +25,7 @@ where not alg instanceof Literal and resMsg = "Use of unrecognized symmetric encryption algorithm." ) else ( - not alg.getEncryptionName().matches("AES%") and + not alg.getEncryptionName().startsWith("AES") and resMsg = "Use of banned symmetric encryption algorithm: " + alg.getEncryptionName() + "." ) ) and diff --git a/cpp/ql/src/external/examples/filters/ExcludeGeneratedCode.ql b/cpp/ql/src/external/examples/filters/ExcludeGeneratedCode.ql index 44ef72735fc9..529c1379e710 100644 --- a/cpp/ql/src/external/examples/filters/ExcludeGeneratedCode.ql +++ b/cpp/ql/src/external/examples/filters/ExcludeGeneratedCode.ql @@ -10,7 +10,7 @@ import cpp import external.DefectFilter -predicate generatedFile(File f) { f.getAbsolutePath().matches("%generated%") } +predicate generatedFile(File f) { f.getAbsolutePath().contains("generated") } from DefectResult res where not generatedFile(res.getFile()) diff --git a/cpp/ql/src/jsf/4.05 Libraries/AV Rule 17.ql b/cpp/ql/src/jsf/4.05 Libraries/AV Rule 17.ql index 07f78f0b0279..84861ecd8cb0 100644 --- a/cpp/ql/src/jsf/4.05 Libraries/AV Rule 17.ql +++ b/cpp/ql/src/jsf/4.05 Libraries/AV Rule 17.ql @@ -17,5 +17,5 @@ where or errno.(Variable).hasName("errno") and use = errno.(Variable).getAnAccess() ) and - errno.getFile().getAbsolutePath().matches("%errno.h") + errno.getFile().getAbsolutePath().endsWith("errno.h") select use, "AV Rule 17: The error indicator errno shall not be used." diff --git a/cpp/ql/src/jsf/4.05 Libraries/AV Rule 18.ql b/cpp/ql/src/jsf/4.05 Libraries/AV Rule 18.ql index 09f3dfd6b173..53b84fbee0a7 100644 --- a/cpp/ql/src/jsf/4.05 Libraries/AV Rule 18.ql +++ b/cpp/ql/src/jsf/4.05 Libraries/AV Rule 18.ql @@ -13,6 +13,6 @@ import cpp from Macro offsetof where offsetof.getHead().matches("offsetof(%,%)") and - offsetof.getFile().getAbsolutePath().matches("%stddef.h") + offsetof.getFile().getAbsolutePath().endsWith("stddef.h") select offsetof.getAnInvocation(), "AV Rule 18: The macro offsetof, in library , shall not be used." diff --git a/cpp/ql/src/jsf/4.05 Libraries/AV Rule 19.ql b/cpp/ql/src/jsf/4.05 Libraries/AV Rule 19.ql index f22ef860126f..bab0ea3a2581 100644 --- a/cpp/ql/src/jsf/4.05 Libraries/AV Rule 19.ql +++ b/cpp/ql/src/jsf/4.05 Libraries/AV Rule 19.ql @@ -11,5 +11,5 @@ import cpp from Include incl -where incl.getIncludedFile().getAbsolutePath().matches("%locale.h") +where incl.getIncludedFile().getAbsolutePath().endsWith("locale.h") select incl, "AV Rule 19: and the setlocale function shall not be used." diff --git a/cpp/ql/src/jsf/4.05 Libraries/AV Rule 20.ql b/cpp/ql/src/jsf/4.05 Libraries/AV Rule 20.ql index 3fcfee2f55d6..d0074750e5fc 100644 --- a/cpp/ql/src/jsf/4.05 Libraries/AV Rule 20.ql +++ b/cpp/ql/src/jsf/4.05 Libraries/AV Rule 20.ql @@ -15,7 +15,7 @@ import cpp class Setjmp extends Macro { Setjmp() { super.getHead().matches("setjmp(%)") and - super.getFile().getAbsolutePath().matches("%setjmp.h") + super.getFile().getAbsolutePath().endsWith("setjmp.h") } } @@ -23,7 +23,7 @@ class Longjmp extends Function { Longjmp() { super.hasName("longjmp") and super.getNumberOfParameters() = 2 and - super.getFile().getAbsolutePath().matches("%setjmp.h") + super.getFile().getAbsolutePath().endsWith("setjmp.h") } } diff --git a/cpp/ql/src/jsf/4.05 Libraries/AV Rule 21.ql b/cpp/ql/src/jsf/4.05 Libraries/AV Rule 21.ql index 3640ddcb4b65..d06cf7f82a93 100644 --- a/cpp/ql/src/jsf/4.05 Libraries/AV Rule 21.ql +++ b/cpp/ql/src/jsf/4.05 Libraries/AV Rule 21.ql @@ -12,5 +12,5 @@ import cpp from Include incl -where incl.getIncludedFile().getAbsolutePath().matches("%signal.h") +where incl.getIncludedFile().getAbsolutePath().endsWith("signal.h") select incl, "AV Rule 21: The signal handling facilities of shall not be used." diff --git a/cpp/ql/src/jsf/4.05 Libraries/AV Rule 22.ql b/cpp/ql/src/jsf/4.05 Libraries/AV Rule 22.ql index e13f767f5819..711186b275f8 100644 --- a/cpp/ql/src/jsf/4.05 Libraries/AV Rule 22.ql +++ b/cpp/ql/src/jsf/4.05 Libraries/AV Rule 22.ql @@ -12,5 +12,5 @@ import cpp from Include incl -where incl.getIncludedFile().getAbsolutePath().matches("%stdio.h") +where incl.getIncludedFile().getAbsolutePath().endsWith("stdio.h") select incl, "AV Rule 22: The input/output library shall not be used." diff --git a/cpp/ql/src/jsf/4.05 Libraries/AV Rule 23.ql b/cpp/ql/src/jsf/4.05 Libraries/AV Rule 23.ql index ff4b1baec76e..57261adb5cfe 100644 --- a/cpp/ql/src/jsf/4.05 Libraries/AV Rule 23.ql +++ b/cpp/ql/src/jsf/4.05 Libraries/AV Rule 23.ql @@ -14,6 +14,6 @@ import cpp from Function f where f.getName() = ["atof", "atoi", "atol"] and - f.getFile().getAbsolutePath().matches("%stdlib.h") + f.getFile().getAbsolutePath().endsWith("stdlib.h") select f.getACallToThisFunction(), "AV Rule 23: The library functions atof, atoi and atol from library shall not be used." diff --git a/cpp/ql/src/jsf/4.05 Libraries/AV Rule 24.ql b/cpp/ql/src/jsf/4.05 Libraries/AV Rule 24.ql index 3bf27d8121c2..f63dc88d993e 100644 --- a/cpp/ql/src/jsf/4.05 Libraries/AV Rule 24.ql +++ b/cpp/ql/src/jsf/4.05 Libraries/AV Rule 24.ql @@ -14,6 +14,6 @@ import cpp from Function f where f.getName() = ["abort", "exit", "getenv", "system"] and - f.getFile().getAbsolutePath().matches("%stdlib.h") + f.getFile().getAbsolutePath().endsWith("stdlib.h") select f.getACallToThisFunction(), "The library functions abort, exit, getenv and system from library should not be used." diff --git a/cpp/ql/src/jsf/4.05 Libraries/AV Rule 25.ql b/cpp/ql/src/jsf/4.05 Libraries/AV Rule 25.ql index 5024a55f72b5..ec680d739f55 100644 --- a/cpp/ql/src/jsf/4.05 Libraries/AV Rule 25.ql +++ b/cpp/ql/src/jsf/4.05 Libraries/AV Rule 25.ql @@ -12,5 +12,5 @@ import cpp from Include incl -where incl.getIncludedFile().getAbsolutePath().matches("%time.h") +where incl.getIncludedFile().getAbsolutePath().endsWith("time.h") select incl, "AV Rule 25: The time handling functions of library shall not be used." diff --git a/cpp/ql/src/jsf/4.06 Pre-Processing Directives/AV Rule 29.ql b/cpp/ql/src/jsf/4.06 Pre-Processing Directives/AV Rule 29.ql index edbc026fe795..d18c4e11498f 100644 --- a/cpp/ql/src/jsf/4.06 Pre-Processing Directives/AV Rule 29.ql +++ b/cpp/ql/src/jsf/4.06 Pre-Processing Directives/AV Rule 29.ql @@ -11,5 +11,5 @@ import cpp from Macro m -where m.getHead().matches("%(%") // Macro functions are simply macros with brackets in the head +where m.getHead().contains("(") // Macro functions are simply macros with brackets in the head select m, "The #define pre-processor directive shall not be used to create inline macros." diff --git a/cpp/ql/src/jsf/4.06 Pre-Processing Directives/AV Rule 30.ql b/cpp/ql/src/jsf/4.06 Pre-Processing Directives/AV Rule 30.ql index 86175efea498..bbe6657fb8de 100644 --- a/cpp/ql/src/jsf/4.06 Pre-Processing Directives/AV Rule 30.ql +++ b/cpp/ql/src/jsf/4.06 Pre-Processing Directives/AV Rule 30.ql @@ -14,14 +14,14 @@ import cpp class ConstantDefMacro extends Macro { ConstantDefMacro() { // Exclude functions - not this.getHead().matches("%(%") and + not this.getHead().contains("(") and exists(string body | body = this.getBody() and // Empty defines are allowed (rule 31 restricts their use though) body != "" and // No special characters in the body - not body.matches("%(%") and - not body.matches("%{%") + not body.contains("(") and + not body.contains("{") ) } } diff --git a/cpp/ql/src/jsf/4.07 Header Files/AV Rule 33.ql b/cpp/ql/src/jsf/4.07 Header Files/AV Rule 33.ql index b17bbd0f1735..9ed073bbf5b5 100644 --- a/cpp/ql/src/jsf/4.07 Header Files/AV Rule 33.ql +++ b/cpp/ql/src/jsf/4.07 Header Files/AV Rule 33.ql @@ -12,5 +12,5 @@ import cpp from Include i -where i.getIncludeText().matches("<%") +where i.getIncludeText().startsWith("<") select i, "AV Rule 33: the #include notation shall be used." diff --git a/cpp/ql/src/jsf/4.20 Unions and Bit Fields/AV Rule 156.ql b/cpp/ql/src/jsf/4.20 Unions and Bit Fields/AV Rule 156.ql index 27ced03ed0b4..4fe0d46be661 100644 --- a/cpp/ql/src/jsf/4.20 Unions and Bit Fields/AV Rule 156.ql +++ b/cpp/ql/src/jsf/4.20 Unions and Bit Fields/AV Rule 156.ql @@ -21,7 +21,7 @@ import cpp from Declaration m where m.isMember() and - m.getName().matches("(%") and + m.getName().startsWith("(") and not m.(BitField).getDeclaredNumBits() = 0 select m, "AV Rule 156: All the members of a structure (or class) shall be named and shall only be accessed via their names." diff --git a/cpp/ql/src/utils/modelgenerator/internal/CaptureModels.qll b/cpp/ql/src/utils/modelgenerator/internal/CaptureModels.qll index 90160df3c210..378afd440c1d 100644 --- a/cpp/ql/src/utils/modelgenerator/internal/CaptureModels.qll +++ b/cpp/ql/src/utils/modelgenerator/internal/CaptureModels.qll @@ -65,8 +65,8 @@ private predicate isUninterestingForModels(Callable api) { // Exclude functions in test directories (but not the ones in the CodeQL test directory) exists(Cpp::File f | f = api.getFile() and - f.getAbsolutePath().matches("%test%") and - not f.getAbsolutePath().matches("%test/library-tests/dataflow/modelgenerator/dataflow/%") + f.getAbsolutePath().contains("test") and + not f.getAbsolutePath().contains("test/library-tests/dataflow/modelgenerator/dataflow/") ) } diff --git a/cpp/ql/test/library-tests/constants/constants/ints.ql b/cpp/ql/test/library-tests/constants/constants/ints.ql index aaa00f0e684e..90f56598f1b1 100644 --- a/cpp/ql/test/library-tests/constants/constants/ints.ql +++ b/cpp/ql/test/library-tests/constants/constants/ints.ql @@ -5,5 +5,5 @@ where l = v.getInitializer().getExpr() and v.getFunction().hasName("integers") and clazz = l.getAQlClass() and - (clazz.matches("%Literal") or clazz = "Zero") + (clazz.endsWith("Literal") or clazz = "Zero") select v, l.getValue(), l.getValueText(), clazz diff --git a/cpp/ql/test/library-tests/controlflow/guards/GuardsInline.ql b/cpp/ql/test/library-tests/controlflow/guards/GuardsInline.ql index a6875080d370..c10918829ecd 100644 --- a/cpp/ql/test/library-tests/controlflow/guards/GuardsInline.ql +++ b/cpp/ql/test/library-tests/controlflow/guards/GuardsInline.ql @@ -3,7 +3,7 @@ import semmle.code.cpp.controlflow.Guards import codeql.util.Boolean bindingset[s] -string escape(string s) { if s.matches("% %") then result = "'" + s + "'" else result = s } +string escape(string s) { if s.contains(" ") then result = "'" + s + "'" else result = s } Expr getUnconverted(Element e) { not e instanceof Expr and diff --git a/cpp/ql/test/library-tests/dataflow/asDefinition/test.ql b/cpp/ql/test/library-tests/dataflow/asDefinition/test.ql index b996f47fb49f..22450350ab34 100644 --- a/cpp/ql/test/library-tests/dataflow/asDefinition/test.ql +++ b/cpp/ql/test/library-tests/dataflow/asDefinition/test.ql @@ -3,7 +3,7 @@ import utils.test.InlineExpectationsTest import semmle.code.cpp.dataflow.new.DataFlow::DataFlow bindingset[s] -string quote(string s) { if s.matches("% %") then result = "\"" + s + "\"" else result = s } +string quote(string s) { if s.contains(" ") then result = "\"" + s + "\"" else result = s } module AsDefinitionTest implements TestSig { string getARelevantTag() { result = "asDefinition" } diff --git a/cpp/ql/test/library-tests/dataflow/asExpr/test-indirect.ql b/cpp/ql/test/library-tests/dataflow/asExpr/test-indirect.ql index dc71a92ee228..3ee06703453c 100644 --- a/cpp/ql/test/library-tests/dataflow/asExpr/test-indirect.ql +++ b/cpp/ql/test/library-tests/dataflow/asExpr/test-indirect.ql @@ -3,7 +3,7 @@ import utils.test.InlineExpectationsTest import semmle.code.cpp.dataflow.new.DataFlow::DataFlow bindingset[s] -string quote(string s) { if s.matches("% %") then result = "\"" + s + "\"" else result = s } +string quote(string s) { if s.contains(" ") then result = "\"" + s + "\"" else result = s } string formatNumberOfNodesForIndirectExpr(Expr e) { exists(int n | n = strictcount(Node node | node.asIndirectExpr() = e) | diff --git a/cpp/ql/test/library-tests/dataflow/asExpr/test.ql b/cpp/ql/test/library-tests/dataflow/asExpr/test.ql index e17962ce5a94..159808c678ef 100644 --- a/cpp/ql/test/library-tests/dataflow/asExpr/test.ql +++ b/cpp/ql/test/library-tests/dataflow/asExpr/test.ql @@ -3,7 +3,7 @@ import utils.test.InlineExpectationsTest import semmle.code.cpp.dataflow.new.DataFlow::DataFlow bindingset[s] -string quote(string s) { if s.matches("% %") then result = "\"" + s + "\"" else result = s } +string quote(string s) { if s.contains(" ") then result = "\"" + s + "\"" else result = s } string formatNumberOfNodesForExpr(Expr e) { exists(int n | n = strictcount(Node node | node.asExpr() = e) | n > 1 and result = ": " + n) diff --git a/cpp/ql/test/library-tests/dataflow/certain/test.ql b/cpp/ql/test/library-tests/dataflow/certain/test.ql index 231e3c31663e..348077ebfb48 100644 --- a/cpp/ql/test/library-tests/dataflow/certain/test.ql +++ b/cpp/ql/test/library-tests/dataflow/certain/test.ql @@ -3,7 +3,7 @@ import utils.test.InlineExpectationsTest import semmle.code.cpp.dataflow.new.DataFlow::DataFlow bindingset[s] -string quote(string s) { if s.matches("% %") then result = "\"" + s + "\"" else result = s } +string quote(string s) { if s.contains(" ") then result = "\"" + s + "\"" else result = s } module AsDefinitionTest implements TestSig { string getARelevantTag() { result = ["certain", "uncertain"] } diff --git a/cpp/ql/test/library-tests/dataflow/dataflow-tests/TestBase.qll b/cpp/ql/test/library-tests/dataflow/dataflow-tests/TestBase.qll index e28d19133c75..0a80b7d9de07 100644 --- a/cpp/ql/test/library-tests/dataflow/dataflow-tests/TestBase.qll +++ b/cpp/ql/test/library-tests/dataflow/dataflow-tests/TestBase.qll @@ -25,7 +25,7 @@ module AstTest { predicate isSource(DataFlow::Node source) { source.asExpr().(FunctionCall).getTarget().getName() = "source" or - source.asParameter().getName().matches("source%") + source.asParameter().getName().startsWith("source") or source.asExpr().(FunctionCall).getTarget().getName() = "indirect_source" or @@ -141,7 +141,7 @@ module IRTest { source.asIndirectExpr(n).(StringLiteral).getValue() = s ) or - source.asParameter().getName().matches("source%") + source.asParameter().getName().startsWith("source") or source.(DataFlow::DefinitionByReferenceNode).getParameter().getName().matches("ref_source%") or diff --git a/cpp/ql/test/library-tests/dataflow/dataflow-tests/guard-condition-regression-test.ql b/cpp/ql/test/library-tests/dataflow/dataflow-tests/guard-condition-regression-test.ql index 1218fe396c84..6e728afd2c01 100644 --- a/cpp/ql/test/library-tests/dataflow/dataflow-tests/guard-condition-regression-test.ql +++ b/cpp/ql/test/library-tests/dataflow/dataflow-tests/guard-condition-regression-test.ql @@ -5,7 +5,7 @@ private import semmle.code.cpp.controlflow.IRGuards module IRTestAllocationConfig implements DataFlow::ConfigSig { predicate isSource(DataFlow::Node source) { - source.asParameter().getName().matches("source%") and + source.asParameter().getName().startsWith("source") and source.getLocation().getFile().getBaseName() = "guard-condition-regression-test.cpp" } diff --git a/cpp/ql/test/library-tests/dataflow/forwarding/test.ql b/cpp/ql/test/library-tests/dataflow/forwarding/test.ql index e625769b0224..130b948a770f 100644 --- a/cpp/ql/test/library-tests/dataflow/forwarding/test.ql +++ b/cpp/ql/test/library-tests/dataflow/forwarding/test.ql @@ -4,7 +4,7 @@ import semmle.code.cpp.dataflow.ExternalFlow import semmle.code.cpp.ir.IR bindingset[s] -string quote(string s) { if s.matches("% %") then result = "\"" + s + "\"" else result = s } +string quote(string s) { if s.contains(" ") then result = "\"" + s + "\"" else result = s } string getConstructorId(Constructor constructor) { exists(CppStyleComment comment, string filepath, int startline, int endline | diff --git a/cpp/ql/test/library-tests/dataflow/taint-tests/taint.ql b/cpp/ql/test/library-tests/dataflow/taint-tests/taint.ql index 3bde6ca03f06..294a26ff36ef 100644 --- a/cpp/ql/test/library-tests/dataflow/taint-tests/taint.ql +++ b/cpp/ql/test/library-tests/dataflow/taint-tests/taint.ql @@ -47,7 +47,7 @@ module AstTest { predicate isSource(DataFlow::Node source) { source.asExpr().(FunctionCall).getTarget().getName() = "source" or - source.asParameter().getName().matches("source%") + source.asParameter().getName().startsWith("source") or // Track uninitialized variables exists(source.asUninitialized()) @@ -104,7 +104,7 @@ module IRTest { or source.asIndirectExpr().(FunctionCall).getTarget().getName() = "indirect_source" or - source.asParameter().getName().matches("source%") + source.asParameter().getName().startsWith("source") or exists(FunctionCall fc | fc.getAnArgument() = source.asDefiningArgument() and diff --git a/cpp/ql/test/library-tests/fields/fields/Fields.ql b/cpp/ql/test/library-tests/fields/fields/Fields.ql index 28948b148e3e..9b8dba2a6404 100644 --- a/cpp/ql/test/library-tests/fields/fields/Fields.ql +++ b/cpp/ql/test/library-tests/fields/fields/Fields.ql @@ -22,7 +22,7 @@ string accessType(Field f) { string fieldType(Field f) { result = f.getType().getAQlClass() and ( - result.matches("%Type") or + result.endsWith("Type") or result = "Enum" ) } diff --git a/cpp/ql/test/library-tests/friends/friends/nesting.ql b/cpp/ql/test/library-tests/friends/friends/nesting.ql index 2d33db4337eb..ad85deb108f6 100644 --- a/cpp/ql/test/library-tests/friends/friends/nesting.ql +++ b/cpp/ql/test/library-tests/friends/friends/nesting.ql @@ -6,6 +6,6 @@ int relativeLine(Locatable first, Locatable second) { from Class c, FriendDecl d where - c.getName().matches("Outer%") and + c.getName().startsWith("Outer") and d = c.getAFriendDecl() select c.toString(), d.getFriend().toString(), relativeLine(c, d) diff --git a/cpp/ql/test/library-tests/ir/range-analysis/RangeAnalysis.ql b/cpp/ql/test/library-tests/ir/range-analysis/RangeAnalysis.ql index b7413b1d6df6..e17e4cc8e128 100644 --- a/cpp/ql/test/library-tests/ir/range-analysis/RangeAnalysis.ql +++ b/cpp/ql/test/library-tests/ir/range-analysis/RangeAnalysis.ql @@ -34,7 +34,7 @@ private string getOffsetString(float value) { } bindingset[s] -string quote(string s) { if s.matches("% %") then result = "\"" + s + "\"" else result = s } +string quote(string s) { if s.contains(" ") then result = "\"" + s + "\"" else result = s } bindingset[delta] private string getBoundString(SemBound b, float delta) { diff --git a/cpp/ql/test/library-tests/odasa2646/cfi.ql b/cpp/ql/test/library-tests/odasa2646/cfi.ql index 1f54b8f85e74..05d415c276fd 100644 --- a/cpp/ql/test/library-tests/odasa2646/cfi.ql +++ b/cpp/ql/test/library-tests/odasa2646/cfi.ql @@ -4,5 +4,5 @@ from ConstructorFieldInit cfi, Expr e, string clazz where e = cfi.getExpr() and clazz = e.getAQlClass() and - clazz.matches("%Literal") + clazz.endsWith("Literal") select cfi, e, clazz diff --git a/cpp/ql/test/library-tests/type_strings/exprs.ql b/cpp/ql/test/library-tests/type_strings/exprs.ql index 918256ee81a5..2f402dffa7bf 100644 --- a/cpp/ql/test/library-tests/type_strings/exprs.ql +++ b/cpp/ql/test/library-tests/type_strings/exprs.ql @@ -1,5 +1,5 @@ import cpp from Expr e -where not (e instanceof CStyleCast and e.getValue().matches("%0")) +where not (e instanceof CStyleCast and e.getValue().endsWith("0")) select e, e.getType().toString(), e.getType().explain() diff --git a/cpp/ql/test/library-tests/types/__wchar_t/wchar_t.ql b/cpp/ql/test/library-tests/types/__wchar_t/wchar_t.ql index 446af45d2d80..b8d1d667c7a2 100644 --- a/cpp/ql/test/library-tests/types/__wchar_t/wchar_t.ql +++ b/cpp/ql/test/library-tests/types/__wchar_t/wchar_t.ql @@ -1,5 +1,5 @@ import cpp from Type t -where t.getName().matches("%wchar%") +where t.getName().contains("wchar") select t, concat(t.getAQlClass(), ", "), concat(t.(DerivedType).getBaseType().getAQlClass(), ", ") diff --git a/cpp/ql/test/library-tests/types/wchar_t_typedef/wchar_t.ql b/cpp/ql/test/library-tests/types/wchar_t_typedef/wchar_t.ql index 446af45d2d80..b8d1d667c7a2 100644 --- a/cpp/ql/test/library-tests/types/wchar_t_typedef/wchar_t.ql +++ b/cpp/ql/test/library-tests/types/wchar_t_typedef/wchar_t.ql @@ -1,5 +1,5 @@ import cpp from Type t -where t.getName().matches("%wchar%") +where t.getName().contains("wchar") select t, concat(t.getAQlClass(), ", "), concat(t.(DerivedType).getBaseType().getAQlClass(), ", ") diff --git a/cpp/ql/test/library-tests/variables/variables/variable.ql b/cpp/ql/test/library-tests/variables/variables/variable.ql index d21a34ec8069..7fac2eeada3a 100644 --- a/cpp/ql/test/library-tests/variables/variables/variable.ql +++ b/cpp/ql/test/library-tests/variables/variables/variable.ql @@ -3,9 +3,9 @@ import cpp string interestingQlClass(Variable v) { result = v.getAQlClass() and ( - result.matches("%Variable%") + result.contains("Variable") or - result.matches("%Field%") + result.contains("Field") ) } diff --git a/csharp/ql/integration-tests/all-platforms/standalone_dependency_dir/Assemblies.ql b/csharp/ql/integration-tests/all-platforms/standalone_dependency_dir/Assemblies.ql index 625fc299761e..4506412de5f4 100644 --- a/csharp/ql/integration-tests/all-platforms/standalone_dependency_dir/Assemblies.ql +++ b/csharp/ql/integration-tests/all-platforms/standalone_dependency_dir/Assemblies.ql @@ -3,5 +3,5 @@ import csharp from Assembly a where not a.getCompilation().getOutputAssembly() = a and - a.getName().matches("%Newtonsoft%") + a.getName().contains("Newtonsoft") select a diff --git a/csharp/ql/integration-tests/all-platforms/standalone_resx/CompilationInfo.ql b/csharp/ql/integration-tests/all-platforms/standalone_resx/CompilationInfo.ql index 28898f02fd24..957daaf46083 100644 --- a/csharp/ql/integration-tests/all-platforms/standalone_resx/CompilationInfo.ql +++ b/csharp/ql/integration-tests/all-platforms/standalone_resx/CompilationInfo.ql @@ -4,6 +4,6 @@ import semmle.code.csharp.commons.Diagnostics query predicate compilationInfo(string key, string value) { key != "Resolved references" and key != "Resolved assembly conflicts" and - not key.matches("Compiler diagnostic count for%") and + not key.startsWith("Compiler diagnostic count for") and value = any(Compilation c).getInfo(key) } diff --git a/csharp/ql/integration-tests/posix/standalone_dependencies_nuget_clear/CompilationInfo.ql b/csharp/ql/integration-tests/posix/standalone_dependencies_nuget_clear/CompilationInfo.ql index ae7505a8b0be..813a882a381d 100644 --- a/csharp/ql/integration-tests/posix/standalone_dependencies_nuget_clear/CompilationInfo.ql +++ b/csharp/ql/integration-tests/posix/standalone_dependencies_nuget_clear/CompilationInfo.ql @@ -3,6 +3,6 @@ import semmle.code.csharp.commons.Diagnostics query predicate compilationInfo(string key, string value) { key != "Resolved references" and - not key.matches("Compiler diagnostic count for%") and + not key.startsWith("Compiler diagnostic count for") and value = any(Compilation c).getInfo(key) } diff --git a/csharp/ql/integration-tests/posix/standalone_dependencies_nuget_config_error/CompilationInfo.ql b/csharp/ql/integration-tests/posix/standalone_dependencies_nuget_config_error/CompilationInfo.ql index ae7505a8b0be..813a882a381d 100644 --- a/csharp/ql/integration-tests/posix/standalone_dependencies_nuget_config_error/CompilationInfo.ql +++ b/csharp/ql/integration-tests/posix/standalone_dependencies_nuget_config_error/CompilationInfo.ql @@ -3,6 +3,6 @@ import semmle.code.csharp.commons.Diagnostics query predicate compilationInfo(string key, string value) { key != "Resolved references" and - not key.matches("Compiler diagnostic count for%") and + not key.startsWith("Compiler diagnostic count for") and value = any(Compilation c).getInfo(key) } diff --git a/csharp/ql/integration-tests/posix/standalone_dependencies_nuget_config_error_timeout/CompilationInfo.ql b/csharp/ql/integration-tests/posix/standalone_dependencies_nuget_config_error_timeout/CompilationInfo.ql index ae7505a8b0be..813a882a381d 100644 --- a/csharp/ql/integration-tests/posix/standalone_dependencies_nuget_config_error_timeout/CompilationInfo.ql +++ b/csharp/ql/integration-tests/posix/standalone_dependencies_nuget_config_error_timeout/CompilationInfo.ql @@ -3,6 +3,6 @@ import semmle.code.csharp.commons.Diagnostics query predicate compilationInfo(string key, string value) { key != "Resolved references" and - not key.matches("Compiler diagnostic count for%") and + not key.startsWith("Compiler diagnostic count for") and value = any(Compilation c).getInfo(key) } diff --git a/csharp/ql/integration-tests/posix/standalone_dependencies_nuget_config_fallback/CompilationInfo.ql b/csharp/ql/integration-tests/posix/standalone_dependencies_nuget_config_fallback/CompilationInfo.ql index ae7505a8b0be..813a882a381d 100644 --- a/csharp/ql/integration-tests/posix/standalone_dependencies_nuget_config_fallback/CompilationInfo.ql +++ b/csharp/ql/integration-tests/posix/standalone_dependencies_nuget_config_fallback/CompilationInfo.ql @@ -3,6 +3,6 @@ import semmle.code.csharp.commons.Diagnostics query predicate compilationInfo(string key, string value) { key != "Resolved references" and - not key.matches("Compiler diagnostic count for%") and + not key.startsWith("Compiler diagnostic count for") and value = any(Compilation c).getInfo(key) } diff --git a/csharp/ql/integration-tests/windows/subst/file.ql b/csharp/ql/integration-tests/windows/subst/file.ql index 43cc4a13fdc5..b7aafa691431 100644 --- a/csharp/ql/integration-tests/windows/subst/file.ql +++ b/csharp/ql/integration-tests/windows/subst/file.ql @@ -2,6 +2,6 @@ import csharp from File f, string relative where - not f.getURL().matches("file://C:/Program Files/%") and + not f.getURL().startsWith("file://C:/Program Files/") and if exists(f.getRelativePath()) then relative = "relative" else relative = "" select f, relative diff --git a/csharp/ql/lib/Linq/Helpers.qll b/csharp/ql/lib/Linq/Helpers.qll index 1657e812c268..33ecdcb97f87 100644 --- a/csharp/ql/lib/Linq/Helpers.qll +++ b/csharp/ql/lib/Linq/Helpers.qll @@ -79,7 +79,7 @@ predicate isEnumerableType(ValueOrRefType t) { predicate isIEnumerableType(ValueOrRefType t) { exists(string type | t.hasFullyQualifiedName("System.Collections.Generic", type) and - type.matches("IEnumerable%") + type.startsWith("IEnumerable") ) } diff --git a/csharp/ql/lib/semmle/code/asp/WebConfig.qll b/csharp/ql/lib/semmle/code/asp/WebConfig.qll index 384c3a013c3b..17e14ca548a5 100644 --- a/csharp/ql/lib/semmle/code/asp/WebConfig.qll +++ b/csharp/ql/lib/semmle/code/asp/WebConfig.qll @@ -8,14 +8,14 @@ import csharp * A `Web.config` file. */ class WebConfigXml extends XmlFile { - WebConfigXml() { this.getName().toLowerCase().matches("%web.config") } + WebConfigXml() { this.getName().toLowerCase().endsWith("web.config") } } /** * A `Web.config` transformation file. */ class WebConfigReleaseTransformXml extends XmlFile { - WebConfigReleaseTransformXml() { this.getName().toLowerCase().matches("%web.release.config") } + WebConfigReleaseTransformXml() { this.getName().toLowerCase().endsWith("web.release.config") } } /** A `` tag in an ASP.NET configuration file. */ diff --git a/csharp/ql/lib/semmle/code/csharp/Comments.qll b/csharp/ql/lib/semmle/code/csharp/Comments.qll index dfce22ebbee1..9af51c1327fb 100644 --- a/csharp/ql/lib/semmle/code/csharp/Comments.qll +++ b/csharp/ql/lib/semmle/code/csharp/Comments.qll @@ -214,7 +214,7 @@ class CommentBlock extends @commentblock { // Logic taken verbatim from Java query CommentedCode.qll result = this.getAChild() and exists(string trimmed | trimmed = result.getText().regexpReplaceAll("\\s*//.*$", "") | - trimmed.matches("%;") or trimmed.matches("%{") or trimmed.matches("%}") + trimmed.endsWith(";") or trimmed.endsWith("{") or trimmed.endsWith("}") ) } } diff --git a/csharp/ql/lib/semmle/code/csharp/File.qll b/csharp/ql/lib/semmle/code/csharp/File.qll index 464e08cebb48..eb075fdfba3d 100644 --- a/csharp/ql/lib/semmle/code/csharp/File.qll +++ b/csharp/ql/lib/semmle/code/csharp/File.qll @@ -56,7 +56,7 @@ class File extends Container, Impl::File { pragma[noinline] predicate isStub() { this.extractedQlTest() and - this.getAbsolutePath().matches("%resources/stubs/%") + this.getAbsolutePath().contains("resources/stubs/") } /** Holds if this file contains source code. */ diff --git a/csharp/ql/lib/semmle/code/csharp/commons/GeneratedCode.qll b/csharp/ql/lib/semmle/code/csharp/commons/GeneratedCode.qll index 4a90c121e2e2..3ede54a26ae3 100644 --- a/csharp/ql/lib/semmle/code/csharp/commons/GeneratedCode.qll +++ b/csharp/ql/lib/semmle/code/csharp/commons/GeneratedCode.qll @@ -8,22 +8,22 @@ abstract class GeneratedCodeFile extends SourceFile { } /** An auto-generated Designer file. */ class DesignerFile extends GeneratedCodeFile { - DesignerFile() { this.getBaseName().toLowerCase().matches("%.designer.cs") } + DesignerFile() { this.getBaseName().toLowerCase().endsWith(".designer.cs") } } /** An auto-generated SpecFlow feature file. */ class FeatureFile extends GeneratedCodeFile { - FeatureFile() { this.getBaseName().toLowerCase().matches("%.feature.cs") } + FeatureFile() { this.getBaseName().toLowerCase().endsWith(".feature.cs") } } /** An auto-generated XAML code file. */ class XamlFile extends GeneratedCodeFile { - XamlFile() { this.getBaseName().matches("%.g.cs") } + XamlFile() { this.getBaseName().endsWith(".g.cs") } } /** An auto-generated XSD code file. */ class AutogenXsdFile extends GeneratedCodeFile { - AutogenXsdFile() { this.getBaseName().matches("%.autogen.cs") } + AutogenXsdFile() { this.getBaseName().endsWith(".autogen.cs") } } /** An auto-generated CodeDOM file. */ diff --git a/csharp/ql/lib/semmle/code/csharp/dataflow/internal/ExternalFlow.qll b/csharp/ql/lib/semmle/code/csharp/dataflow/internal/ExternalFlow.qll index f8cec8c4d9f6..019753033395 100644 --- a/csharp/ql/lib/semmle/code/csharp/dataflow/internal/ExternalFlow.qll +++ b/csharp/ql/lib/semmle/code/csharp/dataflow/internal/ExternalFlow.qll @@ -252,7 +252,7 @@ module ModelValidation { type = name + "<" + any(string s) | summaryModel(namespace, type, _, name, _, _, _, output, _, _, _) and - output.matches("ReturnValue%") and + output.startsWith("ReturnValue") and result = "Constructor model for " + namespace + "." + type + " should use `Argument[this]` in the output, not `ReturnValue`." diff --git a/csharp/ql/lib/semmle/code/csharp/frameworks/EntityFramework.qll b/csharp/ql/lib/semmle/code/csharp/frameworks/EntityFramework.qll index 181bfaae5cce..157788c2355c 100644 --- a/csharp/ql/lib/semmle/code/csharp/frameworks/EntityFramework.qll +++ b/csharp/ql/lib/semmle/code/csharp/frameworks/EntityFramework.qll @@ -209,7 +209,7 @@ module EntityFramework { SqlParameter() { this.getType() instanceof StringType and ( - exists(Callable c | this = c.getParameter(0) | c.getName().matches("%Sql")) + exists(Callable c | this = c.getParameter(0) | c.getName().endsWith("Sql")) or this.getName() = "sql" ) and @@ -358,7 +358,7 @@ module EntityFramework { pragma[nomagic] Method getASaveChanges() { this.hasMethod(result) and - result.getName().matches("SaveChanges%") + result.getName().startsWith("SaveChanges") } /** Holds if component stack `head :: tail` is required for the input specification. */ diff --git a/csharp/ql/lib/semmle/code/csharp/frameworks/JsonNET.qll b/csharp/ql/lib/semmle/code/csharp/frameworks/JsonNET.qll index 69ae1ec292b5..b649f69da168 100644 --- a/csharp/ql/lib/semmle/code/csharp/frameworks/JsonNET.qll +++ b/csharp/ql/lib/semmle/code/csharp/frameworks/JsonNET.qll @@ -36,13 +36,13 @@ module JsonNET { /** Gets a `Deserialize` method. */ Method getADeserializeMethod() { result = this.getAMethod() and - result.getName().matches("Deserialize%") + result.getName().startsWith("Deserialize") } /** Gets a `Serialize` method. */ Method getASerializeMethod() { result = this.getAMethod() and - result.getName().matches("Serialize%") + result.getName().startsWith("Serialize") } } diff --git a/csharp/ql/lib/semmle/code/csharp/frameworks/Razor.qll b/csharp/ql/lib/semmle/code/csharp/frameworks/Razor.qll index aee0789e3292..76d36c5ee83f 100644 --- a/csharp/ql/lib/semmle/code/csharp/frameworks/Razor.qll +++ b/csharp/ql/lib/semmle/code/csharp/frameworks/Razor.qll @@ -199,12 +199,12 @@ private class RelativeViewCallFilepath extends NormalizableFilepath { template = getViewSearchTemplate(idx_, vc_.hasArea()) | ( - if template.matches("%{2}%") + if template.contains("{2}") then sub2 = template.replaceAll("{2}", vc_.getAreaName()) else sub2 = template ) and ( - if template.matches("%{1}%") + if template.contains("{1}") then sub1 = sub2.replaceAll("{1}", vc_.getControllerName()) else sub1 = sub2 ) and @@ -226,7 +226,7 @@ class PageModelClass extends Class { /** Gets a handler method such as `OnGetAsync` */ Method getAHandlerMethod() { result = this.getAMethod() and - result.getName().matches("On%") and + result.getName().startsWith("On") and not exists(Attribute attr | attr = result.getAnAttribute() and attr.getType() diff --git a/csharp/ql/lib/semmle/code/csharp/frameworks/microsoft/AspNetCore.qll b/csharp/ql/lib/semmle/code/csharp/frameworks/microsoft/AspNetCore.qll index 1f5060a6ce06..f85e63bc73f0 100644 --- a/csharp/ql/lib/semmle/code/csharp/frameworks/microsoft/AspNetCore.qll +++ b/csharp/ql/lib/semmle/code/csharp/frameworks/microsoft/AspNetCore.qll @@ -216,7 +216,7 @@ private predicate isPotentialMicrosoftAspNetCoreMvcController(Class controller) ( c.getABaseType*() instanceof MicrosoftAspNetCoreMvcControllerBaseClass or - c.getABaseType*().getName().matches("%Controller") + c.getABaseType*().getName().endsWith("Controller") or c.getABaseType*() .getAnAttribute() @@ -402,7 +402,7 @@ private predicate isDefaultMicrosoftAspNetCoreMvcController(Class controller) { ( hasMicrosoftAspNetCoreMvcControllerIdentity(controller) or - controller.getName().toLowerCase().matches("%controller") and + controller.getName().toLowerCase().endsWith("controller") and hasMicrosoftAspNetCoreMvcEndpointMapping(_, controller) ) and not controller.getABaseType*().getAnAttribute() instanceof @@ -434,11 +434,11 @@ class MicrosoftAspNetCoreMvcControllerHelperClass extends Class { Method getAResponseMethod() { result = this.getAMethod() and ( - result.getName().matches("Redirect%") + result.getName().startsWith("Redirect") or - result.getName().matches("Accepted%") + result.getName().startsWith("Accepted") or - result.getName().matches("Created%") + result.getName().startsWith("Created") ) } } diff --git a/csharp/ql/lib/semmle/code/csharp/frameworks/microsoft/Owin.qll b/csharp/ql/lib/semmle/code/csharp/frameworks/microsoft/Owin.qll index 2bd31bc4357f..ceffcc36e404 100644 --- a/csharp/ql/lib/semmle/code/csharp/frameworks/microsoft/Owin.qll +++ b/csharp/ql/lib/semmle/code/csharp/frameworks/microsoft/Owin.qll @@ -129,7 +129,7 @@ class MicrosoftOwinIOwinRequestClass extends Class { class MicrosoftOwinString extends Class { MicrosoftOwinString() { this.getNamespace() instanceof MicrosoftOwinNamespace and - this.getName().matches("%String") + this.getName().endsWith("String") } /** Gets the `Value` property. */ diff --git a/csharp/ql/lib/semmle/code/csharp/frameworks/system/IO.qll b/csharp/ql/lib/semmle/code/csharp/frameworks/system/IO.qll index 9756bf9c982e..868286324fd4 100644 --- a/csharp/ql/lib/semmle/code/csharp/frameworks/system/IO.qll +++ b/csharp/ql/lib/semmle/code/csharp/frameworks/system/IO.qll @@ -53,13 +53,13 @@ class SystemIOStreamClass extends SystemIOClass { /** Gets a method that performs a read. */ Method getAReadMethod() { result = this.getAMethod() and - result.getName().matches("%Read%") + result.getName().contains("Read") } /** Gets a method that performs a write. */ Method getAWriteMethod() { result = this.getAMethod() and - result.getName().matches("%Write%") + result.getName().contains("Write") } /** Gets the `Read(byte[], int, int)` method. */ diff --git a/csharp/ql/lib/semmle/code/csharp/frameworks/system/web/Mvc.qll b/csharp/ql/lib/semmle/code/csharp/frameworks/system/web/Mvc.qll index b2051a8464fe..d33fa5ceec29 100644 --- a/csharp/ql/lib/semmle/code/csharp/frameworks/system/web/Mvc.qll +++ b/csharp/ql/lib/semmle/code/csharp/frameworks/system/web/Mvc.qll @@ -68,7 +68,7 @@ class SystemWebMvcControllerClass extends SystemWebMvcClass { /** Gets a `Redirect..` method. */ Method getARedirectMethod() { result = this.getAMethod() and - result.getName().matches("Redirect%") + result.getName().startsWith("Redirect") } } diff --git a/csharp/ql/lib/semmle/code/csharp/frameworks/system/xml/XPath.qll b/csharp/ql/lib/semmle/code/csharp/frameworks/system/xml/XPath.qll index 7e703f446083..3fbaefcd5ba8 100644 --- a/csharp/ql/lib/semmle/code/csharp/frameworks/system/xml/XPath.qll +++ b/csharp/ql/lib/semmle/code/csharp/frameworks/system/xml/XPath.qll @@ -29,7 +29,7 @@ module SystemXmlXPath { /** Gets a method that selects nodes. */ CSharp::Method getASelectMethod() { - result = this.getAMethod() and result.getName().matches("Select%") + result = this.getAMethod() and result.getName().startsWith("Select") } /** Gets the `Compile` method. */ diff --git a/csharp/ql/lib/semmle/code/csharp/security/SensitiveActions.qll b/csharp/ql/lib/semmle/code/csharp/security/SensitiveActions.qll index 739d92588cff..c40d8bcaa636 100644 --- a/csharp/ql/lib/semmle/code/csharp/security/SensitiveActions.qll +++ b/csharp/ql/lib/semmle/code/csharp/security/SensitiveActions.qll @@ -170,13 +170,13 @@ class AuthMethod extends SensitiveExecutionMethod { AuthMethod() { exists(string s | s = this.getName().toLowerCase() | ( - s.matches("%login%") or - s.matches("%auth%") + s.contains("login") or + s.contains("auth") ) and not ( - s.matches("get%") or - s.matches("set%") or - s.matches("%loginfo%") + s.startsWith("get") or + s.startsWith("set") or + s.contains("loginfo") ) ) } @@ -185,7 +185,7 @@ class AuthMethod extends SensitiveExecutionMethod { /** A method that sends data, and so should not be run conditionally on user input. */ class SendingMethod extends SensitiveExecutionMethod { SendingMethod() { - exists(string s | s.matches("%Socket") | + exists(string s | s.endsWith("Socket") | this.getDeclaringType().hasFullyQualifiedName("System.Net.Sockets", s) and this.hasName("Send") ) diff --git a/csharp/ql/lib/semmle/code/csharp/security/auth/ActionMethods.qll b/csharp/ql/lib/semmle/code/csharp/security/auth/ActionMethods.qll index b606bb6259eb..e90e8d15629a 100644 --- a/csharp/ql/lib/semmle/code/csharp/security/auth/ActionMethods.qll +++ b/csharp/ql/lib/semmle/code/csharp/security/auth/ActionMethods.qll @@ -53,7 +53,7 @@ private class MvcActionMethod extends ActionMethod { private class WebFormActionMethod extends ActionMethod { WebFormActionMethod() { this.getDeclaringType().getBaseClass+() instanceof SystemWebUIPageClass and - this.getAParameter().getType().getName().matches("%EventArgs") + this.getAParameter().getType().getName().endsWith("EventArgs") } override Callable getAnAuthorizingCallable() { diff --git a/csharp/ql/lib/semmle/code/csharp/security/auth/MissingFunctionLevelAccessControlQuery.qll b/csharp/ql/lib/semmle/code/csharp/security/auth/MissingFunctionLevelAccessControlQuery.qll index 0e3074065f46..900d9137d150 100644 --- a/csharp/ql/lib/semmle/code/csharp/security/auth/MissingFunctionLevelAccessControlQuery.qll +++ b/csharp/ql/lib/semmle/code/csharp/security/auth/MissingFunctionLevelAccessControlQuery.qll @@ -20,9 +20,9 @@ class AuthExpr extends Expr { .getTarget() .hasFullyQualifiedName("System.Security.Principal", "IIdentity", ["IsAuthenticated", "Name"]) or - this.(MethodCall).getTarget().getName().toLowerCase().matches("%auth%") + this.(MethodCall).getTarget().getName().toLowerCase().contains("auth") or - this.(PropertyAccess).getTarget().getName().toLowerCase().matches("%auth%") + this.(PropertyAccess).getTarget().getName().toLowerCase().contains("auth") } } @@ -81,7 +81,7 @@ predicate hasAuthViaXml(ActionMethod m) { /** Holds if the given action has an attribute that indications authorization. */ predicate hasAuthViaAttribute(ActionMethod m) { - exists(Attribute attr | attr.getType().getABaseType*().getName().toLowerCase().matches("%auth%") | + exists(Attribute attr | attr.getType().getABaseType*().getName().toLowerCase().contains("auth") | attr = m.getOverridee*().getAnAttribute() or attr = getAnUnboundBaseType*(m.getDeclaringType()).getAnAttribute() ) diff --git a/csharp/ql/lib/semmle/code/csharp/security/cryptography/HardcodedSymmetricEncryptionKey.qll b/csharp/ql/lib/semmle/code/csharp/security/cryptography/HardcodedSymmetricEncryptionKey.qll index 37690c169c0b..4f3bf760edc8 100644 --- a/csharp/ql/lib/semmle/code/csharp/security/cryptography/HardcodedSymmetricEncryptionKey.qll +++ b/csharp/ql/lib/semmle/code/csharp/security/cryptography/HardcodedSymmetricEncryptionKey.qll @@ -42,7 +42,7 @@ module HardcodedSymmetricEncryptionKey { private class SymmetricAlgorithmSink extends Sink { private string kind; - SymmetricAlgorithmSink() { sinkNode(this, kind) and kind.matches("encryption%") } + SymmetricAlgorithmSink() { sinkNode(this, kind) and kind.startsWith("encryption") } override string getDescription() { kind = "encryption-encryptor" and result = "Encryptor(rgbKey, IV)" diff --git a/csharp/ql/lib/semmle/code/csharp/security/dataflow/CodeInjectionQuery.qll b/csharp/ql/lib/semmle/code/csharp/security/dataflow/CodeInjectionQuery.qll index f567e3cbc021..81c6d56d8f87 100644 --- a/csharp/ql/lib/semmle/code/csharp/security/dataflow/CodeInjectionQuery.qll +++ b/csharp/ql/lib/semmle/code/csharp/security/dataflow/CodeInjectionQuery.qll @@ -70,7 +70,7 @@ private class GuidSanitizer extends Sanitizer, GuidSanitizedExpr { } class CompileAssemblyFromSourceSink extends Sink { CompileAssemblyFromSourceSink() { exists(Method m, MethodCall mc | - m.getName().matches("CompileAssemblyFromSource%") and + m.getName().startsWith("CompileAssemblyFromSource") and m = any(SystemCodeDomCompilerICodeCompilerClass c).getAMethod() and mc = m.getAnOverrider*().getACall() | diff --git a/csharp/ql/lib/semmle/code/csharp/security/dataflow/HardcodedCredentialsQuery.qll b/csharp/ql/lib/semmle/code/csharp/security/dataflow/HardcodedCredentialsQuery.qll index 72951df2f979..be54f2e88567 100644 --- a/csharp/ql/lib/semmle/code/csharp/security/dataflow/HardcodedCredentialsQuery.qll +++ b/csharp/ql/lib/semmle/code/csharp/security/dataflow/HardcodedCredentialsQuery.qll @@ -77,9 +77,9 @@ module HardcodedCredentials { not ( source.getNode().asExpr().getFile() instanceof TestFile and exists(MethodCall createOrAddCall, string createOrAddMethodName | - createOrAddMethodName.matches("Update%") or - createOrAddMethodName.matches("Create%") or - createOrAddMethodName.matches("Add%") + createOrAddMethodName.startsWith("Update") or + createOrAddMethodName.startsWith("Create") or + createOrAddMethodName.startsWith("Add") | createOrAddCall.getTarget().hasName(createOrAddMethodName) and createOrAddCall.getAnArgument() = sink.getNode().asExpr() diff --git a/csharp/ql/lib/semmle/code/csharp/security/dataflow/UrlRedirectQuery.qll b/csharp/ql/lib/semmle/code/csharp/security/dataflow/UrlRedirectQuery.qll index 1e53fccaaea1..47a35b338747 100644 --- a/csharp/ql/lib/semmle/code/csharp/security/dataflow/UrlRedirectQuery.qll +++ b/csharp/ql/lib/semmle/code/csharp/security/dataflow/UrlRedirectQuery.qll @@ -200,7 +200,7 @@ class HostComparisonSanitizer extends Sanitizer { class ConcatenationSanitizer extends Sanitizer { ConcatenationSanitizer() { this.getType() instanceof StringType and - this.getExpr().(AddExpr).getLeftOperand().getValue().matches("%?%") + this.getExpr().(AddExpr).getLeftOperand().getValue().contains("?") } } @@ -212,7 +212,7 @@ class ConcatenationSanitizer extends Sanitizer { */ private class InterpolationSanitizer extends Sanitizer { InterpolationSanitizer() { - this.getExpr().(InterpolatedStringExpr).getText(0).getValue().matches("%?%") + this.getExpr().(InterpolatedStringExpr).getText(0).getValue().contains("?") } } @@ -229,7 +229,7 @@ private class StringFormatSanitizer extends Sanitizer { | format = e.(StringLiteral).getValue() and exists(format.regexpFind("\\{[0-9]+\\}", 0, index)) and - format.substring(0, index).matches("%?%") + format.substring(0, index).contains("?") ) } } diff --git a/csharp/ql/lib/semmle/code/csharp/security/dataflow/XSSSinks.qll b/csharp/ql/lib/semmle/code/csharp/security/dataflow/XSSSinks.qll index fede4750c0ff..199a57c00077 100644 --- a/csharp/ql/lib/semmle/code/csharp/security/dataflow/XSSSinks.qll +++ b/csharp/ql/lib/semmle/code/csharp/security/dataflow/XSSSinks.qll @@ -101,7 +101,7 @@ private class SystemWebSetterNonHtmlSink extends Sink { name = "GroupingTest" or name = "GroupName" or name = "Style" or - name.matches("%URL") + name.endsWith("URL") ) } } diff --git a/csharp/ql/lib/semmle/code/csharp/security/dataflow/flowsinks/ParallelSink.qll b/csharp/ql/lib/semmle/code/csharp/security/dataflow/flowsinks/ParallelSink.qll index 1546d72887d5..430158ecc436 100644 --- a/csharp/ql/lib/semmle/code/csharp/security/dataflow/flowsinks/ParallelSink.qll +++ b/csharp/ql/lib/semmle/code/csharp/security/dataflow/flowsinks/ParallelSink.qll @@ -32,7 +32,7 @@ class ThreadStartParallelSink extends ParallelSink { ThreadStartParallelSink() { exists(DelegateCreation dc, Expr e | e = this.asExpr() | dc.getArgument() = e and - dc.getType().getName().matches("%Start") + dc.getType().getName().endsWith("Start") ) } } diff --git a/csharp/ql/src/ASP/BlockCodeResponseWrite.ql b/csharp/ql/src/ASP/BlockCodeResponseWrite.ql index 93f43342f0ee..1b8192c5903a 100644 --- a/csharp/ql/src/ASP/BlockCodeResponseWrite.ql +++ b/csharp/ql/src/ASP/BlockCodeResponseWrite.ql @@ -14,5 +14,5 @@ import semmle.code.asp.AspNet from AspBlockCode code -where code.getBody().trim().matches("Response.Write(%") +where code.getBody().trim().startsWith("Response.Write(") select code, "Non-inline code calls 'Response.Write()'." diff --git a/csharp/ql/src/Architecture/Dependencies/MutualDependency.ql b/csharp/ql/src/Architecture/Dependencies/MutualDependency.ql index 5f5d58345a13..b21a8721614a 100644 --- a/csharp/ql/src/Architecture/Dependencies/MutualDependency.ql +++ b/csharp/ql/src/Architecture/Dependencies/MutualDependency.ql @@ -33,9 +33,9 @@ where not ( nestedWithin(t1, t2) or nestedWithin(t2, t1) or - t1.getName().toLowerCase().matches("%visitor%") or - t2.getName().toLowerCase().matches("%visitor%") or - t1.getAMember().getName().toLowerCase().matches("%visit%") or - t2.getAMember().getName().toLowerCase().matches("%visit%") + t1.getName().toLowerCase().contains("visitor") or + t2.getName().toLowerCase().contains("visitor") or + t1.getAMember().getName().toLowerCase().contains("visit") or + t2.getAMember().getName().toLowerCase().contains("visit") ) select t1, "This type and type $@ are mutually dependent.", t2, t2.getName() diff --git a/csharp/ql/src/Bad Practices/Naming Conventions/DefaultControlNames.ql b/csharp/ql/src/Bad Practices/Naming Conventions/DefaultControlNames.ql index e12bd2e6af30..510ebad72908 100644 --- a/csharp/ql/src/Bad Practices/Naming Conventions/DefaultControlNames.ql +++ b/csharp/ql/src/Bad Practices/Naming Conventions/DefaultControlNames.ql @@ -24,7 +24,7 @@ predicate controlName(string prefix) { predicate usedInHumanWrittenCode(Field f) { exists(File file | f.getAnAccess().getFile() = file and - not file.getBaseName().toLowerCase().matches("%.designer.cs") + not file.getBaseName().toLowerCase().endsWith(".designer.cs") ) } diff --git a/csharp/ql/src/Bad Practices/Naming Conventions/VariableNameTooShort.ql b/csharp/ql/src/Bad Practices/Naming Conventions/VariableNameTooShort.ql index cb778465df8b..7761b1063a45 100644 --- a/csharp/ql/src/Bad Practices/Naming Conventions/VariableNameTooShort.ql +++ b/csharp/ql/src/Bad Practices/Naming Conventions/VariableNameTooShort.ql @@ -44,7 +44,7 @@ predicate allowedVariable(Variable variable) { exists(Parameter param | variable = param and not exists(param.getAnAccess()) and - param.getType().getName().matches("%EventArgs") + param.getType().getName().endsWith("EventArgs") ) or exists(LocalVariable local | diff --git a/csharp/ql/src/Bad Practices/UseOfSystemOutputStream.ql b/csharp/ql/src/Bad Practices/UseOfSystemOutputStream.ql index b9a45126d3c6..eec20888cdbd 100644 --- a/csharp/ql/src/Bad Practices/UseOfSystemOutputStream.ql +++ b/csharp/ql/src/Bad Practices/UseOfSystemOutputStream.ql @@ -28,7 +28,7 @@ predicate isConsoleErrorRedefinedSomewhere() { } predicate isCallToConsoleWrite(MethodCall mc) { - mc.getTarget().getName().matches("Write%") and + mc.getTarget().getName().startsWith("Write") and mc.getTarget().getDeclaringType().hasFullyQualifiedName("System", "Console") } diff --git a/csharp/ql/src/Concurrency/Concurrency.qll b/csharp/ql/src/Concurrency/Concurrency.qll index 861d03bf7898..fe8dda21179a 100644 --- a/csharp/ql/src/Concurrency/Concurrency.qll +++ b/csharp/ql/src/Concurrency/Concurrency.qll @@ -93,7 +93,7 @@ class LockingCall extends MethodCall { this.getTarget() = any(Method m | m.getDeclaringType().hasFullyQualifiedName("System.Threading", "Monitor") and - m.getName().matches("%Enter%") + m.getName().contains("Enter") ) or this.getTarget().hasName("EnterReadLock") or this.getTarget().hasName("EnterWriteLock") diff --git a/csharp/ql/src/Concurrency/UnsynchronizedStaticAccess.ql b/csharp/ql/src/Concurrency/UnsynchronizedStaticAccess.ql index 340663c6701f..63cdc9770b29 100644 --- a/csharp/ql/src/Concurrency/UnsynchronizedStaticAccess.ql +++ b/csharp/ql/src/Concurrency/UnsynchronizedStaticAccess.ql @@ -20,7 +20,7 @@ import ThreadCreation predicate correctlySynchronized(CollectionMember c, Expr access) { access = c.getAReadOrWrite() and ( - c.getType().(ValueOrRefType).getABaseType*().getName().matches("Concurrent%") or + c.getType().(ValueOrRefType).getABaseType*().getName().startsWith("Concurrent") or access.getEnclosingStmt().getParent*() instanceof LockStmt or any(LockingCall call).getControlFlowNode().getASuccessor+() = access.getControlFlowNode() ) diff --git a/csharp/ql/src/Security Features/CWE-327/InsecureSQLConnection.ql b/csharp/ql/src/Security Features/CWE-327/InsecureSQLConnection.ql index a1dd249fabac..bfd4998a1d8b 100644 --- a/csharp/ql/src/Security Features/CWE-327/InsecureSQLConnection.ql +++ b/csharp/ql/src/Security Features/CWE-327/InsecureSQLConnection.ql @@ -19,9 +19,9 @@ import InsecureSqlConnection::PathGraph module InsecureSqlConnectionConfig implements DataFlow::ConfigSig { predicate isSource(DataFlow::Node source) { exists(string s | s = source.asExpr().(StringLiteral).getValue().toLowerCase() | - s.matches("%encrypt=false%") + s.contains("encrypt=false") or - not s.matches("%encrypt=%") + not s.contains("encrypt=") ) } diff --git a/csharp/ql/src/Security Features/CookieWithOverlyBroadDomain.ql b/csharp/ql/src/Security Features/CookieWithOverlyBroadDomain.ql index 59a6340104a9..120568f4dc41 100644 --- a/csharp/ql/src/Security Features/CookieWithOverlyBroadDomain.ql +++ b/csharp/ql/src/Security Features/CookieWithOverlyBroadDomain.ql @@ -19,6 +19,6 @@ where pa.getTarget().getDeclaringType().hasFullyQualifiedName("System.Web", "HttpCookie") and ( a.getRightOperand().getValue().regexpReplaceAll("[^.]", "").length() < 2 or - a.getRightOperand().getValue().matches(".%") + a.getRightOperand().getValue().startsWith(".") ) select a, "Overly broad domain for cookie." diff --git a/csharp/ql/src/Security Features/PersistentCookie.ql b/csharp/ql/src/Security Features/PersistentCookie.ql index edc97b464e5c..804699cbc2d1 100644 --- a/csharp/ql/src/Security Features/PersistentCookie.ql +++ b/csharp/ql/src/Security Features/PersistentCookie.ql @@ -19,7 +19,7 @@ class FutureDateExpr extends MethodCall { pa.getTarget().hasName("Now") and pa.getTarget().getDeclaringType().hasFullyQualifiedName("System", "DateTime") ) and - this.getTarget().getName().matches("Add%") + this.getTarget().getName().startsWith("Add") } float getTimeInSecond() { diff --git a/csharp/ql/src/Telemetry/ExtractorInformation.ql b/csharp/ql/src/Telemetry/ExtractorInformation.ql index 6fdaf9ca22d5..5c179a184d71 100644 --- a/csharp/ql/src/Telemetry/ExtractorInformation.ql +++ b/csharp/ql/src/Telemetry/ExtractorInformation.ql @@ -11,8 +11,8 @@ import semmle.code.csharp.commons.Diagnostics import DatabaseQuality predicate compilationInfo(string key, float value) { - not key.matches("Compiler diagnostic count for%") and - not key.matches("Extractor message count for group%") and + not key.startsWith("Compiler diagnostic count for") and + not key.startsWith("Extractor message count for group") and exists(Compilation c, string infoKey, string infoValue | infoValue = c.getInfo(infoKey) | key = infoKey and value = infoValue.toFloat() @@ -24,12 +24,12 @@ predicate compilationInfo(string key, float value) { } predicate compilerDiagnostics(string key, int value) { - key.matches("Compiler diagnostic count for%") and + key.startsWith("Compiler diagnostic count for") and strictsum(Compilation c | | c.getInfo(key).toInt()) = value } predicate extractorMessages(string key, int value) { - key.matches("Extractor message count for group%") and + key.startsWith("Extractor message count for group") and strictsum(Compilation c | | c.getInfo(key).toInt()) = value } diff --git a/csharp/ql/src/experimental/Security Features/Serialization/DataSetSerialization.qll b/csharp/ql/src/experimental/Security Features/Serialization/DataSetSerialization.qll index 324dc883a352..b752c35b0cf1 100644 --- a/csharp/ql/src/experimental/Security Features/Serialization/DataSetSerialization.qll +++ b/csharp/ql/src/experimental/Security Features/Serialization/DataSetSerialization.qll @@ -80,7 +80,7 @@ class UnsafeXmlReadMethod extends Method { UnsafeXmlReadMethod() { this.hasFullyQualifiedName("System.Data", ["DataTable", "DataSet"], ["ReadXml", "ReadXmlSchema"]) or - this.getName().matches("ReadXml%") and + this.getName().startsWith("ReadXml") and exists(Class c | c.getAMethod() = this | c.getABaseType*() instanceof DataSetOrTableRelatedClass ) diff --git a/csharp/ql/src/experimental/Security Features/backdoor/DangerousNativeFunctionCall.ql b/csharp/ql/src/experimental/Security Features/backdoor/DangerousNativeFunctionCall.ql index 347f3f507a37..458bb00caddb 100644 --- a/csharp/ql/src/experimental/Security Features/backdoor/DangerousNativeFunctionCall.ql +++ b/csharp/ql/src/experimental/Security Features/backdoor/DangerousNativeFunctionCall.ql @@ -18,20 +18,20 @@ predicate isDangerousMethod(Method m) { m.getName() = "OpenThreadToken" or m.getName() = "DuplicateToken" or m.getName() = "DuplicateTokenEx" or - m.getName().matches("LogonUser%") or - m.getName().matches("WNetAddConnection%") or + m.getName().startsWith("LogonUser") or + m.getName().startsWith("WNetAddConnection") or m.getName() = "DeviceIoControl" or - m.getName().matches("LoadLibrary%") or + m.getName().startsWith("LoadLibrary") or m.getName() = "GetProcAddress" or - m.getName().matches("CreateProcess%") or - m.getName().matches("InitiateSystemShutdown%") or + m.getName().startsWith("CreateProcess") or + m.getName().startsWith("InitiateSystemShutdown") or m.getName() = "GetCurrentProcess" or m.getName() = "GetCurrentProcessToken" or m.getName() = "GetCurrentThreadToken" or m.getName() = "GetCurrentThreadEffectiveToken" or m.getName() = "OpenThreadToken" or m.getName() = "SetTokenInformation" or - m.getName().matches("LookupPrivilegeValue%") or + m.getName().startsWith("LookupPrivilegeValue") or m.getName() = "AdjustTokenPrivileges" or m.getName() = "SetProcessPrivilege" or m.getName() = "ImpersonateLoggedOnUser" or diff --git a/csharp/ql/src/experimental/Security Features/backdoor/ProcessNameToHashTaintFlow.ql b/csharp/ql/src/experimental/Security Features/backdoor/ProcessNameToHashTaintFlow.ql index c8b23f476fd2..9962e3fead04 100644 --- a/csharp/ql/src/experimental/Security Features/backdoor/ProcessNameToHashTaintFlow.ql +++ b/csharp/ql/src/experimental/Security Features/backdoor/ProcessNameToHashTaintFlow.ql @@ -25,7 +25,7 @@ module DataFlowFromMethodToHash = TaintTracking::Global` element references a bean if the URI starts with "bean:", or there is no scheme. - this.matches("bean:%") or + this.startsWith("bean:") or not exists(this.indexOf(":")) } diff --git a/java/ql/lib/semmle/code/java/frameworks/Cucumber.qll b/java/ql/lib/semmle/code/java/frameworks/Cucumber.qll index 15e71a25f890..1c2f549c2099 100644 --- a/java/ql/lib/semmle/code/java/frameworks/Cucumber.qll +++ b/java/ql/lib/semmle/code/java/frameworks/Cucumber.qll @@ -10,7 +10,7 @@ import java * An annotation defined in the Cucumber library. */ class CucumberAnnotation extends Annotation { - CucumberAnnotation() { this.getType().getPackage().getName().matches("cucumber.api.java%") } + CucumberAnnotation() { this.getType().getPackage().getName().startsWith("cucumber.api.java") } } /** diff --git a/java/ql/lib/semmle/code/java/frameworks/IoJsonWebToken.qll b/java/ql/lib/semmle/code/java/frameworks/IoJsonWebToken.qll index b4573013295b..4c3ec20dd385 100644 --- a/java/ql/lib/semmle/code/java/frameworks/IoJsonWebToken.qll +++ b/java/ql/lib/semmle/code/java/frameworks/IoJsonWebToken.qll @@ -9,5 +9,5 @@ private import semmle.code.java.dataflow.FlowSteps private class JwsHeaderFieldsInheritTaint extends DataFlow::SyntheticFieldContent, TaintInheritingContent { - JwsHeaderFieldsInheritTaint() { this.getField().matches("io.jsonwebtoken.JwsHeader.%") } + JwsHeaderFieldsInheritTaint() { this.getField().startsWith("io.jsonwebtoken.JwsHeader.") } } diff --git a/java/ql/lib/semmle/code/java/frameworks/JAXB.qll b/java/ql/lib/semmle/code/java/frameworks/JAXB.qll index c781abdb8287..5e209db39316 100644 --- a/java/ql/lib/semmle/code/java/frameworks/JAXB.qll +++ b/java/ql/lib/semmle/code/java/frameworks/JAXB.qll @@ -145,7 +145,7 @@ class JaxbBoundField extends Field { * A getter or setter method, as defined by whether the method name starts with "set" or "get". */ class GetterOrSetterMethod extends Method { - GetterOrSetterMethod() { this.getName().matches("get%") or this.getName().matches("set%") } + GetterOrSetterMethod() { this.getName().startsWith("get") or this.getName().startsWith("set") } Field getField() { result.getDeclaringType() = this.getDeclaringType() and diff --git a/java/ql/lib/semmle/code/java/frameworks/JaxWS.qll b/java/ql/lib/semmle/code/java/frameworks/JaxWS.qll index 38bac53485bf..1c0313618f24 100644 --- a/java/ql/lib/semmle/code/java/frameworks/JaxWS.qll +++ b/java/ql/lib/semmle/code/java/frameworks/JaxWS.qll @@ -126,7 +126,7 @@ private class JaxValueType extends RefType { // Mutually exclusive with other `JaxAcceptableType`s not this instanceof Array and not this instanceof JaxAcceptableStandardClass and - not this.getPackage().getName().matches("java.%") and + not this.getPackage().getName().startsWith("java.") and // Must not implement (directly or indirectly) the java.rmi.Remote interface. not this.getAnAncestor() instanceof TypeRemote and // The Java type of a public field must be a supported JAX-RPC type as specified in the section 5.1. diff --git a/java/ql/lib/semmle/code/java/frameworks/JoddJson.qll b/java/ql/lib/semmle/code/java/frameworks/JoddJson.qll index 3f28b2e8c7e4..f96b4b093b28 100644 --- a/java/ql/lib/semmle/code/java/frameworks/JoddJson.qll +++ b/java/ql/lib/semmle/code/java/frameworks/JoddJson.qll @@ -15,7 +15,7 @@ class JoddJsonParser extends RefType { class JoddJsonParseMethod extends Method { JoddJsonParseMethod() { this.getDeclaringType() instanceof JoddJsonParser and - this.getName().matches("parse%") + this.getName().startsWith("parse") } } diff --git a/java/ql/lib/semmle/code/java/frameworks/Lombok.qll b/java/ql/lib/semmle/code/java/frameworks/Lombok.qll index 84a890c498f8..b866b111a280 100644 --- a/java/ql/lib/semmle/code/java/frameworks/Lombok.qll +++ b/java/ql/lib/semmle/code/java/frameworks/Lombok.qll @@ -16,7 +16,7 @@ import java class LombokAnnotation extends Annotation { LombokAnnotation() { this.getType().getPackage().hasName("lombok") or - this.getType().getPackage().getName().matches("lombok.%") + this.getType().getPackage().getName().startsWith("lombok.") } } diff --git a/java/ql/lib/semmle/code/java/frameworks/Mockito.qll b/java/ql/lib/semmle/code/java/frameworks/Mockito.qll index 2613b0e5c51c..879fe7f672fb 100644 --- a/java/ql/lib/semmle/code/java/frameworks/Mockito.qll +++ b/java/ql/lib/semmle/code/java/frameworks/Mockito.qll @@ -13,7 +13,7 @@ import java */ class MockitoVerifyMethod extends Method { MockitoVerifyMethod() { - this.getDeclaringType().getPackage().getName().matches("org.mockito%") and + this.getDeclaringType().getPackage().getName().startsWith("org.mockito") and this.hasName("verify") } } @@ -88,7 +88,7 @@ class MockitoInitedTest extends Class { class MockitoAnnotation extends Annotation { MockitoAnnotation() { this.getType().getPackage().hasName("org.mockito") or - this.getType().getPackage().getName().matches("org.mockito.%") + this.getType().getPackage().getName().startsWith("org.mockito.") } } diff --git a/java/ql/lib/semmle/code/java/frameworks/Networking.qll b/java/ql/lib/semmle/code/java/frameworks/Networking.qll index 21df7ae7f8d2..65b686c16e0a 100644 --- a/java/ql/lib/semmle/code/java/frameworks/Networking.qll +++ b/java/ql/lib/semmle/code/java/frameworks/Networking.qll @@ -30,7 +30,7 @@ class TypeUrl extends RefType { /** Specifies that if a `URL` is tainted, then so are its synthetic fields. */ private class UrlFieldsInheritTaint extends DataFlow::SyntheticFieldContent, TaintInheritingContent { - UrlFieldsInheritTaint() { this.getField().matches("java.net.URL.%") } + UrlFieldsInheritTaint() { this.getField().startsWith("java.net.URL.") } } /** The type `java.net.URLDecoder`. */ diff --git a/java/ql/lib/semmle/code/java/frameworks/Properties.qll b/java/ql/lib/semmle/code/java/frameworks/Properties.qll index 50a13c236744..c4d3a2f72e7c 100644 --- a/java/ql/lib/semmle/code/java/frameworks/Properties.qll +++ b/java/ql/lib/semmle/code/java/frameworks/Properties.qll @@ -44,7 +44,7 @@ class PropertiesSetPropertyMethod extends Method { class PropertiesStoreMethod extends Method { PropertiesStoreMethod() { this.getDeclaringType() instanceof TypeProperty and - (this.getName().matches("store%") or this.getName() = "save") + (this.getName().startsWith("store") or this.getName() = "save") } } diff --git a/java/ql/lib/semmle/code/java/frameworks/android/Compose.qll b/java/ql/lib/semmle/code/java/frameworks/android/Compose.qll index 134e93ea4eb7..531964dae3ba 100644 --- a/java/ql/lib/semmle/code/java/frameworks/android/Compose.qll +++ b/java/ql/lib/semmle/code/java/frameworks/android/Compose.qll @@ -39,7 +39,7 @@ class LiveLiteral extends MethodCall { /** A live literal method. */ class LiveLiteralMethod extends Method { - LiveLiteralMethod() { this.getDeclaringType().getName().matches("LiveLiterals$%") } + LiveLiteralMethod() { this.getDeclaringType().getName().startsWith("LiveLiterals$") } } private predicate methodReturns(Method m, Expr res) { diff --git a/java/ql/lib/semmle/code/java/frameworks/android/Intent.qll b/java/ql/lib/semmle/code/java/frameworks/android/Intent.qll index b11e4e5d4ef8..eebc6e981d7d 100644 --- a/java/ql/lib/semmle/code/java/frameworks/android/Intent.qll +++ b/java/ql/lib/semmle/code/java/frameworks/android/Intent.qll @@ -117,7 +117,7 @@ class StartServiceMethod extends Method { private class IntentFieldsInheritTaint extends DataFlow::SyntheticFieldContent, TaintInheritingContent { - IntentFieldsInheritTaint() { this.getField().matches("android.content.Intent.%") } + IntentFieldsInheritTaint() { this.getField().startsWith("android.content.Intent.") } } /** The method `Intent.getParcelableExtra`. */ diff --git a/java/ql/lib/semmle/code/java/frameworks/android/SharedPreferences.qll b/java/ql/lib/semmle/code/java/frameworks/android/SharedPreferences.qll index a11857e9f1f4..31178ed32a79 100644 --- a/java/ql/lib/semmle/code/java/frameworks/android/SharedPreferences.qll +++ b/java/ql/lib/semmle/code/java/frameworks/android/SharedPreferences.qll @@ -46,7 +46,7 @@ class SharedPreferencesEditor extends Interface { class PutSharedPreferenceMethod extends Method { PutSharedPreferenceMethod() { this.getDeclaringType() instanceof SharedPreferencesEditor and - this.getName().matches("put%") + this.getName().startsWith("put") } } diff --git a/java/ql/lib/semmle/code/java/frameworks/android/XmlParsing.qll b/java/ql/lib/semmle/code/java/frameworks/android/XmlParsing.qll index 2235bc5eaecc..659b676fd3ff 100644 --- a/java/ql/lib/semmle/code/java/frameworks/android/XmlParsing.qll +++ b/java/ql/lib/semmle/code/java/frameworks/android/XmlParsing.qll @@ -10,7 +10,7 @@ class XmlPullParser extends Interface { class XmlPullGetMethod extends Method { XmlPullGetMethod() { this.getDeclaringType() instanceof XmlPullParser and - this.getName().matches("get%") + this.getName().startsWith("get") } } @@ -21,6 +21,6 @@ class XmlAttrSet extends Interface { class XmlAttrSetGetMethod extends Method { XmlAttrSetGetMethod() { this.getDeclaringType() instanceof XmlAttrSet and - this.getName().matches("get%") + this.getName().startsWith("get") } } diff --git a/java/ql/lib/semmle/code/java/frameworks/gigaspaces/GigaSpaces.qll b/java/ql/lib/semmle/code/java/frameworks/gigaspaces/GigaSpaces.qll index a03ed1c5266e..eab7fd30d4af 100644 --- a/java/ql/lib/semmle/code/java/frameworks/gigaspaces/GigaSpaces.qll +++ b/java/ql/lib/semmle/code/java/frameworks/gigaspaces/GigaSpaces.qll @@ -39,7 +39,7 @@ predicate isGigaSpacesEventMethod(Method eventMethod) { class GigaSpacesSpaceIdGetterMethod extends Method { GigaSpacesSpaceIdGetterMethod() { this.getAnAnnotation().getType().hasQualifiedName("com.gigaspaces.annotation.pojo", "SpaceId") and - this.getName().matches("get%") + this.getName().startsWith("get") } } @@ -50,7 +50,7 @@ class GigaSpacesSpaceIdSetterMethod extends Method { GigaSpacesSpaceIdSetterMethod() { exists(GigaSpacesSpaceIdGetterMethod getterMethod | getterMethod.getDeclaringType() = this.getDeclaringType() and - this.getName().matches("set%") + this.getName().startsWith("set") | getterMethod.getName().suffix(3) = this.getName().suffix(3) ) @@ -66,6 +66,6 @@ class GigaSpacesSpaceRoutingMethod extends Method { this.getAnAnnotation() .getType() .hasQualifiedName("com.gigaspaces.annotation.pojo", "SpaceRouting") and - this.getName().matches("get%") + this.getName().startsWith("get") } } diff --git a/java/ql/lib/semmle/code/java/frameworks/gwt/GWT.qll b/java/ql/lib/semmle/code/java/frameworks/gwt/GWT.qll index a58e49aa76f0..0c97f38b3d6b 100644 --- a/java/ql/lib/semmle/code/java/frameworks/gwt/GWT.qll +++ b/java/ql/lib/semmle/code/java/frameworks/gwt/GWT.qll @@ -67,9 +67,9 @@ class ClientSideGwtCompilationUnit extends GwtCompilationUnit { private predicate jsni(Javadoc jsni, File file, int startline) { // The comment must start with `-{` ... - jsni.getChild(0).getText().matches("-{%") and + jsni.getChild(0).getText().startsWith("-{") and // ... and it must end with `}-`. - jsni.getChild(jsni.getNumChild() - 1).getText().matches("%}-") and + jsni.getChild(jsni.getNumChild() - 1).getText().endsWith("}-") and file = jsni.getFile() and startline = jsni.getLocation().getStartLine() } diff --git a/java/ql/lib/semmle/code/java/frameworks/gwt/GwtUiBinderXml.qll b/java/ql/lib/semmle/code/java/frameworks/gwt/GwtUiBinderXml.qll index fef34f1bc44d..3197f678291c 100644 --- a/java/ql/lib/semmle/code/java/frameworks/gwt/GwtUiBinderXml.qll +++ b/java/ql/lib/semmle/code/java/frameworks/gwt/GwtUiBinderXml.qll @@ -8,7 +8,7 @@ import java /** A GWT UiBinder XML template file with a `.ui.xml` suffix. */ class GwtUiTemplateXmlFile extends XmlFile { - GwtUiTemplateXmlFile() { this.getBaseName().matches("%.ui.xml") } + GwtUiTemplateXmlFile() { this.getBaseName().endsWith(".ui.xml") } /** Gets the top-level UiBinder element. */ GwtUiBinderTemplateElement getUiBinderElement() { result = this.getAChild() } diff --git a/java/ql/lib/semmle/code/java/frameworks/gwt/GwtXml.qll b/java/ql/lib/semmle/code/java/frameworks/gwt/GwtXml.qll index b36824543005..c22eb0b5aab3 100644 --- a/java/ql/lib/semmle/code/java/frameworks/gwt/GwtXml.qll +++ b/java/ql/lib/semmle/code/java/frameworks/gwt/GwtXml.qll @@ -11,7 +11,7 @@ predicate isGwtXmlIncluded() { exists(GwtXmlFile webXml) } /** A GWT module XML file with a `.gwt.xml` suffix. */ class GwtXmlFile extends XmlFile { - GwtXmlFile() { this.getBaseName().matches("%.gwt.xml") } + GwtXmlFile() { this.getBaseName().endsWith(".gwt.xml") } /** Gets the top-level module element of a GWT module XML file. */ GwtModuleElement getModuleElement() { result = this.getAChild() } diff --git a/java/ql/lib/semmle/code/java/frameworks/j2objc/J2ObjC.qll b/java/ql/lib/semmle/code/java/frameworks/j2objc/J2ObjC.qll index abb24b909e97..a478c2c49f2f 100644 --- a/java/ql/lib/semmle/code/java/frameworks/j2objc/J2ObjC.qll +++ b/java/ql/lib/semmle/code/java/frameworks/j2objc/J2ObjC.qll @@ -12,9 +12,9 @@ import java class OcniComment extends Javadoc { OcniComment() { // The comment must start with `-[` ... - this.getChild(0).getText().matches("-[%") and + this.getChild(0).getText().startsWith("-[") and // ... and it must end with `]-`. - this.getChild(this.getNumChild() - 1).getText().matches("%]-") + this.getChild(this.getNumChild() - 1).getText().endsWith("]-") } } diff --git a/java/ql/lib/semmle/code/java/frameworks/jackson/JacksonSerializability.qll b/java/ql/lib/semmle/code/java/frameworks/jackson/JacksonSerializability.qll index b9fdbe58f77d..a98f3de42301 100644 --- a/java/ql/lib/semmle/code/java/frameworks/jackson/JacksonSerializability.qll +++ b/java/ql/lib/semmle/code/java/frameworks/jackson/JacksonSerializability.qll @@ -35,7 +35,7 @@ private class JacksonWriteValueMethod extends Method, TaintPreservingCallable { this.getDeclaringType().hasQualifiedName("com.fasterxml.jackson.databind", "ObjectWriter") or this.getDeclaringType().hasQualifiedName("com.fasterxml.jackson.databind", "ObjectMapper") ) and - this.getName().matches("writeValue%") and + this.getName().startsWith("writeValue") and this.getParameter(this.getNumberOfParameters() - 1).getType() instanceof TypeObject } diff --git a/java/ql/lib/semmle/code/java/frameworks/javaee/ejb/EJB.qll b/java/ql/lib/semmle/code/java/frameworks/javaee/ejb/EJB.qll index efbd0c0b1eb5..09c2caf2d3d7 100644 --- a/java/ql/lib/semmle/code/java/frameworks/javaee/ejb/EJB.qll +++ b/java/ql/lib/semmle/code/java/frameworks/javaee/ejb/EJB.qll @@ -350,7 +350,7 @@ class EjbAnnotatedInitMethod extends Method { */ class EjbCreateMethod extends Method { EjbCreateMethod() { - this.getName().matches("ejbCreate%") and + this.getName().startsWith("ejbCreate") and exists(SessionEjb ejb | ejb.inherits(this)) } @@ -364,7 +364,7 @@ class EjbCreateMethod extends Method { */ class EjbInterfaceCreateMethod extends Method { EjbInterfaceCreateMethod() { - this.getName().matches("create%") and + this.getName().startsWith("create") and exists(LegacyEjbHomeInterface i | i.inherits(this)) } diff --git a/java/ql/lib/semmle/code/java/frameworks/javaee/ejb/EJBRestrictions.qll b/java/ql/lib/semmle/code/java/frameworks/javaee/ejb/EJBRestrictions.qll index 478728168253..b2e8637c1e8a 100644 --- a/java/ql/lib/semmle/code/java/frameworks/javaee/ejb/EJBRestrictions.qll +++ b/java/ql/lib/semmle/code/java/frameworks/javaee/ejb/EJBRestrictions.qll @@ -150,7 +150,7 @@ ThisAccess forbiddenThisUse(Callable c) { class ReflectionPackage extends Package { ReflectionPackage() { this.getName() = "java.lang.reflect" or - this.getName().matches("java.lang.reflect.%") + this.getName().startsWith("java.lang.reflect.") } } @@ -158,7 +158,7 @@ class ReflectionPackage extends Package { class GraphicsPackage extends Package { GraphicsPackage() { this.getName() = "java.awt" or - this.getName().matches("java.awt.%") or + this.getName().startsWith("java.awt.") or this.getName() = javaxOrJakarta() + ".swing" or this.getName().matches(javaxOrJakarta() + ".swing.%") } @@ -168,7 +168,7 @@ class GraphicsPackage extends Package { class ConcurrentPackage extends Package { ConcurrentPackage() { this.getName() = "java.util.concurrent" or - this.getName().matches("java.util.concurrent.%") + this.getName().startsWith("java.util.concurrent.") } } diff --git a/java/ql/lib/semmle/code/java/frameworks/spring/SpringAutowire.qll b/java/ql/lib/semmle/code/java/frameworks/spring/SpringAutowire.qll index 970870f95037..ebded27ac5c7 100644 --- a/java/ql/lib/semmle/code/java/frameworks/spring/SpringAutowire.qll +++ b/java/ql/lib/semmle/code/java/frameworks/spring/SpringAutowire.qll @@ -97,7 +97,7 @@ class SpringBeanXmlAutowiredSetterMethod extends Method { // The resulting bean is of the right type. result.getClass().getAnAncestor() = this.getParameter(0).getType() and this.getNumberOfParameters() = 1 and - this.getName().matches("set%") + this.getName().startsWith("set") ) } } diff --git a/java/ql/lib/semmle/code/java/frameworks/spring/SpringProfile.qll b/java/ql/lib/semmle/code/java/frameworks/spring/SpringProfile.qll index 2d8a4577e567..fd7cc76035fe 100644 --- a/java/ql/lib/semmle/code/java/frameworks/spring/SpringProfile.qll +++ b/java/ql/lib/semmle/code/java/frameworks/spring/SpringProfile.qll @@ -40,7 +40,7 @@ class SpringProfileExpr extends string { * A Spring profile expression that begins with "!", indicating a negated expression. */ class NotSpringProfileExpr extends SpringProfileExpr { - NotSpringProfileExpr() { this.matches("!%") } + NotSpringProfileExpr() { this.startsWith("!") } /** * Gets the profile described in this profile expression. diff --git a/java/ql/lib/semmle/code/java/frameworks/stapler/Stapler.qll b/java/ql/lib/semmle/code/java/frameworks/stapler/Stapler.qll index d7563100d974..f70912f5bba2 100644 --- a/java/ql/lib/semmle/code/java/frameworks/stapler/Stapler.qll +++ b/java/ql/lib/semmle/code/java/frameworks/stapler/Stapler.qll @@ -23,7 +23,7 @@ class DataBoundAnnotated extends Callable { this = an.getAnnotatedElement() ) or - exists(Javadoc doc | doc.getAChild().getText().matches("%@stapler-constructor%") | + exists(Javadoc doc | doc.getAChild().getText().contains("@stapler-constructor") | doc.getCommentedElement() = this ) } diff --git a/java/ql/lib/semmle/code/java/frameworks/struts/StrutsActions.qll b/java/ql/lib/semmle/code/java/frameworks/struts/StrutsActions.qll index f5b5e345802a..c79dc0577610 100644 --- a/java/ql/lib/semmle/code/java/frameworks/struts/StrutsActions.qll +++ b/java/ql/lib/semmle/code/java/frameworks/struts/StrutsActions.qll @@ -138,7 +138,7 @@ class Struts2ActionSupportClass extends Class { result.isPublic() and exists(string name | result.getField().getName().toLowerCase() = name | result.getName().toLowerCase().substring(3, result.getName().length()) = name and - result.getName().matches("set%") + result.getName().startsWith("set") ) } } diff --git a/java/ql/lib/semmle/code/java/frameworks/struts/StrutsConventions.qll b/java/ql/lib/semmle/code/java/frameworks/struts/StrutsConventions.qll index ba70a59df59c..ac34b0e25fae 100644 --- a/java/ql/lib/semmle/code/java/frameworks/struts/StrutsConventions.qll +++ b/java/ql/lib/semmle/code/java/frameworks/struts/StrutsConventions.qll @@ -56,7 +56,7 @@ private predicate isStrutsConventionPluginUsed(RefType refType) { strutsConventionAnnotationUsedInFolder(getSourceFolder(refType.getCompilationUnit())) or // The struts configuration file for this file sets a convention property - getRootXmlFile(refType).getAConstant().getName().matches("struts.convention%") + getRootXmlFile(refType).getAConstant().getName().startsWith("struts.convention") or // We've found the POM for this RefType, and it includes a dependency on the convention plugin exists(Pom pom | diff --git a/java/ql/lib/semmle/code/java/security/AndroidCertificatePinningQuery.qll b/java/ql/lib/semmle/code/java/security/AndroidCertificatePinningQuery.qll index 7130e41eeb7e..6ce0b5a3a776 100644 --- a/java/ql/lib/semmle/code/java/security/AndroidCertificatePinningQuery.qll +++ b/java/ql/lib/semmle/code/java/security/AndroidCertificatePinningQuery.qll @@ -107,7 +107,7 @@ private class MissingPinningSink extends DataFlow::Node { private module UntrustedUrlConfig implements DataFlow::ConfigSig { predicate isSource(DataFlow::Node node) { exists(string lit | lit = node.asExpr().(CompileTimeConstantExpr).getStringValue() | - lit.matches("%://%") and // it's a URL + lit.contains("://") and // it's a URL not lit.regexpMatch("^(classpath|file|jar):.*") and // discard non-network URIs not exists(string dom | trustedDomain(dom) and lit.matches("%" + dom + "%")) ) diff --git a/java/ql/lib/semmle/code/java/security/ArbitraryApkInstallation.qll b/java/ql/lib/semmle/code/java/security/ArbitraryApkInstallation.qll index 8600ecda7ad1..5195777424a8 100644 --- a/java/ql/lib/semmle/code/java/security/ArbitraryApkInstallation.qll +++ b/java/ql/lib/semmle/code/java/security/ArbitraryApkInstallation.qll @@ -76,7 +76,7 @@ class ExternalApkSource extends ApiSourceNode { ExternalApkSource() { sourceNode(this, "android-external-storage-dir") or this.asExpr().(MethodCall).getMethod() instanceof UriConstructorMethod or - this.asExpr().(StringLiteral).getValue().matches("file://%") or + this.asExpr().(StringLiteral).getValue().startsWith("file://") or this instanceof ActiveThreatModelSource } } diff --git a/java/ql/lib/semmle/code/java/security/CommandArguments.qll b/java/ql/lib/semmle/code/java/security/CommandArguments.qll index 1ac42192e040..5f089c12913d 100644 --- a/java/ql/lib/semmle/code/java/security/CommandArguments.qll +++ b/java/ql/lib/semmle/code/java/security/CommandArguments.qll @@ -69,7 +69,7 @@ private class CommandArgumentList extends SsaExplicitWrite { CommandArgumentList() { this.getSourceVariable().getType() instanceof ListOfStringType and forex(CollectionMutation ma | ma.getQualifier() = this.getARead() | - ma.getMethod().getName().matches("add%") + ma.getMethod().getName().startsWith("add") ) } @@ -92,7 +92,7 @@ private class CommandArgumentList extends SsaExplicitWrite { */ MethodCall getAnAdd() { result.getQualifier() = this.getARead() and - result.getMethod().getName().matches("add%") + result.getMethod().getName().startsWith("add") } /** Gets an addition to this list which could be its first element. */ diff --git a/java/ql/lib/semmle/code/java/security/ControlledString.qll b/java/ql/lib/semmle/code/java/security/ControlledString.qll index fa201b2e8b6f..05c33c3f7576 100644 --- a/java/ql/lib/semmle/code/java/security/ControlledString.qll +++ b/java/ql/lib/semmle/code/java/security/ControlledString.qll @@ -24,7 +24,7 @@ private predicate boxedToString(Method method) { * it is better to use a prepared query than to just put single quotes around the string. */ predicate endsInQuote(Expr expr) { - exists(string str | str = expr.(StringLiteral).getValue() | str.matches("%'")) + exists(string str | str = expr.(StringLiteral).getValue() | str.endsWith("'")) or exists(Variable var | expr = var.getAnAccess() | endsInQuote(var.getAnAssignedValue())) or diff --git a/java/ql/lib/semmle/code/java/security/ExternalAPIs.qll b/java/ql/lib/semmle/code/java/security/ExternalAPIs.qll index df941be97448..d74166eb202e 100644 --- a/java/ql/lib/semmle/code/java/security/ExternalAPIs.qll +++ b/java/ql/lib/semmle/code/java/security/ExternalAPIs.qll @@ -29,7 +29,7 @@ private class DefaultSafeExternalApiMethod extends SafeExternalApiMethod { or this.getDeclaringType().hasQualifiedName("com.google.common.base", "Preconditions") or - this.getDeclaringType().getPackage().getName().matches("org.junit%") + this.getDeclaringType().getPackage().getName().startsWith("org.junit") or this.getDeclaringType().hasQualifiedName("com.google.common.base", "Strings") and this.getName() = "isNullOrEmpty" diff --git a/java/ql/lib/semmle/code/java/security/HttpsUrls.qll b/java/ql/lib/semmle/code/java/security/HttpsUrls.qll index 071f95b49902..396838f90ba7 100644 --- a/java/ql/lib/semmle/code/java/security/HttpsUrls.qll +++ b/java/ql/lib/semmle/code/java/security/HttpsUrls.qll @@ -17,7 +17,7 @@ class HttpStringLiteral extends StringLiteral { exists(string s | this.getValue() = s | s = "http" or - s.matches("http://%") and + s.startsWith("http://") and not s.substring(7, s.length()) instanceof PrivateHostName and not TaintTracking::localExprTaint(any(StringLiteral p | p.getValue() instanceof PrivateHostName diff --git a/java/ql/lib/semmle/code/java/security/InsecureBasicAuth.qll b/java/ql/lib/semmle/code/java/security/InsecureBasicAuth.qll index 9d26077396bf..9284ce512363 100644 --- a/java/ql/lib/semmle/code/java/security/InsecureBasicAuth.qll +++ b/java/ql/lib/semmle/code/java/security/InsecureBasicAuth.qll @@ -44,5 +44,5 @@ private class DefaultInsecureBasicAuthSink extends InsecureBasicAuthSink { * String pattern of basic authentication. */ private class BasicAuthString extends StringLiteral { - BasicAuthString() { exists(string s | this.getValue() = s | s.matches("Basic %")) } + BasicAuthString() { exists(string s | this.getValue() = s | s.startsWith("Basic ")) } } diff --git a/java/ql/lib/semmle/code/java/security/InsecureRandomnessQuery.qll b/java/ql/lib/semmle/code/java/security/InsecureRandomnessQuery.qll index 524de13513ce..c745f863b700 100644 --- a/java/ql/lib/semmle/code/java/security/InsecureRandomnessQuery.qll +++ b/java/ql/lib/semmle/code/java/security/InsecureRandomnessQuery.qll @@ -80,7 +80,7 @@ module InsecureRandomnessConfig implements DataFlow::ConfigSig { or exists(MethodCall mc, string methodName | mc.getMethod().hasQualifiedName("org.owasp.esapi", "Encoder", methodName) and - methodName.matches("encode%") + methodName.startsWith("encode") | n1.asExpr() = mc.getArgument(0) and n2.asExpr() = mc diff --git a/java/ql/lib/semmle/code/java/security/InsufficientKeySize.qll b/java/ql/lib/semmle/code/java/security/InsufficientKeySize.qll index 6d28a124b854..355d60c3b5d2 100644 --- a/java/ql/lib/semmle/code/java/security/InsufficientKeySize.qll +++ b/java/ql/lib/semmle/code/java/security/InsufficientKeySize.qll @@ -156,7 +156,7 @@ private module Asymmetric { private class Sink extends InsufficientKeySizeSink { Sink() { exists(KeyPairGenInit kpgInit, KeyPairGen kpg | - kpg.getAlgoName().matches("EC%") and + kpg.getAlgoName().startsWith("EC") and DataFlow::localExprFlow(kpg, kpgInit.getQualifier()) and this.asExpr() = kpgInit.getKeySizeArg() ) @@ -175,10 +175,10 @@ private module Asymmetric { /** Returns the key size from an EC algorithm's curve name string */ bindingset[algorithm] private int getKeySize(string algorithm) { - algorithm.matches("sec%") and // specification such as "secp256r1" + algorithm.startsWith("sec") and // specification such as "secp256r1" result = algorithm.regexpCapture("sec[p|t](\\d+)[a-zA-Z].*", 1).toInt() or - algorithm.matches("X9.62%") and // specification such as "X9.62 prime192v2" + algorithm.startsWith("X9.62") and // specification such as "X9.62 prime192v2" result = algorithm.regexpCapture("X9\\.62 .*[a-zA-Z](\\d+)[a-zA-Z].*", 1).toInt() or algorithm.matches(["prime%", "c2tnb%"]) and // specification such as "prime192v2" diff --git a/java/ql/lib/semmle/code/java/security/Mail.qll b/java/ql/lib/semmle/code/java/security/Mail.qll index 5c68355ec3ee..5c1d9424a25b 100644 --- a/java/ql/lib/semmle/code/java/security/Mail.qll +++ b/java/ql/lib/semmle/code/java/security/Mail.qll @@ -17,16 +17,16 @@ predicate isInsecureMailPropertyConfig(Variable properties) { ma.getMethod() instanceof SetPropertyMethod and ma.getQualifier() = properties.getAnAccess() | - getStringValue(ma.getArgument(0)).matches("%.auth%") and //mail.smtp.auth + getStringValue(ma.getArgument(0)).contains(".auth") and //mail.smtp.auth getStringValue(ma.getArgument(1)) = "true" or - getStringValue(ma.getArgument(0)).matches("%.socketFactory%") //mail.smtp.socketFactory or mail.smtp.socketFactory.class + getStringValue(ma.getArgument(0)).contains(".socketFactory") //mail.smtp.socketFactory or mail.smtp.socketFactory.class ) and not exists(MethodCall ma | ma.getMethod() instanceof SetPropertyMethod and ma.getQualifier() = properties.getAnAccess() | - getStringValue(ma.getArgument(0)).matches("%.ssl.checkserveridentity%") and //mail.smtp.ssl.checkserveridentity + getStringValue(ma.getArgument(0)).contains(".ssl.checkserveridentity") and //mail.smtp.ssl.checkserveridentity getStringValue(ma.getArgument(1)) = "true" ) } diff --git a/java/ql/lib/semmle/code/java/security/PartialPathTraversal.qll b/java/ql/lib/semmle/code/java/security/PartialPathTraversal.qll index a7b0c50b0827..abba60913857 100644 --- a/java/ql/lib/semmle/code/java/security/PartialPathTraversal.qll +++ b/java/ql/lib/semmle/code/java/security/PartialPathTraversal.qll @@ -32,7 +32,7 @@ private class SystemPropFileSeparatorExpr extends FileSeparatorExpr { private class StringLiteralFileSeparatorExpr extends FileSeparatorExpr, StringLiteral { StringLiteralFileSeparatorExpr() { - this.getValue().matches("%/") or this.getValue().matches("%\\") + this.getValue().endsWith("/") or this.getValue().matches("%\\") } } diff --git a/java/ql/lib/semmle/code/java/security/PathSanitizer.qll b/java/ql/lib/semmle/code/java/security/PathSanitizer.qll index 6648f1b948e8..0d7e0af77385 100644 --- a/java/ql/lib/semmle/code/java/security/PathSanitizer.qll +++ b/java/ql/lib/semmle/code/java/security/PathSanitizer.qll @@ -209,7 +209,7 @@ private predicate isStringPrefixMatch(MethodCall ma) { getVisualArgument(ma, 0).(CompileTimeConstantExpr).getIntValue() = 0 or m.hasName("matches") and - not getVisualArgument(ma, 0).(ConstantOrRegex).getStringValue().matches(".*%") + not getVisualArgument(ma, 0).(ConstantOrRegex).getStringValue().startsWith(".*") ) } @@ -410,9 +410,9 @@ private predicate replacesDirectoryCharactersWithSingleReplaceAll(StringReplacem // Search for "\\\\" (needs extra backslashes to avoid escaping the '%') targetValue.matches("[%\\\\\\\\%]") or - targetValue.matches("%|%") and + targetValue.contains("|") and targetValue.matches("%" + ["[.]", "\\."] + "%") and - targetValue.matches("%/%") and + targetValue.contains("/") and targetValue.matches("%\\\\\\\\%") ) } @@ -464,7 +464,7 @@ private predicate replacesDirectoryCharactersWithDoubleReplaceOrReplaceAll(Strin targetValue2 != targetValue1 and // make sure one of the calls replaces '.' // then the other call must replace one of '/' or '\' if they are not equal - (targetValue2.matches("%.%") or targetValue1.matches("%.%")) + (targetValue2.contains(".") or targetValue1.contains(".")) ) } diff --git a/java/ql/lib/semmle/code/java/security/RandomDataSource.qll b/java/ql/lib/semmle/code/java/security/RandomDataSource.qll index f040c858d9ce..a9910157c836 100644 --- a/java/ql/lib/semmle/code/java/security/RandomDataSource.qll +++ b/java/ql/lib/semmle/code/java/security/RandomDataSource.qll @@ -60,7 +60,7 @@ class StdlibRandomSource extends RandomDataSource { StdlibRandomSource() { m = this.getMethod() and - m.getName().matches("next%") and + m.getName().startsWith("next") and m.getDeclaringType().getAnAncestor().hasQualifiedName("java.util", "Random") } @@ -131,7 +131,7 @@ class ApacheCommonsRandomSource extends RandomDataSource { ApacheCommonsRandomSource() { m = this.getMethod() and - m.getName().matches("next%") and + m.getName().startsWith("next") and m.getDeclaringType().hasQualifiedName("org.apache.commons.lang3", "RandomUtils") } @@ -165,7 +165,7 @@ class ApacheCommonsRandomSource extends RandomDataSource { class ApacheCommonsRandomStringSource extends RandomDataSource { ApacheCommonsRandomStringSource() { exists(Method m | m = this.getMethod() | - m.getName().matches("random%") and + m.getName().startsWith("random") and m.getDeclaringType() .hasQualifiedName(["org.apache.commons.lang3", "org.apache.commons.lang"], "RandomStringUtils") diff --git a/java/ql/lib/semmle/code/java/security/RandomQuery.qll b/java/ql/lib/semmle/code/java/security/RandomQuery.qll index 88f8611379ca..63d4d62968af 100644 --- a/java/ql/lib/semmle/code/java/security/RandomQuery.qll +++ b/java/ql/lib/semmle/code/java/security/RandomQuery.qll @@ -70,7 +70,7 @@ private predicate predictableCalcStep(Expr e1, Expr e2) { ( m.getName().matches("to%String") or m.getName() = "toByteArray" or - m.getName().matches("%Value") + m.getName().endsWith("Value") ) ) or @@ -80,8 +80,8 @@ private predicate predictableCalcStep(Expr e1, Expr e2) { m = ma.getMethod() and exists(TypeNumber t | hasDescendant(t, m.getDeclaringType())) and ( - m.getName().matches("parse%") or - m.getName().matches("valueOf%") or + m.getName().startsWith("parse") or + m.getName().startsWith("valueOf") or m.getName().matches("to%String") ) ) diff --git a/java/ql/lib/semmle/code/java/security/RsaWithoutOaepQuery.qll b/java/ql/lib/semmle/code/java/security/RsaWithoutOaepQuery.qll index a57cf1d55a5d..9113b1de6a6b 100644 --- a/java/ql/lib/semmle/code/java/security/RsaWithoutOaepQuery.qll +++ b/java/ql/lib/semmle/code/java/security/RsaWithoutOaepQuery.qll @@ -12,8 +12,8 @@ module RsaWithoutOaepConfig implements DataFlow::ConfigSig { exists(CompileTimeConstantExpr specExpr, string spec | specExpr.getStringValue().toUpperCase() = spec and specExpr = src.asExpr() and - spec.matches("RSA/%") and - not spec.matches("%OAEP%") + spec.startsWith("RSA/") and + not spec.contains("OAEP") ) } diff --git a/java/ql/lib/semmle/code/java/security/SecurityTests.qll b/java/ql/lib/semmle/code/java/security/SecurityTests.qll index d8b714c18a1e..3bfd3bd2662f 100644 --- a/java/ql/lib/semmle/code/java/security/SecurityTests.qll +++ b/java/ql/lib/semmle/code/java/security/SecurityTests.qll @@ -8,9 +8,9 @@ import java class NonSecurityTestClass extends TestClass { NonSecurityTestClass() { not exists(RefType s | this.getAnAncestor().getSourceDeclaration() = s and s.fromSource() | - s.getLocation().getFile().getAbsolutePath().matches("%semmle%") or - s.getLocation().getFile().getAbsolutePath().matches("%ql/java/ql/test/%") or - s.getLocation().getFile().getAbsolutePath().matches("%CWE%") + s.getLocation().getFile().getAbsolutePath().contains("semmle") or + s.getLocation().getFile().getAbsolutePath().contains("ql/java/ql/test/") or + s.getLocation().getFile().getAbsolutePath().contains("CWE") ) } } diff --git a/java/ql/lib/semmle/code/java/security/SensitiveActions.qll b/java/ql/lib/semmle/code/java/security/SensitiveActions.qll index 86ff96c19172..c0a413278218 100644 --- a/java/ql/lib/semmle/code/java/security/SensitiveActions.qll +++ b/java/ql/lib/semmle/code/java/security/SensitiveActions.qll @@ -117,7 +117,7 @@ class AuthMethod extends SensitiveExecutionMethod { /** A method that sends data, and so should not be run conditionally on user input. */ class SendingMethod extends SensitiveExecutionMethod { SendingMethod() { - exists(string s | s.matches("%Socket") | + exists(string s | s.endsWith("Socket") | this.getDeclaringType().hasQualifiedName("java.net", s) and this.hasName("send") ) diff --git a/java/ql/lib/semmle/code/java/security/SensitiveKeyboardCacheQuery.qll b/java/ql/lib/semmle/code/java/security/SensitiveKeyboardCacheQuery.qll index 610fb4d6b4de..e9c145b7affa 100644 --- a/java/ql/lib/semmle/code/java/security/SensitiveKeyboardCacheQuery.qll +++ b/java/ql/lib/semmle/code/java/security/SensitiveKeyboardCacheQuery.qll @@ -18,9 +18,9 @@ private Argument setInputTypeForId(string id) { private predicate inputTypeFieldNotCached(Field f) { f.getDeclaringType().hasQualifiedName("android.text", "InputType") and ( - not f.getName().matches("%TEXT%") + not f.getName().contains("TEXT") or - f.getName().matches("%PASSWORD%") + f.getName().contains("PASSWORD") or f.hasName("TYPE_TEXT_FLAG_NO_SUGGESTIONS") ) @@ -56,7 +56,7 @@ private string getInputSensitiveInfoRegex() { /** Holds if input using the given input type (as written in XML) is not stored in the keyboard cache. */ bindingset[ty] private predicate inputTypeNotCached(string ty) { - not ty.matches("%text%") + not ty.contains("text") or ty.regexpMatch("(?i).*(nosuggestions|password).*") } diff --git a/java/ql/lib/semmle/code/java/security/SpringBootActuatorsConfigQuery.qll b/java/ql/lib/semmle/code/java/security/SpringBootActuatorsConfigQuery.qll index 163cd46d5d86..2825fb21dc1a 100644 --- a/java/ql/lib/semmle/code/java/security/SpringBootActuatorsConfigQuery.qll +++ b/java/ql/lib/semmle/code/java/security/SpringBootActuatorsConfigQuery.qll @@ -115,11 +115,11 @@ predicate exposesSensitiveEndpoint( ep.getValue() = "*" or // version 2.x: exposes health and info only by default - springBootVersion.matches("2.%") and + springBootVersion.startsWith("2.") and not ep.getValue() = ["health", "info"] or // version 3.x: exposes health only by default - springBootVersion.matches("3.%") and + springBootVersion.startsWith("3.") and not ep.getValue() = "health" ) ) diff --git a/java/ql/lib/semmle/code/java/security/StaticInitializationVectorQuery.qll b/java/ql/lib/semmle/code/java/security/StaticInitializationVectorQuery.qll index e97a31614999..cc65a83d5e83 100644 --- a/java/ql/lib/semmle/code/java/security/StaticInitializationVectorQuery.qll +++ b/java/ql/lib/semmle/code/java/security/StaticInitializationVectorQuery.qll @@ -73,7 +73,7 @@ private class ArrayUpdate extends Expr { m.hasQualifiedName("org.apache.commons.io", "IOUtils", ["read", "readFully"]) or m.hasQualifiedName("io.netty.buffer", "ByteBuf", "getBytes") or m.hasQualifiedName("org.bouncycastle.crypto.generators", - any(string s | s.matches("%BytesGenerator")), "generateBytes") + any(string s | s.endsWith("BytesGenerator")), "generateBytes") ) } diff --git a/java/ql/lib/semmle/code/java/security/TaintedPermissionsCheckQuery.qll b/java/ql/lib/semmle/code/java/security/TaintedPermissionsCheckQuery.qll index 7113c7036e4c..ec2e95e88660 100644 --- a/java/ql/lib/semmle/code/java/security/TaintedPermissionsCheckQuery.qll +++ b/java/ql/lib/semmle/code/java/security/TaintedPermissionsCheckQuery.qll @@ -34,7 +34,7 @@ private class PermissionsCheckMethodCall extends MethodCall, PermissionsConstruc m.getDeclaringType() instanceof TypeShiroSubject and m.getName() = "isPermitted" or - m.getName().toLowerCase().matches("%permitted%") and + m.getName().toLowerCase().contains("permitted") and m.getNumberOfParameters() = 1 ) } diff --git a/java/ql/lib/semmle/code/java/security/XSS.qll b/java/ql/lib/semmle/code/java/security/XSS.qll index b094346b753e..3c3993bcf2bc 100644 --- a/java/ql/lib/semmle/code/java/security/XSS.qll +++ b/java/ql/lib/semmle/code/java/security/XSS.qll @@ -95,7 +95,7 @@ private class WritingMethod extends Method { WritingMethod() { this.getDeclaringType().getAnAncestor().hasQualifiedName("java.io", _) and ( - this.getName().matches("print%") or + this.getName().startsWith("print") or this.getName() = "append" or this.getName() = "format" or this.getName() = "write" diff --git a/java/ql/lib/semmle/code/java/security/regexp/PolynomialReDoSQuery.qll b/java/ql/lib/semmle/code/java/security/regexp/PolynomialReDoSQuery.qll index 767ebc97437b..806e456ec568 100644 --- a/java/ql/lib/semmle/code/java/security/regexp/PolynomialReDoSQuery.qll +++ b/java/ql/lib/semmle/code/java/security/regexp/PolynomialReDoSQuery.qll @@ -25,10 +25,10 @@ private class LengthRestrictedMethod extends Method { LengthRestrictedMethod() { this.getName().toLowerCase().matches(["%header%", "%requesturi%", "%requesturl%", "%cookie%"]) or - this.getDeclaringType().getName().toLowerCase().matches("%cookie%") and - this.getName().matches("get%") + this.getDeclaringType().getName().toLowerCase().contains("cookie") and + this.getName().startsWith("get") or - this.getDeclaringType().getName().toLowerCase().matches("%request%") and + this.getDeclaringType().getName().toLowerCase().contains("request") and this.getName().toLowerCase().matches(["%get%path%", "get%user%", "%querystring%"]) } } diff --git a/java/ql/lib/semmle/code/xml/AndroidManifest.qll b/java/ql/lib/semmle/code/xml/AndroidManifest.qll index d20165a031ff..dda92657c8f9 100644 --- a/java/ql/lib/semmle/code/xml/AndroidManifest.qll +++ b/java/ql/lib/semmle/code/xml/AndroidManifest.qll @@ -24,7 +24,7 @@ class AndroidManifestXmlFile extends XmlFile { /** * Holds if this Android manifest file is located in a build directory. */ - predicate isInBuildDirectory() { this.getFile().getRelativePath().matches("%build%") } + predicate isInBuildDirectory() { this.getFile().getRelativePath().contains("build") } /** * Holds if this file defines at least one activity, service or contest provider, @@ -319,7 +319,7 @@ class AndroidComponentXmlElement extends XmlElement { */ string getResolvedIdentifier(AndroidIdentifierXmlAttribute identifier) { exists(string name | name = identifier.getValue() | - if name.matches(".%") + if name.startsWith(".") then result = this.getParent() diff --git a/java/ql/lib/semmle/code/xml/MavenPom.qll b/java/ql/lib/semmle/code/xml/MavenPom.qll index 68c81c4ab905..06bed8f1a6e1 100644 --- a/java/ql/lib/semmle/code/xml/MavenPom.qll +++ b/java/ql/lib/semmle/code/xml/MavenPom.qll @@ -133,7 +133,7 @@ class Pom extends ProtoPom { * occurs by considering the properties defined by this project or an ancestor project. */ string resolvePlaceholder(string name) { - if name.matches("project.%") + if name.startsWith("project.") then exists(PomElement p | p = this.getProjectProperty() and @@ -289,7 +289,7 @@ class PomElement extends XmlElement { string getValue() { exists(string s | s = this.allCharactersString() and - if s.matches("${%") + if s.startsWith("${") then // Resolve the placeholder in the parent POM result = this.getParent*().(Pom).resolvePlaceholder(s.substring(2, s.length() - 1)) diff --git a/java/ql/src/Architecture/Dependencies/MutualDependency.ql b/java/ql/src/Architecture/Dependencies/MutualDependency.ql index 6d66daf1c67e..8bbc79503232 100644 --- a/java/ql/src/Architecture/Dependencies/MutualDependency.ql +++ b/java/ql/src/Architecture/Dependencies/MutualDependency.ql @@ -26,10 +26,10 @@ where t1 instanceof BoundedType or t2 instanceof AnonymousClass or t2 instanceof BoundedType or - t1.getName().toLowerCase().matches("%visitor%") or - t2.getName().toLowerCase().matches("%visitor%") or - t1.getAMethod().getName().toLowerCase().matches("%visit%") or - t2.getAMethod().getName().toLowerCase().matches("%visit%") or + t1.getName().toLowerCase().contains("visitor") or + t2.getName().toLowerCase().contains("visitor") or + t1.getAMethod().getName().toLowerCase().contains("visit") or + t2.getAMethod().getName().toLowerCase().contains("visit") or t1.getPackage() = t2.getPackage() or t1.getFile().isKotlinSourceFile() or t2.getFile().isKotlinSourceFile() diff --git a/java/ql/src/Likely Bugs/Comparison/HashedButNoHash.ql b/java/ql/src/Likely Bugs/Comparison/HashedButNoHash.ql index bb370bead3b5..db255e3362a8 100644 --- a/java/ql/src/Likely Bugs/Comparison/HashedButNoHash.ql +++ b/java/ql/src/Likely Bugs/Comparison/HashedButNoHash.ql @@ -37,7 +37,7 @@ predicate hashingMethod(Method m) { /** Holds if `e` is an expression in which `t` is used in a hashing data structure. */ predicate usedInHash(RefType t, Expr e) { exists(RefType s | - s.getName().matches("%Hash%") and not s.getSourceDeclaration().getName() = "IdentityHashMap" + s.getName().contains("Hash") and not s.getSourceDeclaration().getName() = "IdentityHashMap" | exists(MethodCall ma | ma.getQualifier().getType() = s and diff --git a/java/ql/src/Likely Bugs/Comparison/IncomparableEquals.ql b/java/ql/src/Likely Bugs/Comparison/IncomparableEquals.ql index cf75399caf45..06b4d1f98bbb 100644 --- a/java/ql/src/Likely Bugs/Comparison/IncomparableEquals.ql +++ b/java/ql/src/Likely Bugs/Comparison/IncomparableEquals.ql @@ -24,7 +24,7 @@ class EqualsCall extends MethodCall { */ predicate whitelisted() { // Allow tests and assertions to verify that `equals` methods return `false`. - this.getParent*().(MethodCall).getMethod().getName().matches("assert%") or + this.getParent*().(MethodCall).getMethod().getName().startsWith("assert") or this.getEnclosingStmt() instanceof AssertStmt } diff --git a/java/ql/src/Likely Bugs/Concurrency/BusyWait.ql b/java/ql/src/Likely Bugs/Concurrency/BusyWait.ql index 2cba4d10f035..31e0af006291 100644 --- a/java/ql/src/Likely Bugs/Concurrency/BusyWait.ql +++ b/java/ql/src/Likely Bugs/Concurrency/BusyWait.ql @@ -35,7 +35,7 @@ class WaitMethod extends Method { } class ConcurrentMethod extends Method { - ConcurrentMethod() { this.getDeclaringType().getQualifiedName().matches("java.util.concurrent%") } + ConcurrentMethod() { this.getDeclaringType().getQualifiedName().startsWith("java.util.concurrent") } } class CommunicationMethod extends Method { diff --git a/java/ql/src/Likely Bugs/Concurrency/SynchSetUnsynchGet.ql b/java/ql/src/Likely Bugs/Concurrency/SynchSetUnsynchGet.ql index 642a3f5e46fe..61e6b45916df 100644 --- a/java/ql/src/Likely Bugs/Concurrency/SynchSetUnsynchGet.ql +++ b/java/ql/src/Likely Bugs/Concurrency/SynchSetUnsynchGet.ql @@ -46,7 +46,7 @@ predicate bothAccessVolatileField(Method set, Method get) { from Method set, Method get where set.getDeclaringType() = get.getDeclaringType() and - set.getName().matches("set%") and + set.getName().startsWith("set") and get.getName() = "get" + set.getName().substring(3, set.getName().length()) and set.isSynchronized() and not (get.isSynchronized() or isSynchronizedByBlock(get)) and diff --git a/java/ql/src/Likely Bugs/Frameworks/Swing/BadlyOverriddenAdapter.ql b/java/ql/src/Likely Bugs/Frameworks/Swing/BadlyOverriddenAdapter.ql index 34fd190ccf11..2e6906bf10aa 100644 --- a/java/ql/src/Likely Bugs/Frameworks/Swing/BadlyOverriddenAdapter.ql +++ b/java/ql/src/Likely Bugs/Frameworks/Swing/BadlyOverriddenAdapter.ql @@ -16,7 +16,7 @@ import java class Adapter extends Class { Adapter() { - this.getName().matches("%Adapter") and + this.getName().endsWith("Adapter") and ( this.getPackage().hasName("java.awt.event") or this.getPackage().hasName(javaxOrJakarta() + ".swing.event") diff --git a/java/ql/src/Likely Bugs/Likely Typos/SuspiciousDateFormat.ql b/java/ql/src/Likely Bugs/Likely Typos/SuspiciousDateFormat.ql index 1e97c4250d97..1b3f92d6cdaa 100644 --- a/java/ql/src/Likely Bugs/Likely Typos/SuspiciousDateFormat.ql +++ b/java/ql/src/Likely Bugs/Likely Typos/SuspiciousDateFormat.ql @@ -16,6 +16,6 @@ from ConstructorCall c, string format where c.getConstructedType().hasQualifiedName("java.text", "SimpleDateFormat") and format = c.getArgument(0).(StringLiteral).getValue() and - format.matches("%Y%") and - format.matches("%M%") + format.contains("Y") and + format.contains("M") select c, "Date formatter is passed a suspicious pattern \"" + format + "\"." diff --git a/java/ql/src/Likely Bugs/Resource Leaks/CloseType.qll b/java/ql/src/Likely Bugs/Resource Leaks/CloseType.qll index aca95c9bc1f5..5f102f6d91c6 100644 --- a/java/ql/src/Likely Bugs/Resource Leaks/CloseType.qll +++ b/java/ql/src/Likely Bugs/Resource Leaks/CloseType.qll @@ -219,7 +219,7 @@ private predicate closeCalled(LocalScopeVariable v) { or // Otherwise, there should be an explicit call to a method whose name contains "close". exists(MethodCall e | - e.getMethod().getName().toLowerCase().matches("%close%") and + e.getMethod().getName().toLowerCase().contains("close") and exists(VarAccess va | va = v.getAnAccess() | e.getQualifier() = va or e.getAnArgument() = va diff --git a/java/ql/src/Likely Bugs/Statements/InconsistentCallOnResult.ql b/java/ql/src/Likely Bugs/Statements/InconsistentCallOnResult.ql index fe47661def4b..259f4dedf989 100644 --- a/java/ql/src/Likely Bugs/Statements/InconsistentCallOnResult.ql +++ b/java/ql/src/Likely Bugs/Statements/InconsistentCallOnResult.ql @@ -19,10 +19,10 @@ import Chaining predicate exclude(Method m) { exists(string name | name = m.getName().toLowerCase() | - name.matches("get%") or - name.matches("is%") or - name.matches("has%") or - name.matches("add%") + name.startsWith("get") or + name.startsWith("is") or + name.startsWith("has") or + name.startsWith("add") ) } diff --git a/java/ql/src/Security/CWE/CWE-1004/SensitiveCookieNotHttpOnly.ql b/java/ql/src/Security/CWE/CWE-1004/SensitiveCookieNotHttpOnly.ql index afa08fb6928e..963dd1e27501 100644 --- a/java/ql/src/Security/CWE/CWE-1004/SensitiveCookieNotHttpOnly.ql +++ b/java/ql/src/Security/CWE/CWE-1004/SensitiveCookieNotHttpOnly.ql @@ -65,7 +65,7 @@ class SetCookieRawHeaderMethodCall extends MethodCall { */ module MatchesHttpOnlyToRawHeaderConfig implements DataFlow::ConfigSig { predicate isSource(DataFlow::Node source) { - source.asExpr().(CompileTimeConstantExpr).getStringValue().toLowerCase().matches("%httponly%") + source.asExpr().(CompileTimeConstantExpr).getStringValue().toLowerCase().contains("httponly") } predicate isSink(DataFlow::Node sink) { diff --git a/java/ql/src/Security/CWE/CWE-1104/MavenPomDependsOnBintray.ql b/java/ql/src/Security/CWE/CWE-1104/MavenPomDependsOnBintray.ql index cfa36f5a5823..3d0e6738c7b7 100644 --- a/java/ql/src/Security/CWE/CWE-1104/MavenPomDependsOnBintray.ql +++ b/java/ql/src/Security/CWE/CWE-1104/MavenPomDependsOnBintray.ql @@ -14,7 +14,7 @@ import java import semmle.code.xml.MavenPom predicate isBintrayRepositoryUsage(DeclaredRepository repository) { - repository.getRepositoryUrl().matches("%.bintray.com%") + repository.getRepositoryUrl().contains(".bintray.com") } from DeclaredRepository repository diff --git a/java/ql/src/Security/CWE/CWE-338/JHipsterGeneratedPRNG.ql b/java/ql/src/Security/CWE/CWE-338/JHipsterGeneratedPRNG.ql index d94436f2127c..0ebcd0e34ed5 100644 --- a/java/ql/src/Security/CWE/CWE-338/JHipsterGeneratedPRNG.ql +++ b/java/ql/src/Security/CWE/CWE-338/JHipsterGeneratedPRNG.ql @@ -37,7 +37,7 @@ private class VulnerableJHipsterRandomUtilClass extends Class { private class VulnerableJHipsterRandomUtilMethod extends Method { VulnerableJHipsterRandomUtilMethod() { this.getDeclaringType() instanceof VulnerableJHipsterRandomUtilClass and - this.getName().matches("generate%") and + this.getName().startsWith("generate") and this.getReturnType() instanceof TypeString and exists(ReturnStmt s | s = this.getBody().(SingletonBlock).getStmt() and diff --git a/java/ql/src/Violations of Best Practice/Comments/CommentedCode.qll b/java/ql/src/Violations of Best Practice/Comments/CommentedCode.qll index 04ff9502543f..c63d1e1e042c 100644 --- a/java/ql/src/Violations of Best Practice/Comments/CommentedCode.qll +++ b/java/ql/src/Violations of Best Practice/Comments/CommentedCode.qll @@ -16,12 +16,12 @@ import semmle.code.java.frameworks.j2objc.J2ObjC private predicate looksLikeCode(JavadocText line) { exists(string trimmed | trimmed = trimmedCommentText(line) | ( - trimmed.matches("%;") or - trimmed.matches("%{") or - trimmed.matches("%}") + trimmed.endsWith(";") or + trimmed.endsWith("{") or + trimmed.endsWith("}") ) and - not trimmed.matches(">%") and - not trimmed.matches("@%") + not trimmed.startsWith(">") and + not trimmed.startsWith("@") ) } @@ -94,7 +94,7 @@ private int anyCount(JavadocFirst first) { line = following.getAChild() and not exists(string trimmed | trimmed = line.getText().trim() | trimmed.regexpMatch("(|/\\*|/\\*\\*|\\*|\\*/)") or - trimmed.matches("@%") + trimmed.startsWith("@") ) ) ) diff --git a/java/ql/src/Violations of Best Practice/Comments/TodoComments.ql b/java/ql/src/Violations of Best Practice/Comments/TodoComments.ql index ef0b604ac5ee..b8a8dd600505 100644 --- a/java/ql/src/Violations of Best Practice/Comments/TodoComments.ql +++ b/java/ql/src/Violations of Best Practice/Comments/TodoComments.ql @@ -15,6 +15,6 @@ import java from JavadocText c where - c.getText().matches("%TODO%") or - c.getText().matches("%FIXME%") + c.getText().contains("TODO") or + c.getText().contains("FIXME") select c, "TODO comments should be addressed." diff --git a/java/ql/src/Violations of Best Practice/Dead Code/DeadRefTypes.ql b/java/ql/src/Violations of Best Practice/Dead Code/DeadRefTypes.ql index d211351c25d0..e9c4682a83ba 100644 --- a/java/ql/src/Violations of Best Practice/Dead Code/DeadRefTypes.ql +++ b/java/ql/src/Violations of Best Practice/Dead Code/DeadRefTypes.ql @@ -32,7 +32,7 @@ predicate dead(RefType dead) { // Exclude Struts or JSP classes (marked with Javadoc tags). not exists(JavadocTag tag, string x | tag = dead.getDoc().getJavadoc().getATag(x) and - (x.matches("@struts%") or x.matches("@jsp%")) + (x.startsWith("@struts") or x.startsWith("@jsp")) ) and // Exclude public types. not dead.isPublic() and diff --git a/java/ql/src/Violations of Best Practice/Naming Conventions/Shadowing.qll b/java/ql/src/Violations of Best Practice/Naming Conventions/Shadowing.qll index 02f00d4ffb22..76c003d66bc4 100644 --- a/java/ql/src/Violations of Best Practice/Naming Conventions/Shadowing.qll +++ b/java/ql/src/Violations of Best Practice/Naming Conventions/Shadowing.qll @@ -1,13 +1,13 @@ import java predicate getterFor(Method m, Field f) { - m.getName().matches("get%") and + m.getName().startsWith("get") and m.getDeclaringType() = f.getDeclaringType() and exists(ReturnStmt ret | ret.getEnclosingCallable() = m and ret.getExpr() = f.getAnAccess()) } predicate setterFor(Method m, Field f) { - m.getName().matches("set%") and + m.getName().startsWith("set") and m.getDeclaringType() = f.getDeclaringType() and f.getAnAssignedValue() = m.getAParameter().getAnAccess() and m.getNumberOfParameters() = 1 diff --git a/java/ql/src/experimental/Security/CWE/CWE-073/JFinalController.qll b/java/ql/src/experimental/Security/CWE/CWE-073/JFinalController.qll index 07d7c3bfb6b6..315e40a23721 100644 --- a/java/ql/src/experimental/Security/CWE/CWE-073/JFinalController.qll +++ b/java/ql/src/experimental/Security/CWE/CWE-073/JFinalController.qll @@ -27,7 +27,7 @@ class SetSessionAttributeMethod extends Method { /** A request attribute getter method of `JFinalController`. */ class GetRequestAttributeMethod extends Method { GetRequestAttributeMethod() { - this.getName().matches("getAttr%") and + this.getName().startsWith("getAttr") and this.getDeclaringType().getASupertype*() instanceof JFinalController } } diff --git a/java/ql/src/experimental/Security/CWE/CWE-094/InsecureDexLoading.qll b/java/ql/src/experimental/Security/CWE/CWE-094/InsecureDexLoading.qll index 20db5b954347..8f2800fc769a 100644 --- a/java/ql/src/experimental/Security/CWE/CWE-094/InsecureDexLoading.qll +++ b/java/ql/src/experimental/Security/CWE/CWE-094/InsecureDexLoading.qll @@ -72,7 +72,7 @@ private class ExternalFile extends InsecureDexSource { exists(ConstructorCall cc, Argument a | cc.getConstructedType() instanceof TypeFile and a = cc.getArgument(0) and - a.(CompileTimeConstantExpr).getStringValue().matches("%sdcard%") + a.(CompileTimeConstantExpr).getStringValue().contains("sdcard") | this.asExpr() = a ) diff --git a/java/ql/src/experimental/Security/CWE/CWE-094/JythonInjection.ql b/java/ql/src/experimental/Security/CWE/CWE-094/JythonInjection.ql index ccdff05cb34d..97ba20be585c 100644 --- a/java/ql/src/experimental/Security/CWE/CWE-094/JythonInjection.ql +++ b/java/ql/src/experimental/Security/CWE/CWE-094/JythonInjection.ql @@ -73,7 +73,7 @@ class Py extends RefType { class PyCompileMethod extends Method { PyCompileMethod() { this.getDeclaringType().getAnAncestor*() instanceof Py and - this.getName().matches("compile%") + this.getName().startsWith("compile") } } diff --git a/java/ql/src/experimental/Security/CWE/CWE-094/SpringViewManipulationLib.qll b/java/ql/src/experimental/Security/CWE/CWE-094/SpringViewManipulationLib.qll index 90c7ceaf1fc0..ad9ef1683e57 100644 --- a/java/ql/src/experimental/Security/CWE/CWE-094/SpringViewManipulationLib.qll +++ b/java/ql/src/experimental/Security/CWE/CWE-094/SpringViewManipulationLib.qll @@ -18,7 +18,7 @@ predicate thymeleafIsUsed() { ] ) or - exists(SpringBean b | b.getClassNameRaw().matches("org.thymeleaf.spring%")) + exists(SpringBean b | b.getClassNameRaw().startsWith("org.thymeleaf.spring")) } /** Models methods from the `javax.portlet.RenderState` package which return data from externally controlled sources. */ diff --git a/java/ql/src/experimental/Security/CWE/CWE-297/InsecureLdapEndpoint.ql b/java/ql/src/experimental/Security/CWE/CWE-297/InsecureLdapEndpoint.ql index ba860a1309f0..33592073d451 100644 --- a/java/ql/src/experimental/Security/CWE/CWE-297/InsecureLdapEndpoint.ql +++ b/java/ql/src/experimental/Security/CWE/CWE-297/InsecureLdapEndpoint.ql @@ -83,8 +83,8 @@ predicate isBooleanTrue(Expr expr) { predicate isTestMethod(MethodCall ma) { ma.getEnclosingCallable() instanceof TestMethod or ma.getEnclosingCallable().getDeclaringType() instanceof TestClass or - ma.getEnclosingCallable().getDeclaringType().getPackage().getName().matches("%test%") or - ma.getEnclosingCallable().getDeclaringType().getName().toLowerCase().matches("%test%") + ma.getEnclosingCallable().getDeclaringType().getPackage().getName().contains("test") or + ma.getEnclosingCallable().getDeclaringType().getName().toLowerCase().contains("test") } /** Holds if `MethodCall` ma disables SSL endpoint check. */ diff --git a/java/ql/src/experimental/Security/CWE/CWE-555/PasswordInConfigurationFile.ql b/java/ql/src/experimental/Security/CWE/CWE-555/PasswordInConfigurationFile.ql index ee2ac39bfbbd..9bf34ba731a2 100644 --- a/java/ql/src/experimental/Security/CWE/CWE-555/PasswordInConfigurationFile.ql +++ b/java/ql/src/experimental/Security/CWE/CWE-555/PasswordInConfigurationFile.ql @@ -21,7 +21,7 @@ predicate isNotPassword(string value) { or value.regexpMatch("\\$\\{.*\\}") // Variable placeholder ${password} or - value.matches("%=") // A basic check of encrypted passwords ending with padding characters, which could be improved to be more accurate. + value.endsWith("=") // A basic check of encrypted passwords ending with padding characters, which could be improved to be more accurate. } /** Holds if the attribute value has an embedded password */ diff --git a/java/ql/src/experimental/Security/CWE/CWE-598/SensitiveGetQuery.ql b/java/ql/src/experimental/Security/CWE/CWE-598/SensitiveGetQuery.ql index c661fad26f0c..13f2e764de8c 100644 --- a/java/ql/src/experimental/Security/CWE/CWE-598/SensitiveGetQuery.ql +++ b/java/ql/src/experimental/Security/CWE/CWE-598/SensitiveGetQuery.ql @@ -21,7 +21,7 @@ class SensitiveInfoExpr extends Expr { SensitiveInfoExpr() { exists(Variable v | this = v.getAnAccess() | v.getName().regexpMatch(getCommonSensitiveInfoRegex()) and - not v.getName().matches("token%") // exclude ^token.* since sensitive tokens are usually in the form of accessToken, authToken, ... + not v.getName().startsWith("token") // exclude ^token.* since sensitive tokens are usually in the form of accessToken, authToken, ... ) } } diff --git a/java/ql/src/experimental/Security/CWE/CWE-759/HashWithoutSalt.ql b/java/ql/src/experimental/Security/CWE/CWE-759/HashWithoutSalt.ql index fd2957151a7b..c15cbffa81de 100644 --- a/java/ql/src/experimental/Security/CWE/CWE-759/HashWithoutSalt.ql +++ b/java/ql/src/experimental/Security/CWE/CWE-759/HashWithoutSalt.ql @@ -24,7 +24,7 @@ string getPasswordRegex() { result = "(?i).*pass(wd|word|code|phrase).*" } class PasswordVarExpr extends VarAccess { PasswordVarExpr() { exists(string name | name = this.getVariable().getName().toLowerCase() | - name.regexpMatch(getPasswordRegex()) and not name.matches("%hash%") // Exclude variable names such as `passwordHash` since their values were already hashed + name.regexpMatch(getPasswordRegex()) and not name.contains("hash") // Exclude variable names such as `passwordHash` since their values were already hashed ) } } diff --git a/java/ql/src/experimental/quantum/Examples/BrokenCrypto.ql b/java/ql/src/experimental/quantum/Examples/BrokenCrypto.ql index a4215caac6a5..00ac581a6bd6 100644 --- a/java/ql/src/experimental/quantum/Examples/BrokenCrypto.ql +++ b/java/ql/src/experimental/quantum/Examples/BrokenCrypto.ql @@ -63,7 +63,7 @@ from Crypto::AlgorithmNode alg where alg.getAlgorithmName().regexpMatch(getInsecureAlgorithmRegex()) and // Exclude RSA/ECB/.* ciphers. - not alg.getAlgorithmName().regexpMatch("RSA/ECB.*") and + not alg.getAlgorithmName().startsWith("RSA/ECB") and // Exclude German and French sentences. not alg.getAlgorithmName().regexpMatch(".*\\p{IsLowercase} des \\p{IsLetter}.*") select alg, "Cryptographic algorithm $@ is weak and should not be used.", alg, diff --git a/java/ql/src/experimental/semmle/code/java/frameworks/CredentialsInPropertiesFile.qll b/java/ql/src/experimental/semmle/code/java/frameworks/CredentialsInPropertiesFile.qll index caddfb32a211..2273a9958b4e 100644 --- a/java/ql/src/experimental/semmle/code/java/frameworks/CredentialsInPropertiesFile.qll +++ b/java/ql/src/experimental/semmle/code/java/frameworks/CredentialsInPropertiesFile.qll @@ -25,15 +25,15 @@ predicate isNotCleartextCredentials(string value) { or value.length() < 7 // Typical credentials are no less than 6 characters or - value.matches("% %") // Sentences containing spaces + value.contains(" ") // Sentences containing spaces or value.regexpMatch(".*[^a-zA-Z\\d]{3,}.*") // Contain repeated non-alphanumeric characters such as a fake password pass**** or ???? or - value.matches("@%") // Starts with the "@" sign + value.startsWith("@") // Starts with the "@" sign or value.regexpMatch("\\$\\{.*\\}") // Variable placeholder ${credentials} or - value.matches("%=") // A basic check of encrypted credentials ending with padding characters + value.endsWith("=") // A basic check of encrypted credentials ending with padding characters or value.matches("ENC(%)") // Encrypted value or diff --git a/java/ql/src/utils/modelconverter/ExtractNeutrals.ql b/java/ql/src/utils/modelconverter/ExtractNeutrals.ql index 108aa454232e..c7ff635f5b8e 100644 --- a/java/ql/src/utils/modelconverter/ExtractNeutrals.ql +++ b/java/ql/src/utils/modelconverter/ExtractNeutrals.ql @@ -10,6 +10,6 @@ import semmle.code.java.dataflow.ExternalFlow from string package, string type, string name, string signature, string kind, string provenance where neutralModel(package, type, name, signature, kind, provenance) and - not provenance.matches("%generated") + not provenance.endsWith("generated") select package, type, name, signature, kind, provenance order by package, type, name, signature, kind diff --git a/java/ql/src/utils/modelconverter/ExtractSinks.ql b/java/ql/src/utils/modelconverter/ExtractSinks.ql index ae79cf3a49d7..4bde345a1819 100644 --- a/java/ql/src/utils/modelconverter/ExtractSinks.ql +++ b/java/ql/src/utils/modelconverter/ExtractSinks.ql @@ -12,6 +12,6 @@ from string input, string kind, string provenance where sinkModel(package, type, subtypes, name, signature, ext, input, kind, provenance, _) and - not provenance.matches("%generated") + not provenance.endsWith("generated") select package, type, subtypes, name, signature, ext, input, kind, provenance order by package, type, name, signature, input, kind diff --git a/java/ql/src/utils/modelconverter/ExtractSources.ql b/java/ql/src/utils/modelconverter/ExtractSources.ql index 8aeb4542a00b..59e71b14852a 100644 --- a/java/ql/src/utils/modelconverter/ExtractSources.ql +++ b/java/ql/src/utils/modelconverter/ExtractSources.ql @@ -12,6 +12,6 @@ from string output, string kind, string provenance where sourceModel(package, type, subtypes, name, signature, ext, output, kind, provenance, _) and - not provenance.matches("%generated") + not provenance.endsWith("generated") select package, type, subtypes, name, signature, ext, output, kind, provenance order by package, type, name, signature, output, kind diff --git a/java/ql/src/utils/modelconverter/ExtractSummaries.ql b/java/ql/src/utils/modelconverter/ExtractSummaries.ql index 4976c4a13291..862fc9d684d1 100644 --- a/java/ql/src/utils/modelconverter/ExtractSummaries.ql +++ b/java/ql/src/utils/modelconverter/ExtractSummaries.ql @@ -12,6 +12,6 @@ from string input, string output, string kind, string provenance where summaryModel(package, type, subtypes, name, signature, ext, input, output, kind, provenance, _) and - not provenance.matches("%generated") + not provenance.endsWith("generated") select package, type, subtypes, name, signature, ext, input, output, kind, provenance order by package, type, name, signature, input, output, kind diff --git a/java/ql/src/utils/modelgenerator/internal/CaptureModels.qll b/java/ql/src/utils/modelgenerator/internal/CaptureModels.qll index 2fe9079a9f7f..d6c34571423a 100644 --- a/java/ql/src/utils/modelgenerator/internal/CaptureModels.qll +++ b/java/ql/src/utils/modelgenerator/internal/CaptureModels.qll @@ -27,7 +27,7 @@ predicate isPrimitiveTypeUsedForBulkData(J::Type t) { private predicate isInfrequentlyUsed(J::CompilationUnit cu) { cu.getPackage().getName().matches(javaxOrJakarta() + ".swing%") or - cu.getPackage().getName().matches("java.awt%") + cu.getPackage().getName().startsWith("java.awt") } private predicate relevant(Callable api) { @@ -307,7 +307,7 @@ private module SinkModelGeneratorInput implements SinkModelGeneratorInputSig { bindingset[kind] predicate isRelevantSinkKind(string kind) { not kind = "log-injection" and - not kind.matches("regex-use%") and + not kind.startsWith("regex-use") and not kind = "file-content-store" } diff --git a/java/ql/test-kotlin1/library-tests/annotation-accessor-result-type/test.ql b/java/ql/test-kotlin1/library-tests/annotation-accessor-result-type/test.ql index 65576a7c19dd..cbe59cefe0e2 100644 --- a/java/ql/test-kotlin1/library-tests/annotation-accessor-result-type/test.ql +++ b/java/ql/test-kotlin1/library-tests/annotation-accessor-result-type/test.ql @@ -3,7 +3,7 @@ import java query predicate classExprs(Expr e, string tstr) { exists(e.getFile().getRelativePath()) and tstr = e.getType().toString() and - tstr.matches("%Class%") + tstr.contains("Class") } from Method m diff --git a/java/ql/test-kotlin1/library-tests/compilation-units/cus.ql b/java/ql/test-kotlin1/library-tests/compilation-units/cus.ql index 1886d0259ab9..4ac7c8d3c2eb 100644 --- a/java/ql/test-kotlin1/library-tests/compilation-units/cus.ql +++ b/java/ql/test-kotlin1/library-tests/compilation-units/cus.ql @@ -1,5 +1,5 @@ import java from CompilationUnit cu -where cu.fromSource() or cu.toString().matches("%List%") +where cu.fromSource() or cu.toString().contains("List") select cu.toString(), cu.getLocation().toString().regexpReplaceAll(".*/", ".../") diff --git a/java/ql/test-kotlin1/library-tests/instances/classes.ql b/java/ql/test-kotlin1/library-tests/instances/classes.ql index 2c0dd99626a2..e5fc197dcd28 100644 --- a/java/ql/test-kotlin1/library-tests/instances/classes.ql +++ b/java/ql/test-kotlin1/library-tests/instances/classes.ql @@ -1,5 +1,5 @@ import java from Class c -where c.getName().matches("TestClass%") +where c.getName().startsWith("TestClass") select c diff --git a/java/ql/test-kotlin1/library-tests/java-list-kotlin-user/test.ql b/java/ql/test-kotlin1/library-tests/java-list-kotlin-user/test.ql index 52d28097a4b6..118845bb3a7b 100644 --- a/java/ql/test-kotlin1/library-tests/java-list-kotlin-user/test.ql +++ b/java/ql/test-kotlin1/library-tests/java-list-kotlin-user/test.ql @@ -1,5 +1,5 @@ import java from Method m -where m.getDeclaringType().getName().matches("MyList%") +where m.getDeclaringType().getName().startsWith("MyList") select m.toString() diff --git a/java/ql/test-kotlin1/library-tests/methods/diagnostics.ql b/java/ql/test-kotlin1/library-tests/methods/diagnostics.ql index 1774650beffe..528b3d7ac410 100644 --- a/java/ql/test-kotlin1/library-tests/methods/diagnostics.ql +++ b/java/ql/test-kotlin1/library-tests/methods/diagnostics.ql @@ -1,4 +1,4 @@ import java import semmle.code.java.Diagnostics -select any(Diagnostic d | not d.toString().matches("Not rewriting trap file for%")) +select any(Diagnostic d | not d.toString().startsWith("Not rewriting trap file for")) diff --git a/java/ql/test-kotlin1/library-tests/parameter-defaults/erasure.ql b/java/ql/test-kotlin1/library-tests/parameter-defaults/erasure.ql index 9818700479e1..c0f839b0d9f3 100644 --- a/java/ql/test-kotlin1/library-tests/parameter-defaults/erasure.ql +++ b/java/ql/test-kotlin1/library-tests/parameter-defaults/erasure.ql @@ -16,6 +16,6 @@ predicate containsTypeVariables(Type t) { from Expr e where - e.getEnclosingCallable().getName().matches("%$default") and + e.getEnclosingCallable().getName().endsWith("$default") and containsTypeVariables(e.getType()) select e, e.getType() diff --git a/java/ql/test-kotlin1/library-tests/parameter-defaults/flowTest.ql b/java/ql/test-kotlin1/library-tests/parameter-defaults/flowTest.ql index 0bf36d842e14..f2274151aa0d 100644 --- a/java/ql/test-kotlin1/library-tests/parameter-defaults/flowTest.ql +++ b/java/ql/test-kotlin1/library-tests/parameter-defaults/flowTest.ql @@ -2,12 +2,12 @@ import java import semmle.code.java.dataflow.DataFlow class ShouldNotBeSunk extends StringLiteral { - ShouldNotBeSunk() { this.getValue().matches("%not sunk%") } + ShouldNotBeSunk() { this.getValue().contains("not sunk") } } class ShouldBeSunk extends StringLiteral { ShouldBeSunk() { - this.getValue().matches("%sunk%") and + this.getValue().contains("sunk") and not this instanceof ShouldNotBeSunk } } diff --git a/java/ql/test-kotlin1/library-tests/type_equivalences/type_equivalences.ql b/java/ql/test-kotlin1/library-tests/type_equivalences/type_equivalences.ql index 00fa7f844c93..0483fb9119c4 100644 --- a/java/ql/test-kotlin1/library-tests/type_equivalences/type_equivalences.ql +++ b/java/ql/test-kotlin1/library-tests/type_equivalences/type_equivalences.ql @@ -13,6 +13,6 @@ class ClassOrInterfaceLocation extends ClassOrInterface { from Method m, int i, Parameter p where - m.getName().matches("foo%") and + m.getName().startsWith("foo") and p = m.getParameter(i) select m, m.getReturnType(), i, p, p.getType() diff --git a/java/ql/test-kotlin2/library-tests/annotation-accessor-result-type/test.ql b/java/ql/test-kotlin2/library-tests/annotation-accessor-result-type/test.ql index 65576a7c19dd..cbe59cefe0e2 100644 --- a/java/ql/test-kotlin2/library-tests/annotation-accessor-result-type/test.ql +++ b/java/ql/test-kotlin2/library-tests/annotation-accessor-result-type/test.ql @@ -3,7 +3,7 @@ import java query predicate classExprs(Expr e, string tstr) { exists(e.getFile().getRelativePath()) and tstr = e.getType().toString() and - tstr.matches("%Class%") + tstr.contains("Class") } from Method m diff --git a/java/ql/test-kotlin2/library-tests/compilation-units/cus.ql b/java/ql/test-kotlin2/library-tests/compilation-units/cus.ql index 1886d0259ab9..4ac7c8d3c2eb 100644 --- a/java/ql/test-kotlin2/library-tests/compilation-units/cus.ql +++ b/java/ql/test-kotlin2/library-tests/compilation-units/cus.ql @@ -1,5 +1,5 @@ import java from CompilationUnit cu -where cu.fromSource() or cu.toString().matches("%List%") +where cu.fromSource() or cu.toString().contains("List") select cu.toString(), cu.getLocation().toString().regexpReplaceAll(".*/", ".../") diff --git a/java/ql/test-kotlin2/library-tests/enum/test.ql b/java/ql/test-kotlin2/library-tests/enum/test.ql index 8d83314e5c38..3c3bd3b44781 100644 --- a/java/ql/test-kotlin2/library-tests/enum/test.ql +++ b/java/ql/test-kotlin2/library-tests/enum/test.ql @@ -1,7 +1,7 @@ import java from Method m -where m.getDeclaringType().getName().matches("Enum%") +where m.getDeclaringType().getName().startsWith("Enum") select m.getName() query predicate enumConstants(EnumConstant ec) { ec.fromSource() } diff --git a/java/ql/test-kotlin2/library-tests/instances/classes.ql b/java/ql/test-kotlin2/library-tests/instances/classes.ql index 2c0dd99626a2..e5fc197dcd28 100644 --- a/java/ql/test-kotlin2/library-tests/instances/classes.ql +++ b/java/ql/test-kotlin2/library-tests/instances/classes.ql @@ -1,5 +1,5 @@ import java from Class c -where c.getName().matches("TestClass%") +where c.getName().startsWith("TestClass") select c diff --git a/java/ql/test-kotlin2/library-tests/java-list-kotlin-user/test.ql b/java/ql/test-kotlin2/library-tests/java-list-kotlin-user/test.ql index 52d28097a4b6..118845bb3a7b 100644 --- a/java/ql/test-kotlin2/library-tests/java-list-kotlin-user/test.ql +++ b/java/ql/test-kotlin2/library-tests/java-list-kotlin-user/test.ql @@ -1,5 +1,5 @@ import java from Method m -where m.getDeclaringType().getName().matches("MyList%") +where m.getDeclaringType().getName().startsWith("MyList") select m.toString() diff --git a/java/ql/test-kotlin2/library-tests/methods/diagnostics.ql b/java/ql/test-kotlin2/library-tests/methods/diagnostics.ql index 1774650beffe..528b3d7ac410 100644 --- a/java/ql/test-kotlin2/library-tests/methods/diagnostics.ql +++ b/java/ql/test-kotlin2/library-tests/methods/diagnostics.ql @@ -1,4 +1,4 @@ import java import semmle.code.java.Diagnostics -select any(Diagnostic d | not d.toString().matches("Not rewriting trap file for%")) +select any(Diagnostic d | not d.toString().startsWith("Not rewriting trap file for")) diff --git a/java/ql/test-kotlin2/library-tests/nested_types/types.ql b/java/ql/test-kotlin2/library-tests/nested_types/types.ql index 3499ae037c70..dad47cad3108 100644 --- a/java/ql/test-kotlin2/library-tests/nested_types/types.ql +++ b/java/ql/test-kotlin2/library-tests/nested_types/types.ql @@ -2,6 +2,6 @@ import java from Type t where - t.getName().matches("%MyType%") and + t.getName().contains("MyType") and t.getName().matches(["List<%", "Stack<%", "MkT<%"]) select t diff --git a/java/ql/test-kotlin2/library-tests/parameter-defaults/erasure.ql b/java/ql/test-kotlin2/library-tests/parameter-defaults/erasure.ql index 9818700479e1..c0f839b0d9f3 100644 --- a/java/ql/test-kotlin2/library-tests/parameter-defaults/erasure.ql +++ b/java/ql/test-kotlin2/library-tests/parameter-defaults/erasure.ql @@ -16,6 +16,6 @@ predicate containsTypeVariables(Type t) { from Expr e where - e.getEnclosingCallable().getName().matches("%$default") and + e.getEnclosingCallable().getName().endsWith("$default") and containsTypeVariables(e.getType()) select e, e.getType() diff --git a/java/ql/test-kotlin2/library-tests/parameter-defaults/flowTest.ql b/java/ql/test-kotlin2/library-tests/parameter-defaults/flowTest.ql index 0bf36d842e14..f2274151aa0d 100644 --- a/java/ql/test-kotlin2/library-tests/parameter-defaults/flowTest.ql +++ b/java/ql/test-kotlin2/library-tests/parameter-defaults/flowTest.ql @@ -2,12 +2,12 @@ import java import semmle.code.java.dataflow.DataFlow class ShouldNotBeSunk extends StringLiteral { - ShouldNotBeSunk() { this.getValue().matches("%not sunk%") } + ShouldNotBeSunk() { this.getValue().contains("not sunk") } } class ShouldBeSunk extends StringLiteral { ShouldBeSunk() { - this.getValue().matches("%sunk%") and + this.getValue().contains("sunk") and not this instanceof ShouldNotBeSunk } } diff --git a/java/ql/test-kotlin2/library-tests/type_equivalences/type_equivalences.ql b/java/ql/test-kotlin2/library-tests/type_equivalences/type_equivalences.ql index 00fa7f844c93..0483fb9119c4 100644 --- a/java/ql/test-kotlin2/library-tests/type_equivalences/type_equivalences.ql +++ b/java/ql/test-kotlin2/library-tests/type_equivalences/type_equivalences.ql @@ -13,6 +13,6 @@ class ClassOrInterfaceLocation extends ClassOrInterface { from Method m, int i, Parameter p where - m.getName().matches("foo%") and + m.getName().startsWith("foo") and p = m.getParameter(i) select m, m.getReturnType(), i, p, p.getType() diff --git a/java/ql/test/library-tests/dispatch/viableCallable.ql b/java/ql/test/library-tests/dispatch/viableCallable.ql index 56bf06af70c7..ede564b50135 100644 --- a/java/ql/test/library-tests/dispatch/viableCallable.ql +++ b/java/ql/test/library-tests/dispatch/viableCallable.ql @@ -3,7 +3,7 @@ import semmle.code.java.dispatch.VirtualDispatch from MethodCall ma, Method m where - ma.getFile().toString().matches("ViableCallable%") and + ma.getFile().toString().startsWith("ViableCallable") and ma.getMethod().getSourceDeclaration().fromSource() and m = viableImpl(ma) select ma, m.toString(), m.getDeclaringType().getLocation().getStartLine(), diff --git a/java/ql/test/library-tests/errortype-with-params/Diags.ql b/java/ql/test/library-tests/errortype-with-params/Diags.ql index 1774650beffe..528b3d7ac410 100644 --- a/java/ql/test/library-tests/errortype-with-params/Diags.ql +++ b/java/ql/test/library-tests/errortype-with-params/Diags.ql @@ -1,4 +1,4 @@ import java import semmle.code.java.Diagnostics -select any(Diagnostic d | not d.toString().matches("Not rewriting trap file for%")) +select any(Diagnostic d | not d.toString().startsWith("Not rewriting trap file for")) diff --git a/java/ql/test/library-tests/errortype/Diags.ql b/java/ql/test/library-tests/errortype/Diags.ql index 1774650beffe..528b3d7ac410 100644 --- a/java/ql/test/library-tests/errortype/Diags.ql +++ b/java/ql/test/library-tests/errortype/Diags.ql @@ -1,4 +1,4 @@ import java import semmle.code.java.Diagnostics -select any(Diagnostic d | not d.toString().matches("Not rewriting trap file for%")) +select any(Diagnostic d | not d.toString().startsWith("Not rewriting trap file for")) diff --git a/java/ql/test/library-tests/module-info-wrong-name/Diags.ql b/java/ql/test/library-tests/module-info-wrong-name/Diags.ql index 1774650beffe..528b3d7ac410 100644 --- a/java/ql/test/library-tests/module-info-wrong-name/Diags.ql +++ b/java/ql/test/library-tests/module-info-wrong-name/Diags.ql @@ -1,4 +1,4 @@ import java import semmle.code.java.Diagnostics -select any(Diagnostic d | not d.toString().matches("Not rewriting trap file for%")) +select any(Diagnostic d | not d.toString().startsWith("Not rewriting trap file for")) diff --git a/java/ql/test/library-tests/unknown-method-reference-lhs/Diags.ql b/java/ql/test/library-tests/unknown-method-reference-lhs/Diags.ql index 1774650beffe..528b3d7ac410 100644 --- a/java/ql/test/library-tests/unknown-method-reference-lhs/Diags.ql +++ b/java/ql/test/library-tests/unknown-method-reference-lhs/Diags.ql @@ -1,4 +1,4 @@ import java import semmle.code.java.Diagnostics -select any(Diagnostic d | not d.toString().matches("Not rewriting trap file for%")) +select any(Diagnostic d | not d.toString().startsWith("Not rewriting trap file for")) diff --git a/java/ql/test/library-tests/wildcards-and-captured-types/test.ql b/java/ql/test/library-tests/wildcards-and-captured-types/test.ql index 3e28a2c1d675..6207c5753926 100644 --- a/java/ql/test/library-tests/wildcards-and-captured-types/test.ql +++ b/java/ql/test/library-tests/wildcards-and-captured-types/test.ql @@ -1,5 +1,5 @@ import java from Method m, Type t -where m.getAParamType() = t and t.toString().matches("%? super ? extends%") +where m.getAParamType() = t and t.toString().contains("? super ? extends") select m, t diff --git a/java/ql/test/query-tests/security/CWE-730/ExpRedos/ReDoS.ql b/java/ql/test/query-tests/security/CWE-730/ExpRedos/ReDoS.ql index 98674d09df5e..5d56eec215e5 100644 --- a/java/ql/test/query-tests/security/CWE-730/ExpRedos/ReDoS.ql +++ b/java/ql/test/query-tests/security/CWE-730/ExpRedos/ReDoS.ql @@ -5,7 +5,7 @@ import codeql.regex.nfa.ExponentialBackTracking::Make as ExponentialBa import semmle.code.java.regex.regex bindingset[s] -string quote(string s) { if s.matches("% %") then result = "\"" + s + "\"" else result = s } +string quote(string s) { if s.contains(" ") then result = "\"" + s + "\"" else result = s } module HasExpRedos implements TestSig { string getARelevantTag() { diff --git a/javascript/ql/examples/queries/dataflow/DecodingAfterSanitization/DecodingAfterSanitization.ql b/javascript/ql/examples/queries/dataflow/DecodingAfterSanitization/DecodingAfterSanitization.ql index b83ee8aaee9d..70c8262e16e3 100644 --- a/javascript/ql/examples/queries/dataflow/DecodingAfterSanitization/DecodingAfterSanitization.ql +++ b/javascript/ql/examples/queries/dataflow/DecodingAfterSanitization/DecodingAfterSanitization.ql @@ -17,7 +17,7 @@ module DecodingAfterSanitizationConfig implements DataFlow::ConfigSig { predicate isSink(DataFlow::Node node) { exists(DataFlow::CallNode call | - call.getCalleeName().matches("decodeURI%") and + call.getCalleeName().startsWith("decodeURI") and node = call.getArgument(0) ) } diff --git a/javascript/ql/examples/queries/dataflow/DecodingAfterSanitization/DecodingAfterSanitizationGeneralized.ql b/javascript/ql/examples/queries/dataflow/DecodingAfterSanitization/DecodingAfterSanitizationGeneralized.ql index d10799a8916e..a9323d585ab6 100644 --- a/javascript/ql/examples/queries/dataflow/DecodingAfterSanitization/DecodingAfterSanitizationGeneralized.ql +++ b/javascript/ql/examples/queries/dataflow/DecodingAfterSanitization/DecodingAfterSanitizationGeneralized.ql @@ -19,7 +19,7 @@ class DecodingCall extends DataFlow::CallNode { DataFlow::Node input; DecodingCall() { - this.getCalleeName().matches("decodeURI%") and + this.getCalleeName().startsWith("decodeURI") and input = this.getArgument(0) and kind = "URI decoding" or diff --git a/javascript/ql/integration-tests/subst/file.ql b/javascript/ql/integration-tests/subst/file.ql index 5debbe443cde..fa3fce7f7678 100644 --- a/javascript/ql/integration-tests/subst/file.ql +++ b/javascript/ql/integration-tests/subst/file.ql @@ -2,6 +2,6 @@ import javascript from File f, string relative where - not f.getURL().matches("%/target/intree/%") and + not f.getURL().contains("/target/intree/") and if exists(f.getRelativePath()) then relative = "relative" else relative = "" select f, relative diff --git a/javascript/ql/lib/semmle/javascript/AST.qll b/javascript/ql/lib/semmle/javascript/AST.qll index c37a4e938a23..bfec7d9764c9 100644 --- a/javascript/ql/lib/semmle/javascript/AST.qll +++ b/javascript/ql/lib/semmle/javascript/AST.qll @@ -190,7 +190,7 @@ class AstNode extends @ast_node, NodeInStmtContainer { */ cached private predicate isAmbientTopLevel(TopLevel tl) { - Stages::Ast::ref() and tl.getFile().getBaseName().matches("%.d.ts") + Stages::Ast::ref() and tl.getFile().getBaseName().endsWith(".d.ts") } /** diff --git a/javascript/ql/lib/semmle/javascript/DOM.qll b/javascript/ql/lib/semmle/javascript/DOM.qll index 97f6bc435464..d7ad5255aee7 100644 --- a/javascript/ql/lib/semmle/javascript/DOM.qll +++ b/javascript/ql/lib/semmle/javascript/DOM.qll @@ -375,7 +375,7 @@ module DOM { exists(DataFlow::SourceNode domNode, DataFlow::FunctionNode eventHandler | // NOTE: we do not use `getABoundFunctionValue()`, since bound functions tend to have // a different receiver anyway - eventHandler = domNode.getAPropertySource(any(string n | n.matches("on%"))) + eventHandler = domNode.getAPropertySource(any(string n | n.startsWith("on"))) or eventHandler = domNode.getAMethodCall("addEventListener").getArgument(1).getAFunctionValue() @@ -402,7 +402,7 @@ module DOM { private class DefaultRange extends Range { DefaultRange() { // e.g.
e.target}/> - exists(JsxAttribute attr | attr.getName().matches("on%") | + exists(JsxAttribute attr | attr.getName().startsWith("on") | this = attr.getValue().flow().getABoundFunctionValue(0).getParameter(0) ) or @@ -411,7 +411,7 @@ module DOM { or // node.onSubmit = (e => e.target); exists(DataFlow::PropWrite write | write = domValueRef().getAPropertyWrite() | - write.getPropertyName().matches("on%") and + write.getPropertyName().startsWith("on") and this = write.getRhs().getAFunctionValue().getParameter(0) ) } diff --git a/javascript/ql/lib/semmle/javascript/Files.qll b/javascript/ql/lib/semmle/javascript/Files.qll index 556d25911f11..db7cce613c9b 100644 --- a/javascript/ql/lib/semmle/javascript/Files.qll +++ b/javascript/ql/lib/semmle/javascript/Files.qll @@ -52,7 +52,7 @@ class Folder extends Container, Impl::Folder { /** Like `getFile` except `d.ts` is treated as a single extension. */ overlay[global] private File getFileLongExtension(string stem, string extension) { - not (stem.matches("%.d") and extension = "ts") and + not (stem.endsWith(".d") and extension = "ts") and result = this.getFile(stem, extension) or extension = "d.ts" and diff --git a/javascript/ql/lib/semmle/javascript/GlobalAccessPaths.qll b/javascript/ql/lib/semmle/javascript/GlobalAccessPaths.qll index 7b3004dbde43..2d83ada67660 100644 --- a/javascript/ql/lib/semmle/javascript/GlobalAccessPaths.qll +++ b/javascript/ql/lib/semmle/javascript/GlobalAccessPaths.qll @@ -238,7 +238,7 @@ module AccessPath { baseName = fromRhs(write.getBase(), root) or baseName = fromRhs(GetLaterAccess::getLaterBaseAccess(write), root) and - not baseName.matches("%.%") + not baseName.contains(".") ) or exists(GlobalVariable var | diff --git a/javascript/ql/lib/semmle/javascript/HTML.qll b/javascript/ql/lib/semmle/javascript/HTML.qll index fa3deaf661f2..65a1e255a342 100644 --- a/javascript/ql/lib/semmle/javascript/HTML.qll +++ b/javascript/ql/lib/semmle/javascript/HTML.qll @@ -234,7 +234,7 @@ module HTML { * Gets the folder relative to which the `src` attribute is resolved. */ Folder getSearchRoot() { - if this.getSourcePath().matches("/%") + if this.getSourcePath().startsWith("/") then result.getBaseName() = "" else result = this.getFile().getParentContainer() } diff --git a/javascript/ql/lib/semmle/javascript/JSDoc.qll b/javascript/ql/lib/semmle/javascript/JSDoc.qll index 48d2a984ec43..86963dbfac2a 100644 --- a/javascript/ql/lib/semmle/javascript/JSDoc.qll +++ b/javascript/ql/lib/semmle/javascript/JSDoc.qll @@ -121,7 +121,7 @@ class JSDocTag extends @jsdoc_tag, JSDocTypeExprParent { /** Holds if this tag documents a simple name (as opposed to a name path). */ predicate documentsSimpleName() { - exists(string name | name = this.getName() | not name.matches("%.%")) + exists(string name | name = this.getName() | not name.contains(".")) } /** Gets the toplevel in which this tag appears. */ diff --git a/javascript/ql/lib/semmle/javascript/JsonSchema.qll b/javascript/ql/lib/semmle/javascript/JsonSchema.qll index a298abfd2dd7..e4871cb622f9 100644 --- a/javascript/ql/lib/semmle/javascript/JsonSchema.qll +++ b/javascript/ql/lib/semmle/javascript/JsonSchema.qll @@ -35,7 +35,7 @@ module JsonSchema { /** An object literal with a `$schema` property indicating it is the root of a JSON schema. */ private class SchemaNodeByTag extends SchemaRoot, DataFlow::ObjectLiteralNode { SchemaNodeByTag() { - this.getAPropertyWrite("$schema").getRhs().getStringValue().matches("%//json-schema.org%") + this.getAPropertyWrite("$schema").getRhs().getStringValue().contains("//json-schema.org") } } diff --git a/javascript/ql/lib/semmle/javascript/Modules.qll b/javascript/ql/lib/semmle/javascript/Modules.qll index 9bd9ce434517..6e3abc1234d6 100644 --- a/javascript/ql/lib/semmle/javascript/Modules.qll +++ b/javascript/ql/lib/semmle/javascript/Modules.qll @@ -82,7 +82,7 @@ abstract class Module extends TopLevel { priority = 0 and exists(string v | v = path.getValue() | // paths starting with a dot are resolved relative to the module's directory - if v.matches(".%") + if v.startsWith(".") then searchRoot = this.getFile().getParentContainer() else // all other paths are resolved relative to the file system root diff --git a/javascript/ql/lib/semmle/javascript/NPM.qll b/javascript/ql/lib/semmle/javascript/NPM.qll index 857fc1638047..5947b3d066da 100644 --- a/javascript/ql/lib/semmle/javascript/NPM.qll +++ b/javascript/ql/lib/semmle/javascript/NPM.qll @@ -190,7 +190,7 @@ class PackageJson extends JsonObject { /** Gets an operating system supported by this package. */ string getWhitelistedOS() { result = this.getOSs().getElementStringValue(_) and - not result.matches("!%") + not result.startsWith("!") } /** Gets an operating system not supported by this package. */ @@ -206,7 +206,7 @@ class PackageJson extends JsonObject { /** Gets a platform supported by this package. */ string getWhitelistedCpu() { result = this.getCPUs().getElementStringValue(_) and - not result.matches("!%") + not result.startsWith("!") } /** Gets a platform not supported by this package. */ diff --git a/javascript/ql/lib/semmle/javascript/NodeJS.qll b/javascript/ql/lib/semmle/javascript/NodeJS.qll index 0fbd8d79a749..924cbe03165e 100644 --- a/javascript/ql/lib/semmle/javascript/NodeJS.qll +++ b/javascript/ql/lib/semmle/javascript/NodeJS.qll @@ -165,7 +165,7 @@ class NodeModule extends Module { (searchRoot = this.getFile().getParentContainer() and priority = 0) or // paths starting with `/` are resolved relative to the file system root - pathval.matches("/%") and + pathval.startsWith("/") and (searchRoot.getBaseName() = "" and priority = 0) or // paths that do not start with `./`, `../` or `/` are resolved relative diff --git a/javascript/ql/lib/semmle/javascript/NodeModuleResolutionImpl.qll b/javascript/ql/lib/semmle/javascript/NodeModuleResolutionImpl.qll index 467e14aa74fb..6612c83103e8 100644 --- a/javascript/ql/lib/semmle/javascript/NodeModuleResolutionImpl.qll +++ b/javascript/ql/lib/semmle/javascript/NodeModuleResolutionImpl.qll @@ -225,7 +225,7 @@ private string getAnEnclosingExportProperty(JsonValue part) { private string getExportRelativePath(JsonValue part) { result = getAnEnclosingExportProperty(part) and - result.matches(".%") + result.startsWith(".") } deprecated module MainModulePath { diff --git a/javascript/ql/lib/semmle/javascript/Regexp.qll b/javascript/ql/lib/semmle/javascript/Regexp.qll index 49702214bc62..896933c54061 100644 --- a/javascript/ql/lib/semmle/javascript/Regexp.qll +++ b/javascript/ql/lib/semmle/javascript/Regexp.qll @@ -1241,23 +1241,23 @@ module RegExp { /** Holds if `flags` includes the `m` flag. */ bindingset[flags] - predicate isMultiline(string flags) { flags.matches("%m%") } + predicate isMultiline(string flags) { flags.contains("m") } /** Holds if `flags` includes the `g` flag. */ bindingset[flags] - predicate isGlobal(string flags) { flags.matches("%g%") } + predicate isGlobal(string flags) { flags.contains("g") } /** Holds if `flags` includes the `i` flag. */ bindingset[flags] - predicate isIgnoreCase(string flags) { flags.matches("%i%") } + predicate isIgnoreCase(string flags) { flags.contains("i") } /** Holds if `flags` includes the `s` flag. */ bindingset[flags] - predicate isDotAll(string flags) { flags.matches("%s%") } + predicate isDotAll(string flags) { flags.contains("s") } /** Holds if `flags` includes the `v` flag. */ bindingset[flags] - predicate isUnicodeSets(string flags) { flags.matches("%v%") } + predicate isUnicodeSets(string flags) { flags.contains("v") } /** Holds if `flags` includes the `m` flag or is the unknown flag `?`. */ bindingset[flags] diff --git a/javascript/ql/lib/semmle/javascript/TSConfig.qll b/javascript/ql/lib/semmle/javascript/TSConfig.qll index c10177e5fe24..f5aa758c03e7 100644 --- a/javascript/ql/lib/semmle/javascript/TSConfig.qll +++ b/javascript/ql/lib/semmle/javascript/TSConfig.qll @@ -149,7 +149,7 @@ class TSConfig extends JsonObject { */ predicate hasExactPathMapping(string pattern, string newPath) { this.hasPathMapping(pattern, newPath) and - not pattern.matches("%*%") + not pattern.contains("*") } /** diff --git a/javascript/ql/lib/semmle/javascript/dataflow/TaintTracking.qll b/javascript/ql/lib/semmle/javascript/dataflow/TaintTracking.qll index a8e3658a5e58..04c9bb2d3374 100644 --- a/javascript/ql/lib/semmle/javascript/dataflow/TaintTracking.qll +++ b/javascript/ql/lib/semmle/javascript/dataflow/TaintTracking.qll @@ -714,7 +714,7 @@ module TaintTracking { exists(string m, DataFlow::MethodCallNode call | call = succ | call.getMethodName() = m and call.getReceiver() = pred and - m.matches("get%") + m.startsWith("get") ) } } diff --git a/javascript/ql/lib/semmle/javascript/dependencies/FrameworkLibraries.qll b/javascript/ql/lib/semmle/javascript/dependencies/FrameworkLibraries.qll index 9ff96a58fdc6..aa429816a7f2 100644 --- a/javascript/ql/lib/semmle/javascript/dependencies/FrameworkLibraries.qll +++ b/javascript/ql/lib/semmle/javascript/dependencies/FrameworkLibraries.qll @@ -312,7 +312,7 @@ private predicate jQueryMarkerComment(Comment c, TopLevel tl, string version) { ")(?: - New Wave Javascript)?.*", 1) or // 1.0.0 and 1.0.1 have the same marker comment; we call them both "1.0" - txt.matches("%jQuery - New Wave Javascript%") and version = "1.0" + txt.contains("jQuery - New Wave Javascript") and version = "1.0" ) } diff --git a/javascript/ql/lib/semmle/javascript/filters/ClassifyFiles.qll b/javascript/ql/lib/semmle/javascript/filters/ClassifyFiles.qll index 8d392bc04482..dcf38df69d1b 100644 --- a/javascript/ql/lib/semmle/javascript/filters/ClassifyFiles.qll +++ b/javascript/ql/lib/semmle/javascript/filters/ClassifyFiles.qll @@ -62,7 +62,7 @@ predicate isTestFile(File f) { or f.getAbsolutePath().regexpMatch(".*/__(mocks|tests)__/.*") or - f.getBaseName().matches("%.test.%") + f.getBaseName().contains(".test.") } /** diff --git a/javascript/ql/lib/semmle/javascript/frameworks/Angular2.qll b/javascript/ql/lib/semmle/javascript/frameworks/Angular2.qll index 9fd24c81a4a4..d497aa020c2c 100644 --- a/javascript/ql/lib/semmle/javascript/frameworks/Angular2.qll +++ b/javascript/ql/lib/semmle/javascript/frameworks/Angular2.qll @@ -256,7 +256,7 @@ module Angular2 { predicate isAngularExpressionAttribute(HTML::Attribute attrib) { attrib.getName().matches("(%)") or attrib.getName().matches("[%]") or - attrib.getName().matches("*ng%") + attrib.getName().startsWith("*ng") } private DataFlow::Node getAttributeValueAsNode(HTML::Attribute attrib) { @@ -601,7 +601,7 @@ module Angular2 { elm = any(ComponentClass cls).getATemplateElement() and // Ignore instantiations of known element (mainly focus on native DOM elements) not elm = any(ComponentClass cls).getATemplateInstantiation() and - not elm.getName().matches("ng-%") and + not elm.getName().startsWith("ng-") and this = elm.getAttributeByName(attributeName) .getCodeInAttribute() diff --git a/javascript/ql/lib/semmle/javascript/frameworks/AngularJS/AngularJSExpressions.qll b/javascript/ql/lib/semmle/javascript/frameworks/AngularJS/AngularJSExpressions.qll index 29d7fe3bdf66..2e5592e55d75 100644 --- a/javascript/ql/lib/semmle/javascript/frameworks/AngularJS/AngularJSExpressions.qll +++ b/javascript/ql/lib/semmle/javascript/frameworks/AngularJS/AngularJSExpressions.qll @@ -832,7 +832,7 @@ class NgDataFlowNode extends TNode instanceof NgAstNode { private predicate fileIsImplicitlyAngularJS(HTML::HtmlFile file) { // The file contains ng-* attributes. exists(HTML::Attribute attrib | - attrib.getName().matches("ng-%") and + attrib.getName().startsWith("ng-") and attrib.getFile() = file ) and // But does not contain the ng-app root element, implying that file is diff --git a/javascript/ql/lib/semmle/javascript/frameworks/AsyncPackage.qll b/javascript/ql/lib/semmle/javascript/frameworks/AsyncPackage.qll index 0545f25a1848..6873dd7d3e82 100644 --- a/javascript/ql/lib/semmle/javascript/frameworks/AsyncPackage.qll +++ b/javascript/ql/lib/semmle/javascript/frameworks/AsyncPackage.qll @@ -124,7 +124,7 @@ module AsyncPackage { "concat", "detect", "each", "eachOf", "forEach", "forEachOf", "every", "filter", "groupBy", "map", "mapValues", "reject", "some", "sortBy", ]) and - if name.matches("%Limit") + if name.endsWith("Limit") then ( iteratorCallbackIndex = 2 and finalCallbackIndex = 3 ) else ( diff --git a/javascript/ql/lib/semmle/javascript/frameworks/Babel.qll b/javascript/ql/lib/semmle/javascript/frameworks/Babel.qll index 9ca47fb47276..0859e9c6b24a 100644 --- a/javascript/ql/lib/semmle/javascript/frameworks/Babel.qll +++ b/javascript/ql/lib/semmle/javascript/frameworks/Babel.qll @@ -12,7 +12,7 @@ module Babel { */ class Config extends JsonObject { Config() { - this.isTopLevel() and this.getJsonFile().getBaseName().matches(".babelrc%") + this.isTopLevel() and this.getJsonFile().getBaseName().startsWith(".babelrc") or this = any(PackageJson pkg).getPropValue("babel") } diff --git a/javascript/ql/lib/semmle/javascript/frameworks/Bundling.qll b/javascript/ql/lib/semmle/javascript/frameworks/Bundling.qll index 314a6343c9f0..8cd925714fa2 100644 --- a/javascript/ql/lib/semmle/javascript/frameworks/Bundling.qll +++ b/javascript/ql/lib/semmle/javascript/frameworks/Bundling.qll @@ -186,7 +186,7 @@ predicate isMultiPartBundle(TopLevel tl) { c1.getTopLevel() = tl and c2.getTopLevel() = tl and c1.getText() = "***MULTI-PART" and - c2.getText().regexpMatch("LOGICAL-PATH:.*") + c2.getText().startsWith("LOGICAL-PATH:") ) } @@ -194,7 +194,7 @@ predicate isMultiPartBundle(TopLevel tl) { * A comment that starts with '!'. Minifiers avoid removing such comments. */ class ExclamationPointComment extends Comment { - ExclamationPointComment() { this.getLine(0).matches("!%") } + ExclamationPointComment() { this.getLine(0).startsWith("!") } } /** diff --git a/javascript/ql/lib/semmle/javascript/frameworks/ClientRequests.qll b/javascript/ql/lib/semmle/javascript/frameworks/ClientRequests.qll index fabf0a6d38f5..909718f6cf64 100644 --- a/javascript/ql/lib/semmle/javascript/frameworks/ClientRequests.qll +++ b/javascript/ql/lib/semmle/javascript/frameworks/ClientRequests.qll @@ -732,7 +732,10 @@ module ClientRequest { /** Gets an event listener registered on this XHR object. */ DataFlow::FunctionNode getAnEventListener() { - result = this.getAPropertyWrite("on" + any(string s)).getRhs().getAFunctionValue() + exists(string propertyName | + propertyName.startsWith("on") | + result = this.getAPropertyWrite(propertyName).getRhs().getAFunctionValue() + ) or result = this.getAMethodCall("addEventListener").getArgument(1).getAFunctionValue() } @@ -924,7 +927,7 @@ module ClientRequest { .getACommandArgument() .(StringOps::ConcatenationRoot) .getConstantStringParts() - .matches("curl %") + .startsWith("curl ") ) } diff --git a/javascript/ql/lib/semmle/javascript/frameworks/Firebase.qll b/javascript/ql/lib/semmle/javascript/frameworks/Firebase.qll index 51e465ef908b..b59021d559cb 100644 --- a/javascript/ql/lib/semmle/javascript/frameworks/Firebase.qll +++ b/javascript/ql/lib/semmle/javascript/frameworks/Firebase.qll @@ -94,8 +94,8 @@ module Firebase { or exists(string name | result = query().getAMethodCall(name) | name = "endAt" or - name = "limitTo" + any(string s) or - name = "orderBy" + any(string s) or + name.startsWith("limitTo") or + name.startsWith("orderBy") or name = "startAt" ) or @@ -183,7 +183,7 @@ module Firebase { class RefBuilderListenCall extends DataFlow::MethodCallNode { RefBuilderListenCall() { this = ref().getAMethodCall() and - this.getMethodName() = "on" + any(string s) + this.getMethodName().startsWith("on") } /** diff --git a/javascript/ql/lib/semmle/javascript/frameworks/Markdown.qll b/javascript/ql/lib/semmle/javascript/frameworks/Markdown.qll index 344bdc2a40fc..4eb6b98bcb96 100644 --- a/javascript/ql/lib/semmle/javascript/frameworks/Markdown.qll +++ b/javascript/ql/lib/semmle/javascript/frameworks/Markdown.qll @@ -140,7 +140,7 @@ module Markdown { exists(UnifiedChain chain | // sanitizer. Mostly looking for `rehype-sanitize`, but also other plugins with `sanitize` in their name. not chain.getAUsedPlugin().getALocalSource() = - DataFlow::moduleImport(any(string s | s.matches("%sanitize%"))) + DataFlow::moduleImport(any(string s | s.contains("sanitize"))) | pred = chain.getInput() and succ = chain.getOutput() diff --git a/javascript/ql/lib/semmle/javascript/frameworks/NoSQL.qll b/javascript/ql/lib/semmle/javascript/frameworks/NoSQL.qll index 3888dede5533..380282d7ed42 100644 --- a/javascript/ql/lib/semmle/javascript/frameworks/NoSQL.qll +++ b/javascript/ql/lib/semmle/javascript/frameworks/NoSQL.qll @@ -57,7 +57,7 @@ private module MongoDB { private class Insertion extends DatabaseAccess, API::CallNode { Insertion() { this = ModelOutput::getATypeNode("mongodb.Collection").getAMember().getACall() and - this.getCalleeName().matches("insert%") + this.getCalleeName().startsWith("insert") } override DataFlow::Node getAQueryArgument() { none() } @@ -154,7 +154,7 @@ private module Mongoose { class Insertion extends DatabaseAccess, API::CallNode { Insertion() { this = ModelOutput::getATypeNode("mongoose.Model").getAMember().getACall() and - this.getCalleeName().matches("insert%") + this.getCalleeName().startsWith("insert") } override DataFlow::Node getAQueryArgument() { none() } diff --git a/javascript/ql/lib/semmle/javascript/frameworks/NodeJSLib.qll b/javascript/ql/lib/semmle/javascript/frameworks/NodeJSLib.qll index 3fe945c1ac47..e26ebe0e92c8 100644 --- a/javascript/ql/lib/semmle/javascript/frameworks/NodeJSLib.qll +++ b/javascript/ql/lib/semmle/javascript/frameworks/NodeJSLib.qll @@ -618,7 +618,7 @@ module NodeJSLib { NodeJSFileSystemAccessRead() { methodName = ["read", "readSync", "readFile", "readFileSync"] } override DataFlow::Node getADataNode() { - if methodName.matches("%Sync") + if methodName.endsWith("Sync") then result = this else ( exists(int i, string paramName | fsDataParam(methodName, i, paramName) | @@ -802,7 +802,7 @@ module NodeJSLib { not result.getALocalSource() instanceof DataFlow::FunctionNode } - override predicate isSync() { methodName.matches("%Sync") } + override predicate isSync() { methodName.endsWith("Sync") } /** Holds if `node` is known to be an options object rather than an argument array or callback. */ pragma[inline] @@ -827,9 +827,9 @@ module NodeJSLib { not result = this.getParameter(0).asSink() and // fork/spawn and all sync methos always has options as the last argument if - methodName.matches("fork%") or - methodName.matches("spawn%") or - methodName.matches("%Sync") + methodName.startsWith("fork") or + methodName.startsWith("spawn") or + methodName.endsWith("Sync") then result = this.getLastArgument() else ( result = this.getParameter(this.getNumArgument() - 2).asSink() and diff --git a/javascript/ql/lib/semmle/javascript/frameworks/ShellJS.qll b/javascript/ql/lib/semmle/javascript/frameworks/ShellJS.qll index fc0e366df4b8..28f53d0da5bd 100644 --- a/javascript/ql/lib/semmle/javascript/frameworks/ShellJS.qll +++ b/javascript/ql/lib/semmle/javascript/frameworks/ShellJS.qll @@ -83,7 +83,7 @@ module ShellJS { predicate hasOptionsArg() { exists(string val | this.getArgument(0).mayHaveStringValue(val) and - val.matches("-%") + val.startsWith("-") ) } diff --git a/javascript/ql/lib/semmle/javascript/frameworks/Spife.qll b/javascript/ql/lib/semmle/javascript/frameworks/Spife.qll index f79a6f11eae9..d811c2dc5781 100644 --- a/javascript/ql/lib/semmle/javascript/frameworks/Spife.qll +++ b/javascript/ql/lib/semmle/javascript/frameworks/Spife.qll @@ -180,7 +180,7 @@ module Spife { this = rh.getARequestSource() .ref() - .getAPropertyRead(any(string s | s.matches("validated%"))) + .getAPropertyRead(any(string s | s.startsWith("validated"))) .getAMethodCall("get") and kind = "body" } diff --git a/javascript/ql/lib/semmle/javascript/frameworks/SystemCommandExecutors.qll b/javascript/ql/lib/semmle/javascript/frameworks/SystemCommandExecutors.qll index 20baafa04755..8344d5dc457c 100644 --- a/javascript/ql/lib/semmle/javascript/frameworks/SystemCommandExecutors.qll +++ b/javascript/ql/lib/semmle/javascript/frameworks/SystemCommandExecutors.qll @@ -94,7 +94,7 @@ private class SystemCommandExecutors extends SystemCommandExecution, DataFlow::I */ bindingset[name] private boolean getSync(string name) { - if name.matches("%Sync") or name.matches("%sync") then result = true else result = false + if name.endsWith("Sync") or name.endsWith("sync") then result = true else result = false } private class RemoteCommandExecutor extends SystemCommandExecution, DataFlow::InvokeNode { diff --git a/javascript/ql/lib/semmle/javascript/frameworks/UriLibraries.qll b/javascript/ql/lib/semmle/javascript/frameworks/UriLibraries.qll index ec85c376b67c..7c4415f1c4f8 100644 --- a/javascript/ql/lib/semmle/javascript/frameworks/UriLibraries.qll +++ b/javascript/ql/lib/semmle/javascript/frameworks/UriLibraries.qll @@ -375,7 +375,7 @@ private module ClosureLibraryUri { base.(SetterCall).getUri() = uri | this = base.getAMethodCall(name) and - name.matches("set%") + name.startsWith("set") ) } diff --git a/javascript/ql/lib/semmle/javascript/frameworks/XmlParsers.qll b/javascript/ql/lib/semmle/javascript/frameworks/XmlParsers.qll index c0a783c17644..8f675b330fa5 100644 --- a/javascript/ql/lib/semmle/javascript/frameworks/XmlParsers.qll +++ b/javascript/ql/lib/semmle/javascript/frameworks/XmlParsers.qll @@ -42,7 +42,7 @@ module XML { exists(string m | call = API::moduleImport("libxmljs").getMember(m).getACall() and this = call.asExpr() and - m.matches("parseXml%") + m.startsWith("parseXml") ) } @@ -192,7 +192,7 @@ module XML { .getAMethodCall("parseFromString") .asExpr() and // type contains the string `xml`, that is, it's not `text/html` - this.getArgument(1).mayHaveStringValue(any(string tp | tp.matches("%xml%"))) + this.getArgument(1).mayHaveStringValue(any(string tp | tp.contains("xml"))) } override JS::Expr getSourceArgument() { result = this.getArgument(0) } @@ -284,7 +284,7 @@ module XML { override DataFlow::Node getAResult() { result = - parser.getReturn().getMember(any(string s | s.matches("on%"))).getAParameter().asSource() + parser.getReturn().getMember(any(string s | s.startsWith("on"))).getAParameter().asSource() } } diff --git a/javascript/ql/lib/semmle/javascript/heuristics/AdditionalFrameworks.qll b/javascript/ql/lib/semmle/javascript/heuristics/AdditionalFrameworks.qll index b02863b5a4b7..059a4b28b38b 100644 --- a/javascript/ql/lib/semmle/javascript/heuristics/AdditionalFrameworks.qll +++ b/javascript/ql/lib/semmle/javascript/heuristics/AdditionalFrameworks.qll @@ -15,7 +15,7 @@ private class ImpreciseLodashMember extends LodashUnderscore::Member { ImpreciseLodashMember() { exists(string lodash | this = DataFlow::moduleMember(lodash, name) | - lodash.matches("%-lodash") or lodash.matches("%-underscore") + lodash.endsWith("-lodash") or lodash.endsWith("-underscore") ) } diff --git a/javascript/ql/lib/semmle/javascript/internal/paths/PackageJsonEx.qll b/javascript/ql/lib/semmle/javascript/internal/paths/PackageJsonEx.qll index 5f4a6eb930ea..5247c167a60d 100644 --- a/javascript/ql/lib/semmle/javascript/internal/paths/PackageJsonEx.qll +++ b/javascript/ql/lib/semmle/javascript/internal/paths/PackageJsonEx.qll @@ -11,7 +11,7 @@ class PackageJsonEx extends PackageJson { or exists(string prop, string prevPath | result = this.getAPartOfExportsSection(prevPath).getPropValue(prop) and - if prop.matches("./%") then pattern = prop.suffix(2) else pattern = prevPath + if prop.startsWith("./") then pattern = prop.suffix(2) else pattern = prevPath ) } @@ -21,7 +21,7 @@ class PackageJsonEx extends PackageJson { predicate hasExactPathMapping(string pattern, string newPath) { this.getAPartOfExportsSection(pattern).getStringValue() = newPath and - not pattern.matches("%*%") + not pattern.contains("*") } predicate hasPrefixPathMapping(string pattern, string newPath) { @@ -122,7 +122,7 @@ private module Resolver = Folder::Resolve; bindingset[name] private string stripPackageScope(string name) { result = name.regexpReplaceAll("^@[^/]+/", "") } -private predicate isImplementationFile(File f) { not f.getBaseName().matches("%.d.ts") } +private predicate isImplementationFile(File f) { not f.getBaseName().endsWith(".d.ts") } File guessPackageJsonMain1(PackageJsonEx pkg) { not isImplementationFile(pkg.getMainFile()) and diff --git a/javascript/ql/lib/semmle/javascript/linters/JSLint.qll b/javascript/ql/lib/semmle/javascript/linters/JSLint.qll index d03ecb2abf9b..6a29d3a9ba4a 100644 --- a/javascript/ql/lib/semmle/javascript/linters/JSLint.qll +++ b/javascript/ql/lib/semmle/javascript/linters/JSLint.qll @@ -79,7 +79,7 @@ abstract class JSLintDirective extends SlashStarComment { */ predicate definesFlag(string name, string value) { exists(string defn | defn = this.getContent().splitAt(",").trim() | - if defn.matches("%:%") + if defn.contains(":") then ( name = defn.splitAt(":", 0).trim() and value = defn.splitAt(":", 1).trim() diff --git a/javascript/ql/lib/semmle/javascript/security/UselessUseOfCat.qll b/javascript/ql/lib/semmle/javascript/security/UselessUseOfCat.qll index e66200370dd6..3f3e8cb29957 100644 --- a/javascript/ql/lib/semmle/javascript/security/UselessUseOfCat.qll +++ b/javascript/ql/lib/semmle/javascript/security/UselessUseOfCat.qll @@ -302,7 +302,7 @@ module PrettyPrintCatCall { then result = str.suffix(5) else // prettify `${newpath}` to just newpath - if str.matches("`${%") and str.matches("%}`") and not str.suffix(3).matches("%{%") + if str.startsWith("`${") and str.endsWith("}`") and not str.suffix(3).contains("{") then result = str.prefix(str.length() - 2).suffix(3) else result = str } diff --git a/javascript/ql/lib/semmle/javascript/security/dataflow/InsecureTemporaryFileCustomizations.qll b/javascript/ql/lib/semmle/javascript/security/dataflow/InsecureTemporaryFileCustomizations.qll index 216482947aba..ffb0872a32c5 100644 --- a/javascript/ql/lib/semmle/javascript/security/dataflow/InsecureTemporaryFileCustomizations.qll +++ b/javascript/ql/lib/semmle/javascript/security/dataflow/InsecureTemporaryFileCustomizations.qll @@ -81,7 +81,7 @@ module InsecureTemporaryFile { OSTempDir() { this = DataFlow::moduleImport("os").getAMemberCall("tmpdir") or - this.getStringValue().matches("/tmp/%") + this.getStringValue().startsWith("/tmp/") } } diff --git a/javascript/ql/lib/semmle/javascript/security/dataflow/MissingRateLimiting.qll b/javascript/ql/lib/semmle/javascript/security/dataflow/MissingRateLimiting.qll index 5cac49d6dd66..554bc6cbcdfa 100644 --- a/javascript/ql/lib/semmle/javascript/security/dataflow/MissingRateLimiting.qll +++ b/javascript/ql/lib/semmle/javascript/security/dataflow/MissingRateLimiting.qll @@ -173,7 +173,7 @@ class RateLimiterFlexibleRateLimiter extends DataFlow::FunctionNode { string rateLimiterClassName, API::Node rateLimiterClass, API::Node rateLimiterConsume, DataFlow::ParameterNode request | - rateLimiterClassName.matches("RateLimiter%") and + rateLimiterClassName.startsWith("RateLimiter") and rateLimiterClass = API::moduleImport("rate-limiter-flexible").getMember(rateLimiterClassName) and rateLimiterConsume = rateLimiterClass.getInstance().getMember("consume") and request = getRouteHandlerParameter(this, "request") and diff --git a/javascript/ql/lib/semmle/javascript/security/dataflow/PrototypePollutionCustomizations.qll b/javascript/ql/lib/semmle/javascript/security/dataflow/PrototypePollutionCustomizations.qll index 1e95e4b550fb..6a96f5e49c9c 100644 --- a/javascript/ql/lib/semmle/javascript/security/dataflow/PrototypePollutionCustomizations.qll +++ b/javascript/ql/lib/semmle/javascript/security/dataflow/PrototypePollutionCustomizations.qll @@ -143,7 +143,7 @@ module PrototypePollution { id = "jquery" and version.maybeBefore("3.4.0") or - id = "lodash" + any(string s) and + id.startsWith("lodash") and version.maybeBefore("4.17.12") or id = "merge" and diff --git a/javascript/ql/lib/semmle/javascript/security/dataflow/UrlConcatenation.qll b/javascript/ql/lib/semmle/javascript/security/dataflow/UrlConcatenation.qll index 81b7be46cb26..b8acef5118f5 100644 --- a/javascript/ql/lib/semmle/javascript/security/dataflow/UrlConcatenation.qll +++ b/javascript/ql/lib/semmle/javascript/security/dataflow/UrlConcatenation.qll @@ -21,7 +21,7 @@ private predicate hasIncompleteSubstring(DataFlow::Node nd) { * Holds if the given data flow node refers to a string that ends with a slash. */ private predicate endsWithSlash(DataFlow::Node nd) { - nd.getStringValue().matches("%/") + nd.getStringValue().endsWith("/") or endsWithSlash(StringConcatenation::getLastOperand(nd)) } diff --git a/javascript/ql/lib/semmle/javascript/security/dataflow/XssThroughDomCustomizations.qll b/javascript/ql/lib/semmle/javascript/security/dataflow/XssThroughDomCustomizations.qll index 865324ed8d5b..e39eb1ccef87 100644 --- a/javascript/ql/lib/semmle/javascript/security/dataflow/XssThroughDomCustomizations.qll +++ b/javascript/ql/lib/semmle/javascript/security/dataflow/XssThroughDomCustomizations.qll @@ -46,8 +46,8 @@ module XssThroughDom { */ bindingset[result] string unsafeAttributeName() { - result.matches("data-%") or - result.matches("aria-%") or + result.startsWith("data-") or + result.startsWith("aria-") or result = ["name", "value", "title", "alt"] } diff --git a/javascript/ql/lib/utils/test/ConsistencyChecking.qll b/javascript/ql/lib/utils/test/ConsistencyChecking.qll index f614a93500d7..fb6f89b6e69e 100644 --- a/javascript/ql/lib/utils/test/ConsistencyChecking.qll +++ b/javascript/ql/lib/utils/test/ConsistencyChecking.qll @@ -68,7 +68,7 @@ private class AssertionComment extends Comment { /** * Holds if a consistency issue is expected at this location. */ - predicate expectConsistencyError() { this.getText().matches("%[INCONSISTENCY]%") } + predicate expectConsistencyError() { this.getText().contains("[INCONSISTENCY]") } } deprecated private DataFlow::Node getASink() { diff --git a/javascript/ql/src/AngularJS/IncompatibleService.ql b/javascript/ql/src/AngularJS/IncompatibleService.ql index 511f5c72cdc5..8a6c1e3d855b 100644 --- a/javascript/ql/src/AngularJS/IncompatibleService.ql +++ b/javascript/ql/src/AngularJS/IncompatibleService.ql @@ -107,7 +107,7 @@ string getServiceKind(InjectableFunctionServiceRequest request, string serviceNa or ( custom instanceof ProviderRecipeDefinition and - if serviceName.matches("%Provider") + if serviceName.endsWith("Provider") then result = "provider" else result = "provider-value" ) diff --git a/javascript/ql/src/AngularJS/InsecureUrlWhitelist.ql b/javascript/ql/src/AngularJS/InsecureUrlWhitelist.ql index a0a9865b455f..80b100e64acd 100644 --- a/javascript/ql/src/AngularJS/InsecureUrlWhitelist.ql +++ b/javascript/ql/src/AngularJS/InsecureUrlWhitelist.ql @@ -65,9 +65,9 @@ class ResourceUrlWhitelistEntry extends Expr { ) and explanation = "the " + componentName + " '" + component + "' is insecurely specified" | - componentName = "scheme" and component.matches("%*%") + componentName = "scheme" and component.contains("*") or - componentName = "domain" and component.matches("%**%") + componentName = "domain" and component.contains("**") or componentName = "TLD" and component = "*" ) diff --git a/javascript/ql/src/DOM/TargetBlank.ql b/javascript/ql/src/DOM/TargetBlank.ql index dc7f1d65e791..a577cefec705 100644 --- a/javascript/ql/src/DOM/TargetBlank.ql +++ b/javascript/ql/src/DOM/TargetBlank.ql @@ -33,7 +33,7 @@ predicate maybeInjectedByAngular() { predicate hasDynamicHrefHostAttributeValue(DOM::ElementDefinition elem) { exists(DOM::AttributeDefinition attr | attr = elem.getAnAttribute() and - attr.getName().matches("%href%") + attr.getName().contains("href") | // unknown string not exists(attr.getStringValue()) diff --git a/javascript/ql/src/Declarations/UnusedParameter.qll b/javascript/ql/src/Declarations/UnusedParameter.qll index b8ff6b1d38e5..956436bd2e50 100644 --- a/javascript/ql/src/Declarations/UnusedParameter.qll +++ b/javascript/ql/src/Declarations/UnusedParameter.qll @@ -73,7 +73,7 @@ predicate isAnAccidentallyUnusedParameter(Parameter p) { not f.inExternsFile() and // and p is not documented as being unused not exists(JSDocParamTag parmdoc | parmdoc.getDocumentedParameter() = pv | - parmdoc.getDescription().toLowerCase().matches("%unused%") + parmdoc.getDescription().toLowerCase().contains("unused") ) and // and f is not marked as abstract not f.getDocumentation().getATag().getTitle() = "abstract" and diff --git a/javascript/ql/src/Declarations/UnusedProperty.ql b/javascript/ql/src/Declarations/UnusedProperty.ql index f5521cfe087e..e7fc06f47b69 100644 --- a/javascript/ql/src/Declarations/UnusedProperty.ql +++ b/javascript/ql/src/Declarations/UnusedProperty.ql @@ -71,7 +71,7 @@ where not ( name = "toString" or name = "valueOf" or - name.matches("@@%") // @@iterator, for example + name.startsWith("@@") // @@iterator, for example ) and // avoid flagging properties that a type system requires not flowsToTypeRestrictedExpression(obj) and diff --git a/javascript/ql/src/Expressions/CompareIdenticalValues.ql b/javascript/ql/src/Expressions/CompareIdenticalValues.ql index 19e9338fb6fd..dfa0f97358e8 100644 --- a/javascript/ql/src/Expressions/CompareIdenticalValues.ql +++ b/javascript/ql/src/Expressions/CompareIdenticalValues.ql @@ -41,7 +41,7 @@ predicate accessWithConversions(Expr e, Variable v) { * Holds if `c` is a comment containing the word "NaN". */ predicate isNaNComment(Comment c, string filePath, int startLine) { - c.getText().matches("%NaN%") and + c.getText().contains("NaN") and c.getLocation().hasLocationInfo(filePath, startLine, _, _, _) } diff --git a/javascript/ql/src/Expressions/UnknownDirective.ql b/javascript/ql/src/Expressions/UnknownDirective.ql index be91cf5ff896..31b8ac30d685 100644 --- a/javascript/ql/src/Expressions/UnknownDirective.ql +++ b/javascript/ql/src/Expressions/UnknownDirective.ql @@ -20,5 +20,5 @@ where // but exclude attribute top-levels: `` not d.getParent() instanceof CodeInAttribute and // exclude babel generated directives like "@babel/helpers - typeof". - not d.getDirectiveText().matches("@babel/helpers%") + not d.getDirectiveText().startsWith("@babel/helpers") select d, "Unknown directive: '" + truncate(d.getDirectiveText(), 20, " ... (truncated)") + "'." diff --git a/javascript/ql/src/NodeJS/UnresolvableImport.ql b/javascript/ql/src/NodeJS/UnresolvableImport.ql index 972a6b21ccb9..e8682715a8d0 100644 --- a/javascript/ql/src/NodeJS/UnresolvableImport.ql +++ b/javascript/ql/src/NodeJS/UnresolvableImport.ql @@ -31,7 +31,7 @@ where // downloaded or generated during the build mod = path.regexpCapture("([^./][^/]*)(/.*|$)", 1) and // exclude WebPack/Require.js loaders - not mod.matches("%!%") and + not mod.contains("!") and // import cannot be resolved statically not exists(r.getImportedModule()) and // no enclosing NPM package declares a dependency on `mod` diff --git a/javascript/ql/src/NodeJS/UnusedDependency.ql b/javascript/ql/src/NodeJS/UnusedDependency.ql index 438f589cac9a..bebb51025b43 100644 --- a/javascript/ql/src/NodeJS/UnusedDependency.ql +++ b/javascript/ql/src/NodeJS/UnusedDependency.ql @@ -104,7 +104,7 @@ predicate implicitRequire(NpmPackage pkg, string name) { setViewEngine.getTopLevel() = pkg.getAModule() | // chop off leading dot, if any - if engine.matches(".%") then name = engine.suffix(1) else name = engine + if engine.startsWith(".") then name = engine.suffix(1) else name = engine ) } diff --git a/javascript/ql/src/Security/CWE-020/IncompleteUrlSchemeCheck.ql b/javascript/ql/src/Security/CWE-020/IncompleteUrlSchemeCheck.ql index 109e63b45b15..ce2bf340cebd 100644 --- a/javascript/ql/src/Security/CWE-020/IncompleteUrlSchemeCheck.ql +++ b/javascript/ql/src/Security/CWE-020/IncompleteUrlSchemeCheck.ql @@ -96,7 +96,7 @@ DataFlow::Node schemeCheck(DataFlow::Node nd, DangerousScheme scheme) { or // propagate through trimming, case conversion, and regexp replace exists(DataFlow::MethodCallNode stringop | - stringop.getMethodName().matches("trim%") or + stringop.getMethodName().startsWith("trim") or stringop.getMethodName().matches("to%Case") or stringop.getMethodName() = ["replace", "replaceAll"] | diff --git a/javascript/ql/src/Security/CWE-384/SessionFixation.ql b/javascript/ql/src/Security/CWE-384/SessionFixation.ql index d7b7d3ac3b41..efee1aff1227 100644 --- a/javascript/ql/src/Security/CWE-384/SessionFixation.ql +++ b/javascript/ql/src/Security/CWE-384/SessionFixation.ql @@ -20,7 +20,7 @@ import javascript pragma[inline] predicate isLoginSetup(Express::RouteSetup setup) { // some path that contains "login" with a write to `req.session` - setup.getPath().matches("%login%") and + setup.getPath().contains("login") and exists( setup .getARouteHandler() diff --git a/javascript/ql/src/Security/CWE-730/ServerCrash.ql b/javascript/ql/src/Security/CWE-730/ServerCrash.ql index 08043bf8c7fe..73934a61dbab 100644 --- a/javascript/ql/src/Security/CWE-730/ServerCrash.ql +++ b/javascript/ql/src/Security/CWE-730/ServerCrash.ql @@ -103,7 +103,7 @@ class AsyncSentinelCall extends DataFlow::CallNode { exists(DataFlow::FunctionNode node | node.getAstNode() = asyncCallee | // manual models exists(string memberName | - not memberName.matches("%Sync") and + not memberName.endsWith("Sync") and this = NodeJSLib::FS::moduleMember(memberName).getACall() and node = this.getCallback([1 .. 2]) ) diff --git a/javascript/ql/src/Statements/ImplicitReturn.ql b/javascript/ql/src/Statements/ImplicitReturn.ql index cf76ec616062..00e30aaab0af 100644 --- a/javascript/ql/src/Statements/ImplicitReturn.ql +++ b/javascript/ql/src/Statements/ImplicitReturn.ql @@ -23,7 +23,7 @@ import semmle.javascript.RestrictedLocations predicate isThrowOrReturn(Stmt s) { s instanceof ReturnStmt or s instanceof ThrowStmt or - s.(ExprStmt).getExpr().(CallExpr).getCalleeName().matches("%throw%") + s.(ExprStmt).getExpr().(CallExpr).getCalleeName().contains("throw") } /** diff --git a/javascript/ql/src/experimental/Security/CWE-444/InsecureHttpParser.ql b/javascript/ql/src/experimental/Security/CWE-444/InsecureHttpParser.ql index ec2c34ba6187..ff5de657fa47 100644 --- a/javascript/ql/src/experimental/Security/CWE-444/InsecureHttpParser.ql +++ b/javascript/ql/src/experimental/Security/CWE-444/InsecureHttpParser.ql @@ -27,7 +27,7 @@ where exists(DataFlow::SourceNode env | env = NodeJSLib::process().getAPropertyRead("env") and disable = env.getAPropertyWrite("NODE_OPTIONS") and - disable.getRhs().getStringValue().matches("%--insecure-http-parser%") + disable.getRhs().getStringValue().contains("--insecure-http-parser") ) or ( diff --git a/javascript/ql/src/experimental/Security/CWE-918/SsrfIpv6TransitionIncompleteGuard.ql b/javascript/ql/src/experimental/Security/CWE-918/SsrfIpv6TransitionIncompleteGuard.ql index 14e0766d796b..47e31499c693 100644 --- a/javascript/ql/src/experimental/Security/CWE-918/SsrfIpv6TransitionIncompleteGuard.ql +++ b/javascript/ql/src/experimental/Security/CWE-918/SsrfIpv6TransitionIncompleteGuard.ql @@ -96,10 +96,10 @@ predicate hasTransitionUnwrap(File f) { exists(StringLiteral s | s.getFile() = f and ( - s.getValue().matches("%64:ff9b%") or - s.getValue().matches("%::ffff%") or - s.getValue().matches("%2002:%") or - s.getValue().matches("%2001:%") + s.getValue().contains("64:ff9b") or + s.getValue().contains("::ffff") or + s.getValue().contains("2002:") or + s.getValue().contains("2001:") ) ) or diff --git a/javascript/ql/test/experimental/TypeOrm/tests.ql b/javascript/ql/test/experimental/TypeOrm/tests.ql index 815265ab9374..983f3976af7a 100644 --- a/javascript/ql/test/experimental/TypeOrm/tests.ql +++ b/javascript/ql/test/experimental/TypeOrm/tests.ql @@ -6,7 +6,7 @@ class InlineTest extends LineComment { InlineTest() { tests = this.getText().regexpCapture("\\s*test:(.*)", 1) } string getPositiveTest() { - result = tests.trim().splitAt(",").trim() and not result.matches("!%") + result = tests.trim().splitAt(",").trim() and not result.startsWith("!") } predicate hasPositiveTest(string test) { test = this.getPositiveTest() } diff --git a/javascript/ql/test/library-tests/Classes/tests.ql b/javascript/ql/test/library-tests/Classes/tests.ql index 2fec85f768cf..695c074bff3a 100644 --- a/javascript/ql/test/library-tests/Classes/tests.ql +++ b/javascript/ql/test/library-tests/Classes/tests.ql @@ -83,4 +83,4 @@ query predicate dataflow = TestFlow::flow/2; query BlockStmt staticInitializer(ClassDefinition cd) { result = cd.getAStaticInitializerBlock() } -query Identifier privateIdentifier() { result.getName().matches("#%") } +query Identifier privateIdentifier() { result.getName().startsWith("#") } diff --git a/javascript/ql/test/library-tests/InterProceduralFlow/DataFlowConfig.qll b/javascript/ql/test/library-tests/InterProceduralFlow/DataFlowConfig.qll index f47fd78c159d..015f49aabc61 100644 --- a/javascript/ql/test/library-tests/InterProceduralFlow/DataFlowConfig.qll +++ b/javascript/ql/test/library-tests/InterProceduralFlow/DataFlowConfig.qll @@ -3,21 +3,21 @@ import javascript module TestConfig implements DataFlow::ConfigSig { predicate isSource(DataFlow::Node src) { exists(VariableDeclarator vd | - vd.getBindingPattern().(VarDecl).getName().matches("%source%") and + vd.getBindingPattern().(VarDecl).getName().contains("source") and src.asExpr() = vd.getInit() ) } predicate isSink(DataFlow::Node snk) { exists(VariableDeclarator vd | - vd.getBindingPattern().(VarDecl).getName().matches("%sink%") and + vd.getBindingPattern().(VarDecl).getName().contains("sink") and snk.asExpr() = vd.getInit() ) } predicate isBarrier(DataFlow::Node node) { exists(Function f | - f.getName().matches("%noReturnTracking%") and + f.getName().contains("noReturnTracking") and node = f.getAReturnedExpr().flow() ) or diff --git a/javascript/ql/test/library-tests/InterProceduralFlow/tests.ql b/javascript/ql/test/library-tests/InterProceduralFlow/tests.ql index a32e996b6b56..3e270cf0ec2b 100644 --- a/javascript/ql/test/library-tests/InterProceduralFlow/tests.ql +++ b/javascript/ql/test/library-tests/InterProceduralFlow/tests.ql @@ -52,21 +52,21 @@ query predicate flowLabels(FlowLabelFlow::PathNode source, FlowLabelFlow::PathNo module TaintConfig implements DataFlow::ConfigSig { predicate isSource(DataFlow::Node src) { exists(VariableDeclarator vd | - vd.getBindingPattern().(VarDecl).getName().matches("%source%") and + vd.getBindingPattern().(VarDecl).getName().contains("source") and src.asExpr() = vd.getInit() ) } predicate isSink(DataFlow::Node snk) { exists(VariableDeclarator vd | - vd.getBindingPattern().(VarDecl).getName().matches("%sink%") and + vd.getBindingPattern().(VarDecl).getName().contains("sink") and snk.asExpr() = vd.getInit() ) } predicate isBarrier(DataFlow::Node node) { exists(Function f | - f.getName().matches("%noReturnTracking%") and + f.getName().contains("noReturnTracking") and node = f.getAReturnedExpr().flow() ) or @@ -81,7 +81,7 @@ query predicate taintTracking(DataFlow::Node src, DataFlow::Node snk) { TaintFlo module GermanConfig implements DataFlow::ConfigSig { predicate isSource(DataFlow::Node src) { exists(VariableDeclarator vd | - vd.getBindingPattern().(VarDecl).getName().matches("%source%") and + vd.getBindingPattern().(VarDecl).getName().contains("source") and src.asExpr() = vd.getInit() ) or @@ -90,7 +90,7 @@ module GermanConfig implements DataFlow::ConfigSig { predicate isSink(DataFlow::Node snk) { exists(VariableDeclarator vd | - vd.getBindingPattern().(VarDecl).getName().matches("%sink%") and + vd.getBindingPattern().(VarDecl).getName().contains("sink") and snk.asExpr() = vd.getInit() ) or @@ -99,7 +99,7 @@ module GermanConfig implements DataFlow::ConfigSig { predicate isBarrier(DataFlow::Node node) { exists(Function f | - f.getName().matches("%noReturnTracking%") and + f.getName().contains("noReturnTracking") and node = f.getAReturnedExpr().flow() ) or diff --git a/javascript/ql/test/library-tests/RangeAnalysis/DeadBranch.ql b/javascript/ql/test/library-tests/RangeAnalysis/DeadBranch.ql index 6ce500a65600..7dbcd8cfa16a 100644 --- a/javascript/ql/test/library-tests/RangeAnalysis/DeadBranch.ql +++ b/javascript/ql/test/library-tests/RangeAnalysis/DeadBranch.ql @@ -4,9 +4,9 @@ class AssertionComment extends LineComment { boolean isOK; AssertionComment() { - isOK = true and this.getText().trim().matches("OK%") + isOK = true and this.getText().trim().startsWith("OK") or - isOK = false and this.getText().trim().matches("NOT OK%") + isOK = false and this.getText().trim().startsWith("NOT OK") } ConditionGuardNode getAGuardNode() { diff --git a/javascript/ql/test/library-tests/RegExp/MissingUnicodeFlag/MissingUnicodeFlag.ql b/javascript/ql/test/library-tests/RegExp/MissingUnicodeFlag/MissingUnicodeFlag.ql index e8d47d789f3d..aa0cec7e8d1d 100644 --- a/javascript/ql/test/library-tests/RegExp/MissingUnicodeFlag/MissingUnicodeFlag.ql +++ b/javascript/ql/test/library-tests/RegExp/MissingUnicodeFlag/MissingUnicodeFlag.ql @@ -3,7 +3,7 @@ import javascript from RegExpLiteral literal, RegExpConstant wideConstant where wideConstant.getLiteral() = literal and - not literal.getFlags().matches("%u%") and + not literal.getFlags().contains("u") and wideConstant.getValue().length() > 1 and ( wideConstant.getParent() instanceof RegExpCharacterClass diff --git a/javascript/ql/test/library-tests/StringConcatenation/ClassContainsTwo.ql b/javascript/ql/test/library-tests/StringConcatenation/ClassContainsTwo.ql index 3c2e8661df0f..3e5aa1aee34a 100644 --- a/javascript/ql/test/library-tests/StringConcatenation/ClassContainsTwo.ql +++ b/javascript/ql/test/library-tests/StringConcatenation/ClassContainsTwo.ql @@ -2,7 +2,7 @@ import javascript // Select all expressions whose string value contains the word "two" predicate containsTwo(DataFlow::Node node) { - node.getStringValue().matches("%two%") + node.getStringValue().contains("two") or containsTwo(node.getAPredecessor()) or diff --git a/javascript/ql/test/library-tests/StringConcatenation/ContainsTwo.ql b/javascript/ql/test/library-tests/StringConcatenation/ContainsTwo.ql index d2d38cbcf741..43e0aebe9626 100644 --- a/javascript/ql/test/library-tests/StringConcatenation/ContainsTwo.ql +++ b/javascript/ql/test/library-tests/StringConcatenation/ContainsTwo.ql @@ -2,7 +2,7 @@ import javascript // Select all expressions whose string value contains the word "two" predicate containsTwo(DataFlow::Node node) { - node.getStringValue().matches("%two%") + node.getStringValue().contains("two") or containsTwo(node.getAPredecessor()) or diff --git a/javascript/ql/test/library-tests/TypeScript/Namespaces/CheckGlobals.ql b/javascript/ql/test/library-tests/TypeScript/Namespaces/CheckGlobals.ql index ad9ea2ece173..32944542bb10 100644 --- a/javascript/ql/test/library-tests/TypeScript/Namespaces/CheckGlobals.ql +++ b/javascript/ql/test/library-tests/TypeScript/Namespaces/CheckGlobals.ql @@ -1,9 +1,9 @@ import javascript string getStringKind(StringLiteral lit) { - result = "global" and lit.getStringValue().matches("global%") + result = "global" and lit.getStringValue().startsWith("global") or - result = "non-global" and not lit.getStringValue().matches("global%") + result = "non-global" and not lit.getStringValue().startsWith("global") } string getVariableKind(Variable variable) { diff --git a/javascript/ql/test/library-tests/dependencies/DependencyCustomizations.qll b/javascript/ql/test/library-tests/dependencies/DependencyCustomizations.qll index e99f57bc6302..e616e83a98b6 100644 --- a/javascript/ql/test/library-tests/dependencies/DependencyCustomizations.qll +++ b/javascript/ql/test/library-tests/dependencies/DependencyCustomizations.qll @@ -6,7 +6,7 @@ class FooTools extends FrameworkLibrary { class FooToolsInstance extends FrameworkLibraryInstance { FooToolsInstance() { - exists(Comment c | c.getTopLevel() = this | c.getText().matches("%FooTools%")) + exists(Comment c | c.getTopLevel() = this | c.getText().contains("FooTools")) } override predicate info(FrameworkLibrary fl, string v) { diff --git a/javascript/ql/test/library-tests/frameworks/Restify2/tests.ql b/javascript/ql/test/library-tests/frameworks/Restify2/tests.ql index 720f35ba21d5..5bcc6b3737ca 100644 --- a/javascript/ql/test/library-tests/frameworks/Restify2/tests.ql +++ b/javascript/ql/test/library-tests/frameworks/Restify2/tests.ql @@ -13,10 +13,10 @@ class InlineTest extends LineComment { InlineTest() { tests = this.getText().regexpCapture("\\s*test:(.*)", 1) } string getPositiveTest() { - result = tests.trim().splitAt(",").trim() and not result.matches("!%") + result = tests.trim().splitAt(",").trim() and not result.startsWith("!") } - string getNegativeTest() { result = tests.trim().splitAt(",").trim() and result.matches("!%") } + string getNegativeTest() { result = tests.trim().splitAt(",").trim() and result.startsWith("!") } predicate hasPositiveTest(string test) { test = this.getPositiveTest() } diff --git a/javascript/ql/test/library-tests/frameworks/Shelljs/ShellJS.ql b/javascript/ql/test/library-tests/frameworks/Shelljs/ShellJS.ql index 42858633cd3a..a5dc53062e70 100644 --- a/javascript/ql/test/library-tests/frameworks/Shelljs/ShellJS.ql +++ b/javascript/ql/test/library-tests/frameworks/Shelljs/ShellJS.ql @@ -3,7 +3,7 @@ import javascript query predicate test_FileSystemAccess(FileSystemAccess access) { any() } query predicate test_MissingFileSystemAccess(VarAccess var) { - var.getName().matches("file%") and + var.getName().startsWith("file") and not exists(FileSystemAccess access | access.getAPathArgument().asExpr() = var) } diff --git a/javascript/ql/test/library-tests/frameworks/Spife/tests.ql b/javascript/ql/test/library-tests/frameworks/Spife/tests.ql index 2ea6fc4bd4c3..d112826a42f0 100644 --- a/javascript/ql/test/library-tests/frameworks/Spife/tests.ql +++ b/javascript/ql/test/library-tests/frameworks/Spife/tests.ql @@ -13,10 +13,10 @@ class InlineTest extends LineComment { InlineTest() { tests = this.getText().regexpCapture("\\s*test:(.*)", 1) } string getPositiveTest() { - result = tests.trim().splitAt(",").trim() and not result.matches("!%") + result = tests.trim().splitAt(",").trim() and not result.startsWith("!") } - string getNegativeTest() { result = tests.trim().splitAt(",").trim() and result.matches("!%") } + string getNegativeTest() { result = tests.trim().splitAt(",").trim() and result.startsWith("!") } predicate hasPositiveTest(string test) { test = this.getPositiveTest() } diff --git a/javascript/ql/test/tutorials/Validating RAML-based APIs/RAML.qll b/javascript/ql/test/tutorials/Validating RAML-based APIs/RAML.qll index 50bd4a6ed033..884f267ae3b1 100644 --- a/javascript/ql/test/tutorials/Validating RAML-based APIs/RAML.qll +++ b/javascript/ql/test/tutorials/Validating RAML-based APIs/RAML.qll @@ -14,7 +14,7 @@ class RamlResource extends YamlMapping { getDocument() instanceof RamlSpec and exists(YamlMapping m, string name | this = m.lookup(name) and - name.matches("/%") + name.startsWith("/") ) } diff --git a/javascript/ql/test/tutorials/Validating RAML-based APIs/query2.ql b/javascript/ql/test/tutorials/Validating RAML-based APIs/query2.ql index 45c9c124be2b..0203f73c5295 100644 --- a/javascript/ql/test/tutorials/Validating RAML-based APIs/query2.ql +++ b/javascript/ql/test/tutorials/Validating RAML-based APIs/query2.ql @@ -13,7 +13,7 @@ class RamlResource extends YamlMapping { this.getDocument() instanceof RamlSpec and exists(YamlMapping m, string name | this = m.lookup(name) and - name.matches("/%") + name.startsWith("/") ) } diff --git a/javascript/ql/test/tutorials/Validating RAML-based APIs/query3.ql b/javascript/ql/test/tutorials/Validating RAML-based APIs/query3.ql index 4b532f69fad8..5631782a801a 100644 --- a/javascript/ql/test/tutorials/Validating RAML-based APIs/query3.ql +++ b/javascript/ql/test/tutorials/Validating RAML-based APIs/query3.ql @@ -13,7 +13,7 @@ class RamlResource extends YamlMapping { this.getDocument() instanceof RamlSpec and exists(YamlMapping m, string name | this = m.lookup(name) and - name.matches("/%") + name.startsWith("/") ) } diff --git a/javascript/ql/test/tutorials/Validating RAML-based APIs/query4.ql b/javascript/ql/test/tutorials/Validating RAML-based APIs/query4.ql index 59921f5b79bc..4262a4eccdec 100644 --- a/javascript/ql/test/tutorials/Validating RAML-based APIs/query4.ql +++ b/javascript/ql/test/tutorials/Validating RAML-based APIs/query4.ql @@ -13,7 +13,7 @@ class RamlResource extends YamlMapping { this.getDocument() instanceof RamlSpec and exists(YamlMapping m, string name | this = m.lookup(name) and - name.matches("/%") + name.startsWith("/") ) } diff --git a/python/ql/consistency-queries/TypeTrackingConsistency.ql b/python/ql/consistency-queries/TypeTrackingConsistency.ql index 645bdef52194..9381f1632d80 100644 --- a/python/ql/consistency-queries/TypeTrackingConsistency.ql +++ b/python/ql/consistency-queries/TypeTrackingConsistency.ql @@ -31,7 +31,7 @@ private module ConsistencyChecksInput implements ConsistencyChecksInputSig { // https://github.com/python/cpython/blob/0fb18b02c8ad56299d6a2910be0bab8ad601ef24/Lib/socketserver.py#L276-L303 // which I couldn't just fix. We ignore the problems here, and instead rely on the // test-case added in https://github.com/github/codeql/pull/15841 - n.getLocation().getFile().getAbsolutePath().matches("%/socketserver.py") + n.getLocation().getFile().getAbsolutePath().endsWith("/socketserver.py") or // for iterable unpacking like `a,b = some_list`, we currently don't want to allow // type-tracking... however, in the future when we allow tracking list indexes diff --git a/python/ql/examples/snippets/raw_string.ql b/python/ql/examples/snippets/raw_string.ql index 347d91ad4128..50cfe6f7bd50 100644 --- a/python/ql/examples/snippets/raw_string.ql +++ b/python/ql/examples/snippets/raw_string.ql @@ -9,5 +9,5 @@ import python from StringLiteral s -where s.getPrefix().matches("%r%") +where s.getPrefix().contains("r") select s diff --git a/python/ql/lib/experimental/cryptography/modules/CryptographyModule.qll b/python/ql/lib/experimental/cryptography/modules/CryptographyModule.qll index 0831d625d803..0f58f0ed2cee 100644 --- a/python/ql/lib/experimental/cryptography/modules/CryptographyModule.qll +++ b/python/ql/lib/experimental/cryptography/modules/CryptographyModule.qll @@ -36,7 +36,7 @@ module Hashes { "HashContext", "typing", "utils" ] and // Don't match things like __file__ - not hashName.regexpMatch("_.*") + not hashName.startsWith("_") } /** @@ -262,7 +262,7 @@ module Encryption { bindingset[rawName] string normalizedEncryptionName(string rawName) { - if rawName.matches("AES%") + if rawName.startsWith("AES") then result = super.normalizeName("AES") else result = super.normalizeName(rawName) } @@ -389,7 +389,7 @@ module Encryption { .getMember("modes") .getMember(name) .getACall() and - not name.regexpMatch("_.*") + not name.startsWith("_") } // https://cryptography.io/en/latest/hazmat/primitives/symmetric-encryption/#module-cryptography.hazmat.primitives.ciphers.modes @@ -421,7 +421,7 @@ module Encryption { .getMember("algorithms") .getMember(name) .getACall() and - not name.regexpMatch("_.*") + not name.startsWith("_") } class CrytographyGenericSymmetricEncryption extends SymmetricEncryptionAlgorithm { @@ -468,7 +468,7 @@ module Encryption { .getMember(name) .getACall() and name != "PaddingContext" and - not name.regexpMatch("_.*") + not name.startsWith("_") } class CryptographyGenericSymmetricPadding extends SymmetricPadding { diff --git a/python/ql/lib/experimental/cryptography/modules/stdlib/HashlibModule.qll b/python/ql/lib/experimental/cryptography/modules/stdlib/HashlibModule.qll index 346512e9a2db..b275631d9ad4 100644 --- a/python/ql/lib/experimental/cryptography/modules/stdlib/HashlibModule.qll +++ b/python/ql/lib/experimental/cryptography/modules/stdlib/HashlibModule.qll @@ -111,7 +111,7 @@ module Hashes { "new", "pbkdf2_hmac", "algorithms_available", "algorithms_guaranteed", "file_digest" ] and // Don't match things like __file__ - not hashName.regexpMatch("_.*") + not hashName.startsWith("_") } /** diff --git a/python/ql/lib/modeling/Util.qll b/python/ql/lib/modeling/Util.qll index e0bbc334e4cb..6478cc23d6a5 100644 --- a/python/ql/lib/modeling/Util.qll +++ b/python/ql/lib/modeling/Util.qll @@ -12,7 +12,7 @@ private import semmle.python.filters.Tests class TestFile extends File { TestFile() { this.getRelativePath().regexpMatch(".*(test|spec|examples).+") and - not this.getAbsolutePath().matches("%/ql/test/%") // allows our test cases to work + not this.getAbsolutePath().contains("/ql/test/") // allows our test cases to work } } diff --git a/python/ql/lib/semmle/python/ApiGraphs.qll b/python/ql/lib/semmle/python/ApiGraphs.qll index efd8141efc6e..67329195079e 100644 --- a/python/ql/lib/semmle/python/ApiGraphs.qll +++ b/python/ql/lib/semmle/python/ApiGraphs.qll @@ -441,7 +441,7 @@ module API { // restrict `moduleImport` so it will never give results for a dotted name. Note // that we cannot move this logic to the `MkModuleImport` construction, since we // need the intermediate API graph nodes for the prefixes in `import foo.bar.baz`. - not m.matches("%.%") + not m.contains(".") } /** @@ -457,7 +457,7 @@ module API { // restrict `moduleImport` so it will never give results for a dotted name. Note // that we cannot move this logic to the `MkModuleImport` construction, since we // need the intermediate API graph nodes for the prefixes in `import foo.bar.baz`. - not m.matches("%.%") + not m.contains(".") } /** Gets a node corresponding to the built-in with the given name, if any. */ @@ -1024,7 +1024,7 @@ module API { lbl = Label::mod(m) and succ = MkModuleImport(m) and // Only allow undotted names to count as base modules. - not m.matches("%.%") + not m.contains(".") ) or /* Step from the dotted module name `foo.bar` to `foo.bar.baz` along an edge labeled `baz` */ @@ -1072,7 +1072,7 @@ module API { newtype TLabel = MkLabelModule(string mod) { exists(Impl::MkModuleImport(mod)) and - not mod.matches("%.%") // only top level modules count as base modules + not mod.contains(".") // only top level modules count as base modules } or MkLabelMember(string member) { member = any(DataFlow::AttrRef pr).getAttributeName() or diff --git a/python/ql/lib/semmle/python/Class.qll b/python/ql/lib/semmle/python/Class.qll index cee0e730cb4f..f2fa477dc751 100644 --- a/python/ql/lib/semmle/python/Class.qll +++ b/python/ql/lib/semmle/python/Class.qll @@ -127,11 +127,11 @@ class Class extends Class_, Scope, AstNode { /** Holds if this is probably a mixin (has 'mixin' or similar in name or docstring) */ predicate isProbableMixin() { ( - this.getName().toLowerCase().matches("%mixin%") + this.getName().toLowerCase().contains("mixin") or - this.getDocString().getText().toLowerCase().matches("%mixin%") + this.getDocString().getText().toLowerCase().contains("mixin") or - this.getDocString().getText().toLowerCase().matches("%mix-in%") + this.getDocString().getText().toLowerCase().contains("mix-in") ) } diff --git a/python/ql/lib/semmle/python/Files.qll b/python/ql/lib/semmle/python/Files.qll index bb3c504654e7..ceca182aed5e 100644 --- a/python/ql/lib/semmle/python/Files.qll +++ b/python/ql/lib/semmle/python/Files.qll @@ -91,7 +91,7 @@ class File extends Container, Impl::File { exists(this.getRelativePath()) and ( // The file doesn't have the extension `.py` but still contains Python statements - not this.getExtension().matches("py%") and + not this.getExtension().startsWith("py") and exists(Stmt s | s.getLocation().getFile() = this) or // The file contains the usual `if __name__ == '__main__':` construction @@ -366,7 +366,7 @@ class SyntaxError extends Location { class EncodingError extends SyntaxError { EncodingError() { /* Leave spaces around 'decode' in unlikely event it occurs as a name in a syntax error */ - this.getMessage().toLowerCase().matches("% decode %") + this.getMessage().toLowerCase().contains(" decode ") } override string toString() { result = "Encoding Error" } diff --git a/python/ql/lib/semmle/python/Import.qll b/python/ql/lib/semmle/python/Import.qll index 1e153a0de036..06441aebc1b3 100644 --- a/python/ql/lib/semmle/python/Import.qll +++ b/python/ql/lib/semmle/python/Import.qll @@ -30,7 +30,7 @@ class ImportExpr extends ImportExpr_ { or exists(string bpnm1 | bpnm1 = this.basePackageName(n - 1) and - bpnm1.matches("%.%") and + bpnm1.contains(".") and result = bpnm1.regexpReplaceAll("\\.[^.]*$", "") ) } diff --git a/python/ql/lib/semmle/python/Module.qll b/python/ql/lib/semmle/python/Module.qll index a30aab452c38..3eed1e5a6c6e 100644 --- a/python/ql/lib/semmle/python/Module.qll +++ b/python/ql/lib/semmle/python/Module.qll @@ -79,13 +79,13 @@ class Module extends Module_, Scope, AstNode { /** Gets the package containing this module (or parent package if this is a package) */ Module getPackage() { - this.getName().matches("%.%") and + this.getName().contains(".") and result.getName() = this.getName().regexpReplaceAll("\\.[^.]*$", "") } /** Gets the name of the package containing this module */ string getPackageName() { - this.getName().matches("%.%") and + this.getName().contains(".") and result = this.getName().regexpReplaceAll("\\.[^.]*$", "") } @@ -195,7 +195,7 @@ private string moduleNameFromBase(Container file) { * the execution. */ private predicate transitively_imported_from_entry_point(File file) { - file.getExtension().matches("%py%") and + file.getExtension().contains("py") and exists(File importer | // Only consider files that are in the source archive exists(importer.getRelativePath()) and @@ -323,7 +323,7 @@ string moduleNameFromFile(Container c) { private predicate isStubRoot(Folder f) { not f.getParent*().isImportRoot() and - f.getAbsolutePath().matches("%/data/python/stubs") + f.getAbsolutePath().endsWith("/data/python/stubs") } /** diff --git a/python/ql/lib/semmle/python/dataflow/new/internal/DataFlowDispatch.qll b/python/ql/lib/semmle/python/dataflow/new/internal/DataFlowDispatch.qll index 4a1f08315caf..5a2091ee11ec 100644 --- a/python/ql/lib/semmle/python/dataflow/new/internal/DataFlowDispatch.qll +++ b/python/ql/lib/semmle/python/dataflow/new/internal/DataFlowDispatch.qll @@ -567,7 +567,7 @@ private CallCfgNode getSuperCall() { * this. */ private predicate ignoreForCallGraph(File f) { - f.getAbsolutePath().matches("%/site-packages/sympy/%") + f.getAbsolutePath().contains("/site-packages/sympy/") } private module TrackFunctionInput implements CallGraphConstruction::Simple::InputSig { diff --git a/python/ql/lib/semmle/python/filters/Tests.qll b/python/ql/lib/semmle/python/filters/Tests.qll index 20f6713a837e..6f82f6283d75 100644 --- a/python/ql/lib/semmle/python/filters/Tests.qll +++ b/python/ql/lib/semmle/python/filters/Tests.qll @@ -6,7 +6,7 @@ abstract class TestScope extends Scope { } class UnitTestClass extends TestScope, Class { UnitTestClass() { exists(API::Node testCaseClass, string testCaseString | - testCaseString.matches("%TestCase") and + testCaseString.endsWith("TestCase") and testCaseClass = any(API::Node mod).getMember(testCaseString) | this.getParent() = testCaseClass.getASubclass*().asSource().asExpr() @@ -20,28 +20,28 @@ abstract class Test extends TestScope { } class UnitTestFunction extends Test { UnitTestFunction() { this.getScope+() instanceof UnitTestClass and - this.(Function).getName().matches("test%") + this.(Function).getName().startsWith("test") } } class PyTestFunction extends Test { PyTestFunction() { exists(Module pytest | pytest.getName() = "pytest") and - this.(Function).getName().matches("test%") + this.(Function).getName().startsWith("test") } } class NoseTestFunction extends Test { NoseTestFunction() { exists(Module nose | nose.getName() = "nose") and - this.(Function).getName().matches("test%") + this.(Function).getName().startsWith("test") } } /** A function that is clearly a test, but doesn't belong to a specific framework */ class UnknownTestFunction extends Test { UnknownTestFunction() { - this.(Function).getName().matches("test%") and + this.(Function).getName().startsWith("test") and this.getEnclosingModule().getFile().getShortName().matches("test_%.py") } } diff --git a/python/ql/lib/semmle/python/frameworks/Peewee.qll b/python/ql/lib/semmle/python/frameworks/Peewee.qll index eedc328d98d0..5f943e11f815 100644 --- a/python/ql/lib/semmle/python/frameworks/Peewee.qll +++ b/python/ql/lib/semmle/python/frameworks/Peewee.qll @@ -39,8 +39,8 @@ module Peewee { // class DBClass extends Class, SelfRefMixin { // DBClass() { // exists(this.getLocation().getFile().getRelativePath()) and - // this.getName().matches("%Database") and - // this.getABase().(Name).getId().matches("%Database") + // this.getName().endsWith("Database") and + // this.getABase().(Name).getId().endsWith("Database") // } // } // diff --git a/python/ql/lib/semmle/python/frameworks/ServerLess.qll b/python/ql/lib/semmle/python/frameworks/ServerLess.qll index 36a4e977c7fa..500b61885976 100644 --- a/python/ql/lib/semmle/python/frameworks/ServerLess.qll +++ b/python/ql/lib/semmle/python/frameworks/ServerLess.qll @@ -43,7 +43,7 @@ private Function getAServerlessHandler() { SL::hasServerlessHandler(stem, handler, _, runtime) and file.getAbsolutePath() = stem + ".py" and // if runtime is specified, it should be python - (runtime = "" or runtime.matches("python%")) + (runtime = "" or runtime.startsWith("python")) | mod.getFile() = file and result.getScope() = mod and diff --git a/python/ql/lib/semmle/python/frameworks/internal/SubclassFinder.qll b/python/ql/lib/semmle/python/frameworks/internal/SubclassFinder.qll index 7916a54afcb5..178c6dfdf00d 100644 --- a/python/ql/lib/semmle/python/frameworks/internal/SubclassFinder.qll +++ b/python/ql/lib/semmle/python/frameworks/internal/SubclassFinder.qll @@ -139,7 +139,7 @@ module NotExposed { predicate isTestCode(AstNode ast) { ast.getScope*() instanceof TestScope or - ast.getLocation().getFile().getRelativePath().matches("tests/%") + ast.getLocation().getFile().getRelativePath().startsWith("tests/") } predicate hasAllStatement(Module mod) { diff --git a/python/ql/lib/semmle/python/objects/TObject.qll b/python/ql/lib/semmle/python/objects/TObject.qll index dd191467c19f..a32a5ebc526f 100644 --- a/python/ql/lib/semmle/python/objects/TObject.qll +++ b/python/ql/lib/semmle/python/objects/TObject.qll @@ -216,7 +216,7 @@ private predicate scope_loads_tuplenode(Scope s, TupleNode origin) { predicate isType(ObjectInternal t) { t.isClass() = true or - t.getOrigin().getEnclosingModule().getName().matches("%typing") + t.getOrigin().getEnclosingModule().getName().endsWith("typing") } private predicate is_power_2(int n) { diff --git a/python/ql/lib/semmle/python/security/dataflow/TarSlipCustomizations.qll b/python/ql/lib/semmle/python/security/dataflow/TarSlipCustomizations.qll index 675f48a9442a..ac8f583773fc 100644 --- a/python/ql/lib/semmle/python/security/dataflow/TarSlipCustomizations.qll +++ b/python/ql/lib/semmle/python/security/dataflow/TarSlipCustomizations.qll @@ -148,9 +148,9 @@ module TarSlip { attr.getObject() = tarInfo | // The assumption that any test that matches %path is a sanitizer might be too broad. - call.getAChild*().(AttrNode).getName().matches("%path") + call.getAChild*().(AttrNode).getName().endsWith("path") or - call.getAChild*().(NameNode).getId().matches("%path") + call.getAChild*().(NameNode).getId().endsWith("path") ) and branch = false } diff --git a/python/ql/lib/semmle/python/types/ModuleObject.qll b/python/ql/lib/semmle/python/types/ModuleObject.qll index 0dfa96e7050c..9719e8733862 100644 --- a/python/ql/lib/semmle/python/types/ModuleObject.qll +++ b/python/ql/lib/semmle/python/types/ModuleObject.qll @@ -67,7 +67,7 @@ abstract class ModuleObject extends Object { /** Gets the package for this module. */ PackageObject getPackage() { - this.getName().matches("%.%") and + this.getName().contains(".") and result.getName() = this.getName().regexpReplaceAll("\\.[^.]*$", "") } diff --git a/python/ql/lib/utils/test/dataflow/MaximalFlowTest.qll b/python/ql/lib/utils/test/dataflow/MaximalFlowTest.qll index cbd3b4c6aa51..b09a2431cf7c 100644 --- a/python/ql/lib/utils/test/dataflow/MaximalFlowTest.qll +++ b/python/ql/lib/utils/test/dataflow/MaximalFlowTest.qll @@ -36,7 +36,7 @@ module MaximalFlowsConfig implements DataFlow::ConfigSig { exists(node.getLocation().getFile().getRelativePath()) and not any(CallNode c).getArg(_) = node.asCfgNode() and not isArgumentNode(node, _, _) and - not node.asCfgNode().(NameNode).getId().matches("SINK%") and + not node.asCfgNode().(NameNode).getId().startsWith("SINK") and not DataFlow::localFlowStep(node, _) } } diff --git a/python/ql/src/Classes/ClassAttributes.qll b/python/ql/src/Classes/ClassAttributes.qll index 58f8ae5dffc9..1156f04569fa 100644 --- a/python/ql/src/Classes/ClassAttributes.qll +++ b/python/ql/src/Classes/ClassAttributes.qll @@ -105,7 +105,7 @@ class CheckClass extends ClassObject { } private predicate probablyAbstract() { - this.getName().matches("Abstract%") + this.getName().startsWith("Abstract") or this.isAbstract() } diff --git a/python/ql/src/Functions/IncorrectRaiseInSpecialMethod.ql b/python/ql/src/Functions/IncorrectRaiseInSpecialMethod.ql index 3cd7e0fe9871..78a7de93d85a 100644 --- a/python/ql/src/Functions/IncorrectRaiseInSpecialMethod.ql +++ b/python/ql/src/Functions/IncorrectRaiseInSpecialMethod.ql @@ -144,7 +144,7 @@ predicate noNeedToAlwaysRaise(Function meth, string message, boolean allowNotImp } /** Holds if `func` has a decorator likely marking it as an abstract method. */ -predicate isAbstract(Function func) { func.getADecorator().(Name).getId().matches("%abstract%") } +predicate isAbstract(Function func) { func.getADecorator().(Name).getId().contains("abstract") } /** Holds if `f` always raises the exception `exec`. */ predicate alwaysRaises(Function f, Expr exec) { diff --git a/python/ql/src/Imports/UnusedImport.ql b/python/ql/src/Imports/UnusedImport.ql index 370daf405fe7..3c12b95138cd 100644 --- a/python/ql/src/Imports/UnusedImport.ql +++ b/python/ql/src/Imports/UnusedImport.ql @@ -105,7 +105,7 @@ private string typehint_comment_in_file(File file) { exists(Comment typehint | file = typehint.getLocation().getFile() and result = typehint.getText() and - result.matches("# type:%") + result.startsWith("# type:") ) } diff --git a/python/ql/src/Lexical/CommentedOutCode.qll b/python/ql/src/Lexical/CommentedOutCode.qll index b26daad14916..d167a1595c79 100644 --- a/python/ql/src/Lexical/CommentedOutCode.qll +++ b/python/ql/src/Lexical/CommentedOutCode.qll @@ -237,15 +237,15 @@ private predicate non_code(Comment c) { | not word1 = a_keyword() or - word1 = keyword_requiring_colon() and not c.getText().matches("%:%") + word1 = keyword_requiring_colon() and not c.getText().contains(":") ) and /* Except comments of the form: # (maybe code) # some comment */ not c.getText().regexpMatch("#\\S+\\s.*#.*") or /* Don't count doctests as code */ - c.getText().matches("%>>>%") + c.getText().contains(">>>") or - c.getText().matches("%...%") + c.getText().contains("...") } private predicate filler(Comment c) { c.getText().regexpMatch("#+[\\s*#-_=+]*") } diff --git a/python/ql/src/Lexical/ToDoComment.ql b/python/ql/src/Lexical/ToDoComment.ql index b8bcf98ada8c..faa6f1b4e7ca 100644 --- a/python/ql/src/Lexical/ToDoComment.ql +++ b/python/ql/src/Lexical/ToDoComment.ql @@ -17,5 +17,5 @@ import python from Comment c -where c.getText().matches("%TODO%") or c.getText().matches("%TO DO%") +where c.getText().contains("TODO") or c.getText().contains("TO DO") select c, c.getText() diff --git a/python/ql/src/Security/CWE-352/CSRFProtectionDisabled.ql b/python/ql/src/Security/CWE-352/CSRFProtectionDisabled.ql index 75b161b9e5b1..61f259d32179 100644 --- a/python/ql/src/Security/CWE-352/CSRFProtectionDisabled.ql +++ b/python/ql/src/Security/CWE-352/CSRFProtectionDisabled.ql @@ -18,7 +18,7 @@ predicate relevantSetting(Http::Server::CsrfProtectionSetting s) { // rule out test code as this is a common place to turn off CSRF protection. // We don't use normal `TestScope` to find test files, since we also want to match // a settings file such as `.../integration-tests/settings.py` - not s.getLocation().getFile().getAbsolutePath().matches("%test%") + not s.getLocation().getFile().getAbsolutePath().contains("test") } predicate vulnerableSetting(Http::Server::CsrfProtectionSetting s) { diff --git a/python/ql/src/Security/CWE-798/HardcodedCredentials.ql b/python/ql/src/Security/CWE-798/HardcodedCredentials.ql index baeaf26514c4..de6805258dc3 100644 --- a/python/ql/src/Security/CWE-798/HardcodedCredentials.ql +++ b/python/ql/src/Security/CWE-798/HardcodedCredentials.ql @@ -71,7 +71,7 @@ predicate maybeCredential(ControlFlowNode f) { exists(IntegerLiteral lit | f.getNode() = lit | not exists(lit.getValue()) and /* Not a set of flags or round number */ - not lit.getN().matches("%00%") + not lit.getN().contains("00") ) } @@ -81,14 +81,14 @@ class HardcodedValueSource extends DataFlow::Node { class CredentialSink extends DataFlow::Node { CredentialSink() { - exists(string s | s.matches("credentials-%") | + exists(string s | s.startsWith("credentials-") | // Actual sink-type will be things like `credentials-password` or `credentials-username` ModelOutput::sinkNode(this, s) ) or exists(string name | name.regexpMatch(getACredentialRegex()) and - not name.matches("%file") + not name.endsWith("file") | exists(DataFlowDispatch::ArgumentPosition pos | pos.isKeyword(name) | this.(DataFlow::ArgumentNode).argumentOf(_, pos) @@ -107,7 +107,7 @@ class CredentialSink extends DataFlow::Node { class CredentialSanitizer extends DataFlow::Node { CredentialSanitizer() { - exists(string s | s.matches("credentials-%") | + exists(string s | s.startsWith("credentials-") | // Whatever the string, this will sanitize flow to all credential sinks. ModelOutput::barrierNode(this, s) ) diff --git a/python/ql/src/Statements/RedundantAssignment.ql b/python/ql/src/Statements/RedundantAssignment.ql index a443e199b1ce..713c6dda23e9 100644 --- a/python/ql/src/Statements/RedundantAssignment.ql +++ b/python/ql/src/Statements/RedundantAssignment.ql @@ -75,7 +75,7 @@ predicate same_attribute(Attribute a1, Attribute a2) { } pragma[nomagic] -Comment pyflakes_comment() { result.getText().toLowerCase().matches("%pyflakes%") } +Comment pyflakes_comment() { result.getText().toLowerCase().contains("pyflakes") } int pyflakes_commented_line(File file) { pyflakes_comment().getLocation().hasLocationInfo(file.getAbsolutePath(), result, _, _, _) diff --git a/python/ql/src/Statements/UnusedExceptionObject.ql b/python/ql/src/Statements/UnusedExceptionObject.ql index 890cdc963aca..a7225ff3f1b6 100644 --- a/python/ql/src/Statements/UnusedExceptionObject.ql +++ b/python/ql/src/Statements/UnusedExceptionObject.ql @@ -33,9 +33,9 @@ predicate isUserDefinedExceptionClass(Class cls) { string getBuiltinExceptionName() { result = Builtins::getBuiltinName() and ( - result.matches("%Error") or - result.matches("%Exception") or - result.matches("%Warning") or + result.endsWith("Error") or + result.endsWith("Exception") or + result.endsWith("Warning") or result = ["GeneratorExit", "KeyboardInterrupt", "StopIteration", "StopAsyncIteration", "SystemExit"] ) diff --git a/python/ql/src/Variables/Definition.qll b/python/ql/src/Variables/Definition.qll index 9bd7130957b6..c85235a7c48c 100644 --- a/python/ql/src/Variables/Definition.qll +++ b/python/ql/src/Variables/Definition.qll @@ -122,9 +122,9 @@ predicate name_acceptable_for_unused_variable(Variable var) { exists(string name | var.getId() = name | name.regexpMatch("_+") or name = "empty" or - name.matches("%unused%") or + name.contains("unused") or name = "dummy" or - name.regexpMatch("__.*") + name.startsWith("__") ) } diff --git a/python/ql/src/Variables/UnusedParameter.ql b/python/ql/src/Variables/UnusedParameter.ql index 1efb984fd0bb..d5da9c3882de 100644 --- a/python/ql/src/Variables/UnusedParameter.ql +++ b/python/ql/src/Variables/UnusedParameter.ql @@ -27,7 +27,7 @@ predicate unused_parameter(FunctionValue f, LocalVariable v) { } predicate is_abstract(FunctionValue func) { - func.getScope().getADecorator().(Name).getId().matches("%abstract%") + func.getScope().getADecorator().(Name).getId().contains("abstract") } from PythonFunctionValue f, LocalVariable v diff --git a/python/ql/src/analysis/ImportFailure.ql b/python/ql/src/analysis/ImportFailure.ql index 760a3693d6ea..8e5c6e03bc25 100644 --- a/python/ql/src/analysis/ImportFailure.ql +++ b/python/ql/src/analysis/ImportFailure.ql @@ -27,11 +27,11 @@ ImportExpr alternative_import(ImportExpr ie) { string os_specific_import(ImportExpr ie) { exists(string name | name = ie.getImportedModuleName() | - name.matches("org.python.%") and result = "java" + name.startsWith("org.python.") and result = "java" or - name.matches("java.%") and result = "java" + name.startsWith("java.") and result = "java" or - name.matches("Carbon.%") and result = "darwin" + name.startsWith("Carbon.") and result = "darwin" or result = "win32" and ( @@ -39,7 +39,7 @@ string os_specific_import(ImportExpr ie) { name = "_win32api" or name = "_winreg" or name = "nt" or - name.matches("win32%") or + name.startsWith("win32") or name = "ntpath" ) or @@ -47,7 +47,7 @@ string os_specific_import(ImportExpr ie) { (name = "posix" or name = "posixpath") or result = "unsupported" and - (name = "__pypy__" or name = "ce" or name.matches("riscos%")) + (name = "__pypy__" or name = "ce" or name.startsWith("riscos")) ) } @@ -64,7 +64,7 @@ final class FinalControlFlowNode = ControlFlowNode; class VersionTest extends FinalControlFlowNode { VersionTest() { exists(string name | - name.matches("%version%") and + name.contains("version") and this.(CompareNode) .getAChild+() .(ControlFlowNodeWithPointsTo) diff --git a/python/ql/src/experimental/Security/CWE-287-ConstantSecretKey/WebAppConstantSecretKey.ql b/python/ql/src/experimental/Security/CWE-287-ConstantSecretKey/WebAppConstantSecretKey.ql index f63f590ba376..af2f65e29965 100644 --- a/python/ql/src/experimental/Security/CWE-287-ConstantSecretKey/WebAppConstantSecretKey.ql +++ b/python/ql/src/experimental/Security/CWE-287-ConstantSecretKey/WebAppConstantSecretKey.ql @@ -44,7 +44,7 @@ private module WebAppConstantSecretKeyConfig implements DataFlow::StateConfigSig .matches(["%test%", "%demo%", "%example%", "%sample%"]) and // but that also meant all data-flow nodes in query tests were excluded... so we had // to add this: - not node.getLocation().getFile().getRelativePath().matches("%query-tests/Security/CWE-287%") + not node.getLocation().getFile().getRelativePath().contains("query-tests/Security/CWE-287") } predicate isSink(DataFlow::Node sink, FlowState state) { diff --git a/python/ql/src/experimental/Security/CWE-287-ConstantSecretKey/WebAppConstantSecretKeyFlask.qll b/python/ql/src/experimental/Security/CWE-287-ConstantSecretKey/WebAppConstantSecretKeyFlask.qll index 139f3e58f243..d4839d40d72a 100644 --- a/python/ql/src/experimental/Security/CWE-287-ConstantSecretKey/WebAppConstantSecretKeyFlask.qll +++ b/python/ql/src/experimental/Security/CWE-287-ConstantSecretKey/WebAppConstantSecretKeyFlask.qll @@ -86,13 +86,13 @@ module FlaskConstantSecretKeyConfig { then file.getShortName() = flaskInstance().asSource().getLocation().getFile().getShortName() else ( - fileNamehelper.matches("%.py") and + fileNamehelper.endsWith(".py") and file.getShortName().matches("%" + configFileName + "%") and // after spliting, don't look at %py% pattern configFileName != ".py" or // in case of referencing to a directory which then we must look for __init__.py file - not fileNamehelper.matches("%.py") and + not fileNamehelper.endsWith(".py") and file.getRelativePath() .matches("%" + fileNamehelper.replaceAll(".", "/") + "/__init__.py") ) diff --git a/python/ql/src/experimental/cryptography/example_alerts/WeakBlockMode.ql b/python/ql/src/experimental/cryptography/example_alerts/WeakBlockMode.ql index f0f7253589c2..dd16921f75b1 100644 --- a/python/ql/src/experimental/cryptography/example_alerts/WeakBlockMode.ql +++ b/python/ql/src/experimental/cryptography/example_alerts/WeakBlockMode.ql @@ -21,7 +21,7 @@ where .getFile() .getAbsolutePath() .toString() - .matches("%cryptography/hazmat/%") and + .contains("cryptography/hazmat/") and ( op instanceof BlockMode and // ECB is only allowed for KeyWrapOperations, i.e., only alert on ECB is not a KeyWrapOperation diff --git a/python/ql/src/experimental/semmle/python/libraries/PyJWT.qll b/python/ql/src/experimental/semmle/python/libraries/PyJWT.qll index caf09b4bd99a..cf5ea260bbbf 100644 --- a/python/ql/src/experimental/semmle/python/libraries/PyJWT.qll +++ b/python/ql/src/experimental/semmle/python/libraries/PyJWT.qll @@ -100,7 +100,7 @@ private module PyJwt { exists(KeyValuePair optionsDict, NameConstant falseName | falseName.getId() = "False" and optionsDict = this.getOptions().asExpr().(Dict).getItem(_) and - optionsDict.getKey().(Str_).getS().matches("%verify%") and + optionsDict.getKey().(Str_).getS().contains("verify") and falseName = optionsDict.getValue() ) } diff --git a/python/ql/src/experimental/semmle/python/libraries/PythonJose.qll b/python/ql/src/experimental/semmle/python/libraries/PythonJose.qll index d17f5ec62d56..e6ca3b2f3aad 100644 --- a/python/ql/src/experimental/semmle/python/libraries/PythonJose.qll +++ b/python/ql/src/experimental/semmle/python/libraries/PythonJose.qll @@ -97,7 +97,7 @@ private module PythonJose { exists(KeyValuePair optionsDict, NameConstant falseName | falseName.getId() = "False" and optionsDict = this.getOptions().asExpr().(Dict).getItem(_) and - optionsDict.getKey().(Str_).getS().matches("%verify%") and + optionsDict.getKey().(Str_).getS().contains("verify") and falseName = optionsDict.getValue() ) } diff --git a/python/ql/src/experimental/semmle/python/security/DecompressionBomb.qll b/python/ql/src/experimental/semmle/python/security/DecompressionBomb.qll index a00548e00161..582921f8798f 100644 --- a/python/ql/src/experimental/semmle/python/security/DecompressionBomb.qll +++ b/python/ql/src/experimental/semmle/python/security/DecompressionBomb.qll @@ -155,7 +155,7 @@ module TarFile { .asExpr() .(StringLiteral) .getText() - .matches("r:%") + .startsWith("r:") ) } @@ -273,7 +273,7 @@ module Gzip { .asExpr() .(StringLiteral) .getText() - .matches("%r%") + .contains("r") ) ) } @@ -315,7 +315,7 @@ module Bz2 { .asExpr() .(StringLiteral) .getText() - .matches("%r%") + .contains("r") ) ) } @@ -357,7 +357,7 @@ module Lzma { .asExpr() .(StringLiteral) .getText() - .matches("%r%") + .contains("r") ) ) } @@ -397,7 +397,7 @@ module Zstd { .asExpr() .(StringLiteral) .getText() - .matches("%r%") + .contains("r") ) ) } diff --git a/python/ql/src/external/Thrift.qll b/python/ql/src/external/Thrift.qll index 330aab7ee3f0..38787c51d3ff 100644 --- a/python/ql/src/external/Thrift.qll +++ b/python/ql/src/external/Thrift.qll @@ -83,7 +83,7 @@ abstract class ThriftNamedElement extends ThriftElement { } class ThriftType extends ThriftNamedElement { - ThriftType() { kind.matches("%type") } + ThriftType() { kind.endsWith("type") } override ThriftElement getNameElement() { result = this.getChild(0) diff --git a/python/ql/src/meta/debug/SimpleClassDebug.ql b/python/ql/src/meta/debug/SimpleClassDebug.ql index 017d3f858e91..4d4cb12ed011 100644 --- a/python/ql/src/meta/debug/SimpleClassDebug.ql +++ b/python/ql/src/meta/debug/SimpleClassDebug.ql @@ -8,7 +8,7 @@ import semmle.python.dataflow.new.internal.DataFlowPrivate predicate interestingClass(Class cls) { cls.getName() = "YourClassName" - // and cls.getLocation().getFile().getAbsolutePath().matches("%/folder/file.py") + // and cls.getLocation().getFile().getAbsolutePath().endsWith("/folder/file.py") } query predicate superClasses(Class cls, Class super_) { diff --git a/python/ql/test/extractor-tests/flags/Flags.ql b/python/ql/test/extractor-tests/flags/Flags.ql index 60a484d7f09d..c25620b4926e 100644 --- a/python/ql/test/extractor-tests/flags/Flags.ql +++ b/python/ql/test/extractor-tests/flags/Flags.ql @@ -2,7 +2,7 @@ import python from string k, string v where - k.matches("options.%") and - not k.matches("options.verbos%") and + k.startsWith("options.") and + not k.startsWith("options.verbos") and py_flags_versioned(k, v, _) select k, v diff --git a/python/ql/test/library-tests/PointsTo/functions/Calls.ql b/python/ql/test/library-tests/PointsTo/functions/Calls.ql index 659ba4143f63..7aa3206ac0ee 100644 --- a/python/ql/test/library-tests/PointsTo/functions/Calls.ql +++ b/python/ql/test/library-tests/PointsTo/functions/Calls.ql @@ -8,5 +8,5 @@ where or func.getAFunctionCall() = call and kind = "function" ) and - call.getLocation().getFile().getShortName().matches("odasa%") + call.getLocation().getFile().getShortName().startsWith("odasa") select call.getLocation().getStartLine(), call.toString(), func.toString(), kind diff --git a/python/ql/test/library-tests/PointsTo/general/interesting.qll b/python/ql/test/library-tests/PointsTo/general/interesting.qll index 58a8ebf03dcd..31d8c18c0bb8 100644 --- a/python/ql/test/library-tests/PointsTo/general/interesting.qll +++ b/python/ql/test/library-tests/PointsTo/general/interesting.qll @@ -4,7 +4,7 @@ predicate of_interest(ControlFlowNode n, int line) { exists(Location l, File f | l = n.getLocation() | line = l.getStartLine() and f = l.getFile() and - f.getAbsolutePath().matches("%test.py%") and + f.getAbsolutePath().contains("test.py") and exists(Comment c | c.getLocation().getStartLine() < line and c.getLocation().getFile() = f diff --git a/python/ql/test/library-tests/PointsTo/new/Consistency.ql b/python/ql/test/library-tests/PointsTo/new/Consistency.ql index 0ee1a392ef23..63275038f4c3 100644 --- a/python/ql/test/library-tests/PointsTo/new/Consistency.ql +++ b/python/ql/test/library-tests/PointsTo/new/Consistency.ql @@ -104,7 +104,7 @@ predicate ssa_consistency(string clsname, string problem, string what) { or exists(EssaDefinition def | clsname = def.getAQlClass() and - clsname.matches("Essa%") and + clsname.startsWith("Essa") and what = " at " + def.getLocation() and problem = "not covered by Python-specific subclass." ) diff --git a/python/ql/test/library-tests/PointsTo/new/PointsToMissing.ql b/python/ql/test/library-tests/PointsTo/new/PointsToMissing.ql index 271f35db9963..5e578641df78 100644 --- a/python/ql/test/library-tests/PointsTo/new/PointsToMissing.ql +++ b/python/ql/test/library-tests/PointsTo/new/PointsToMissing.ql @@ -12,7 +12,7 @@ predicate relevant_node(ControlFlowNode n) { exists(Comment c, string filepath, int bl | n.getNode().getScope().getLocation().hasLocationInfo(filepath, bl, _, _, _) and c.getLocation().hasLocationInfo(filepath, bl, _, _, _) and - c.getText().matches("%check") and + c.getText().endsWith("check") and not n.(NameNode).isStore() ) } diff --git a/python/tools/recorded-call-graph-metrics/ql/lib/RecordedCalls.qll b/python/tools/recorded-call-graph-metrics/ql/lib/RecordedCalls.qll index 79d01776728b..fab1ba348ae8 100644 --- a/python/tools/recorded-call-graph-metrics/ql/lib/RecordedCalls.qll +++ b/python/tools/recorded-call-graph-metrics/ql/lib/RecordedCalls.qll @@ -149,10 +149,10 @@ class XmlExternalCallee extends XmlCallee { */ private Builtin traverse_qualname(Builtin parent, string qualname) { not qualname = "__objclass__" and - not qualname.matches("%.%") and + not qualname.contains(".") and result = parent.getMember(qualname) or - qualname.matches("%.%") and + qualname.contains(".") and exists(string before_dot, string after_dot, Builtin intermediate_parent | qualname = before_dot + "." + after_dot and not before_dot = "__objclass__" and diff --git a/ql/ql/src/codeql_ql/ast/Ast.qll b/ql/ql/src/codeql_ql/ast/Ast.qll index 7cdfd6163d2a..14030b808b10 100644 --- a/ql/ql/src/codeql_ql/ast/Ast.qll +++ b/ql/ql/src/codeql_ql/ast/Ast.qll @@ -2832,7 +2832,7 @@ module YAML { ( name = dep or - name.matches("codeql/%") and + name.startsWith("codeql/") and name = dep + "/all" ) ) diff --git a/ql/ql/src/codeql_ql/ast/Yaml.qll b/ql/ql/src/codeql_ql/ast/Yaml.qll index c6d8926c63bc..a05bfaa21aaf 100644 --- a/ql/ql/src/codeql_ql/ast/Yaml.qll +++ b/ql/ql/src/codeql_ql/ast/Yaml.qll @@ -126,7 +126,7 @@ class QlRefDocument extends YamlDocument { predicate usesInlineExpectations() { exists(YamlMapping n, YamlScalar value | n.getDocument() = this and - value.getValue().matches("%InlineExpectations%") + value.getValue().contains("InlineExpectations") | value = n.lookup("postprocess") or @@ -157,7 +157,7 @@ class QlRefDocument extends YamlDocument { or exists(YamlMapping n, YamlScalar value | n.getDocument() = this and - value.getValue().matches("%PrintAst%") + value.getValue().contains("PrintAst") | value = n.lookup("query") ) diff --git a/ql/ql/src/codeql_ql/bugs/PathProblemQueryQuery.qll b/ql/ql/src/codeql_ql/bugs/PathProblemQueryQuery.qll index 9533d2abea52..b54a0afd8d21 100644 --- a/ql/ql/src/codeql_ql/bugs/PathProblemQueryQuery.qll +++ b/ql/ql/src/codeql_ql/bugs/PathProblemQueryQuery.qll @@ -28,13 +28,13 @@ class Query extends File { predicate isPathProblem() { exists(QLDoc doc | doc.getLocation().getFile() = this | - doc.getContents().matches("%@kind path-problem%") + doc.getContents().contains("@kind path-problem") ) } predicate isProblem() { exists(QLDoc doc | doc.getLocation().getFile() = this | - doc.getContents().matches("%@kind problem%") + doc.getContents().contains("@kind problem") ) } diff --git a/ql/ql/src/codeql_ql/style/DeadCodeQuery.qll b/ql/ql/src/codeql_ql/style/DeadCodeQuery.qll index 4098511e9067..cfd417977291 100644 --- a/ql/ql/src/codeql_ql/style/DeadCodeQuery.qll +++ b/ql/ql/src/codeql_ql/style/DeadCodeQuery.qll @@ -45,8 +45,8 @@ private AstNode discardPredicate() { AstNode hackyShouldBeTreatedAsAlive() { // Stages from the shared DataFlow impl are copy-pasted, so predicates that are dead in one stage are not dead in another. - result = any(Module mod | mod.getName().matches("Stage%")).getAMember().(ClasslessPredicate) and - result.getLocation().getFile().getBaseName().matches("DataFlowImpl%") + result = any(Module mod | mod.getName().startsWith("Stage")).getAMember().(ClasslessPredicate) and + result.getLocation().getFile().getBaseName().startsWith("DataFlowImpl") or // Python stuff result.(Predicate).getName() = "quickEvalMe" // private predicate used for quick-eval @@ -244,7 +244,7 @@ private AstNode benign() { result.(ClasslessPredicate).getName() = "forceStage" or result.getLocation().getFile().getBaseName() = "Caching.qll" or // sometimes contains dead code - ignore - result.getLocation().getFile().getRelativePath().matches("%/tutorials/%") or + result.getLocation().getFile().getRelativePath().contains("/tutorials/") or result = classUnion() } @@ -290,5 +290,5 @@ AstNode unQueryable(string msg) { not result = benign() and not result.getParent() = any(AstNode node | not node = queryable()) and msg = result.getLocation().getFile().getBaseName() and - result.getLocation().getFile().getAbsolutePath().matches("%/javascript/%") + result.getLocation().getFile().getAbsolutePath().contains("/javascript/") } diff --git a/ql/ql/src/queries/bugs/PathProblemQuery.ql b/ql/ql/src/queries/bugs/PathProblemQuery.ql index 2baa86540312..e30c0c642c39 100644 --- a/ql/ql/src/queries/bugs/PathProblemQuery.ql +++ b/ql/ql/src/queries/bugs/PathProblemQuery.ql @@ -24,5 +24,5 @@ where query.hasEdgesRelation(pred) and msg = "A problem query should not have a $@." ) and - not query.getAbsolutePath().matches("%/test/%") + not query.getAbsolutePath().contains("/test/") select query, msg, pred, "edges relation" diff --git a/ql/ql/src/queries/performance/AbstractClassImport.ql b/ql/ql/src/queries/performance/AbstractClassImport.ql index 24e05860f0af..ef666abcbd2b 100644 --- a/ql/ql/src/queries/performance/AbstractClassImport.ql +++ b/ql/ql/src/queries/performance/AbstractClassImport.ql @@ -21,15 +21,15 @@ File imports(File file) { ) } -predicate testFile(File f) { f.getRelativePath().matches("%/ql/test/%") } +predicate testFile(File f) { f.getRelativePath().contains("/ql/test/") } -predicate nonTestQuery(File f) { f.getBaseName().matches("%.ql") and not testFile(f) } +predicate nonTestQuery(File f) { f.getBaseName().endsWith(".ql") and not testFile(f) } predicate liveNonTestFile(File f) { exists(File query | nonTestQuery(query) and f = imports*(query)) } -predicate experimentalFile(File f) { f.getRelativePath().matches("%/experimental/%") } +predicate experimentalFile(File f) { f.getRelativePath().contains("/experimental/") } Class getASubclassOfAbstract(Class ab) { ab.isAbstract() and diff --git a/ql/ql/src/queries/performance/VarUnusedInDisjunct.ql b/ql/ql/src/queries/performance/VarUnusedInDisjunct.ql index e6db3ad3d989..d2a6ba272ded 100644 --- a/ql/ql/src/queries/performance/VarUnusedInDisjunct.ql +++ b/ql/ql/src/queries/performance/VarUnusedInDisjunct.ql @@ -183,7 +183,7 @@ predicate badDisjunction(EffectiveDisjunction disj, VarDef var, AstNode notBound var = disj.getEnclosingPredicate().getParameter(_) ) and // recursion prevention never runs, it's a compile-time check, so we remove those results here - not disj.getEnclosingPredicate().getParent().(Class).getName().matches("%RecursionPrevention") and // these are by design + not disj.getEnclosingPredicate().getParent().(Class).getName().endsWith("RecursionPrevention") and // these are by design // not a small type not isSmallType(var.getType()) and // one of the branches is a tiny assignment. These are usually intentional cartesian products (and not too big). diff --git a/ql/ql/src/queries/style/AlertMessage.ql b/ql/ql/src/queries/style/AlertMessage.ql index 4e874fc2eb88..36e7f329c6f6 100644 --- a/ql/ql/src/queries/style/AlertMessage.ql +++ b/ql/ql/src/queries/style/AlertMessage.ql @@ -69,8 +69,8 @@ String shouldHaveFullStop(Select sel) { | str order by i ) and - not result.getValue().matches("%.") and - not result.getValue().matches("%?") + not result.getValue().endsWith(".") and + not result.getValue().endsWith("?") } /** @@ -202,10 +202,10 @@ AstNode getAlertLocLink(Select sel) { from AstNode node, string msg, Select sel where - not node.getLocation().getFile().getAbsolutePath().matches("%/test/%") and - not node.getLocation().getFile().getAbsolutePath().matches("%/examples/%") and - not node.getLocation().getFile().getAbsolutePath().matches("%/experimental/%") and - not node.getLocation().getFile().getAbsolutePath().matches("%/meta/%") and + not node.getLocation().getFile().getAbsolutePath().contains("/test/") and + not node.getLocation().getFile().getAbsolutePath().contains("/examples/") and + not node.getLocation().getFile().getAbsolutePath().contains("/experimental/") and + not node.getLocation().getFile().getAbsolutePath().contains("/meta/") and sel.getQueryDoc().getQueryKind() = ["problem", "path-problem"] and ( node = shouldHaveFullStop(sel) and diff --git a/ql/ql/src/queries/style/AndroidIdPrefix.ql b/ql/ql/src/queries/style/AndroidIdPrefix.ql index 88b479cc7d4d..5e86dbd9cd46 100644 --- a/ql/ql/src/queries/style/AndroidIdPrefix.ql +++ b/ql/ql/src/queries/style/AndroidIdPrefix.ql @@ -14,7 +14,7 @@ predicate importsAndroidModule(TopLevel t) { t.getFile() = any(YAML::QLPack pack | pack.getADependency*().getExtractor() = "java").getAFileInPack() and exists(Import i | t.getAnImport() = i | - i.getImportString().toLowerCase().matches("%android%") + i.getImportString().toLowerCase().contains("android") or exists(TopLevel t2 | t2.getAModule() = i.getResolvedModule().asModule() and @@ -25,8 +25,8 @@ predicate importsAndroidModule(TopLevel t) { from QueryDoc d where - d.getLocation().getFile().getRelativePath().matches("%src/Security/%") and - not d.getQueryId().matches("android/%") and + d.getLocation().getFile().getRelativePath().contains("src/Security/") and + not d.getQueryId().startsWith("android/") and not d.getQueryId() = ["improper-intent-verification", "improper-webview-certificate-validation"] and // known badly identified queries that sadly we can't fix importsAndroidModule(d.getParent()) select d, "This Android query is missing the `android/` prefix in its `@id`." diff --git a/ql/ql/src/queries/style/ConsistentAlertMessage.ql b/ql/ql/src/queries/style/ConsistentAlertMessage.ql index beb1d7b5f4da..6a305a3dd1d2 100644 --- a/ql/ql/src/queries/style/ConsistentAlertMessage.ql +++ b/ql/ql/src/queries/style/ConsistentAlertMessage.ql @@ -60,7 +60,7 @@ Select parseSelect(string id, string lang, string msg, string fingerPrint) { msg = getMessage(result).toLowerCase() // case normalize, because some languages upper-case methods. ) and // excluding experimental - not result.getLocation().getFile().getRelativePath().matches("%/experimental/%") and + not result.getLocation().getFile().getRelativePath().contains("/experimental/") and not lang = "ql" // excluding QL-for-QL } diff --git a/ql/ql/src/queries/style/DBTypeInNonLib.ql b/ql/ql/src/queries/style/DBTypeInNonLib.ql index fac17d2423ec..6d057d2315c2 100644 --- a/ql/ql/src/queries/style/DBTypeInNonLib.ql +++ b/ql/ql/src/queries/style/DBTypeInNonLib.ql @@ -17,11 +17,11 @@ from TypeExpr te where te.isDBType() and not te.getLocation().getFile().getAbsolutePath().matches("%/" + folderWithDbTypes() + "/%") and - exists(File f | f.getAbsolutePath().matches("%/lib/%")) and + exists(File f | f.getAbsolutePath().contains("/lib/")) and // it is needed in one case. not te = any(Class c | c.getName() = "SuppressionScope").getASuperType() and // QL-for-QL only has a src/ folder. - not te.getLocation().getFile().getAbsolutePath().matches("%/ql/ql/%") and + not te.getLocation().getFile().getAbsolutePath().contains("/ql/ql/") and // tests are allowed to use DB types. - not te.getLocation().getFile().getAbsolutePath().matches("%/test/%") + not te.getLocation().getFile().getAbsolutePath().contains("/test/") select te, "Database type used outside the language lib/ folder." diff --git a/ql/ql/src/queries/style/DataFlowConfigModuleNaming.ql b/ql/ql/src/queries/style/DataFlowConfigModuleNaming.ql index 736a65c65d9a..c8ce57900eee 100644 --- a/ql/ql/src/queries/style/DataFlowConfigModuleNaming.ql +++ b/ql/ql/src/queries/style/DataFlowConfigModuleNaming.ql @@ -40,5 +40,5 @@ class DataFlowInternalFile extends File { from DataFlowConfigModule m where not m.getFile() instanceof DataFlowInternalFile and - not m.getName().matches("%Config") + not m.getName().endsWith("Config") select m, "Modules implementing a data flow configuration should end in `Config`." diff --git a/ql/ql/src/queries/style/NonDocBlock.ql b/ql/ql/src/queries/style/NonDocBlock.ql index 1031afa40205..ce0b8e7fadf4 100644 --- a/ql/ql/src/queries/style/NonDocBlock.ql +++ b/ql/ql/src/queries/style/NonDocBlock.ql @@ -32,7 +32,7 @@ BlockComment getACommentThatCouldBeQLDoc(File file) { exists(Location loc | loc = result.getLocation() | file = loc.getFile() and loc.getFile().getExtension() = "qll" and - not result.getContents().matches("/**%") and + not result.getContents().startsWith("/**") and not [loc.getStartLine(), loc.getEndLine()] = getLinesWithNonComment(file) and ( // above something that can be commented. diff --git a/ql/ql/src/queries/style/ToStringInQueryLogic.ql b/ql/ql/src/queries/style/ToStringInQueryLogic.ql index cef95412f142..1bb15b87cf4c 100644 --- a/ql/ql/src/queries/style/ToStringInQueryLogic.ql +++ b/ql/ql/src/queries/style/ToStringInQueryLogic.ql @@ -323,7 +323,7 @@ where // The call doesn't flow to a select not flowsToSelect(call) and // It's in a query - call.getLocation().getFile().getBaseName().matches("%.ql") and + call.getLocation().getFile().getBaseName().endsWith(".ql") and // ... and not in a test not ( call.getLocation() diff --git a/ql/ql/test/queries/performance/VarUnusedInDisjunct/Test.qll b/ql/ql/test/queries/performance/VarUnusedInDisjunct/Test.qll index b4b30f100286..19b4e4b7f1df 100644 --- a/ql/ql/test/queries/performance/VarUnusedInDisjunct/Test.qll +++ b/ql/ql/test/queries/performance/VarUnusedInDisjunct/Test.qll @@ -11,7 +11,7 @@ class MyStr extends string { } predicate bad1(Big b) { - b.toString().matches("%foo") + b.toString().endsWith("foo") or any() // $ Alert } @@ -37,42 +37,42 @@ string good1(Big t) { or result instanceof MyStr // <- t unused here, but that's ok because of the conjunct that binds t. ) and - t.toString().regexpMatch(".*foo") + t.toString().endsWith("foo") } predicate helper(Big a, Big b) { a = b and - a.toString().matches("%foo") + a.toString().endsWith("foo") } predicate bad4(Big fromType, Big toType) { helper(fromType, toType) or - fromType.toString().matches("%foo") + fromType.toString().endsWith("foo") or helper(toType, fromType) // $ Alert } predicate good2(Big t) { exists(Small other | - t.toString().matches("%foo") + t.toString().endsWith("foo") or - other.toString().matches("%foo") // <- t unused here, but that's ok because of the conjunct (exists) that binds t. + other.toString().endsWith("foo") // <- t unused here, but that's ok because of the conjunct (exists) that binds t. | - t.toString().regexpMatch(".*foo") + t.toString().endsWith("foo") ) } predicate mixed1(Big good, Small small) { - good.toString().matches("%foo") + good.toString().endsWith("foo") or good = any(Big bad | - small.toString().matches("%foo") and + small.toString().endsWith("foo") and // the use of good is fine, the comparison further up binds it. // the same is not true for bad. - (bad.toString().matches("%foo") or good.toString().regexpMatch("foo.*")) and // $ Alert - small.toString().regexpMatch(".*foo") + (bad.toString().endsWith("foo") or good.toString().startsWith("foo")) and // $ Alert + small.toString().endsWith("foo") ) } @@ -81,7 +81,7 @@ newtype OtherSmall = Small2(boolean b) { b = true } or Small3(boolean b, Small o) { b = true and - o.toString().matches("%foo") + o.toString().endsWith("foo") } predicate good3(OtherSmall small) { @@ -91,10 +91,10 @@ predicate good3(OtherSmall small) { } predicate good4(Big big, Small small) { - big.toString().matches("%foo") + big.toString().endsWith("foo") or // assignment to small type, intentional cartesian product - small = any(Small s | s.toString().matches("%foo")) + small = any(Small s | s.toString().endsWith("foo")) } predicate good5(Big bb, Big v, boolean certain) { @@ -107,38 +107,38 @@ predicate good5(Big bb, Big v, boolean certain) { v = any(Big lsv | lsv.getEnclosingPredicate() = bb.(Expr).getEnclosingPredicate() and - (lsv.toString().matches("%foo") or v.toString().matches("%foo")) and + (lsv.toString().endsWith("foo") or v.toString().endsWith("foo")) and certain = false ) } -predicate bad5(Big bb) { if none() then bb.toString().matches("%foo") else any() } // $ Alert +predicate bad5(Big bb) { if none() then bb.toString().endsWith("foo") else any() } // $ Alert pragma[inline] predicate good5(Big a, Big b) { // fine. Assumes it's used somewhere where `a` and `b` are bound. - b = any(Big bb | bb.toString().matches("%foo")) + b = any(Big bb | bb.toString().endsWith("foo")) or - a = any(Big bb | bb.toString().matches("%foo")) + a = any(Big bb | bb.toString().endsWith("foo")) } predicate bad6(Big a) { ( - a.toString().matches("%foo") // bad + a.toString().endsWith("foo") // bad or any() // $ Alert ) and ( - a.toString().matches("%foo") // also bad + a.toString().endsWith("foo") // also bad or any() // $ Alert ) } predicate good6(Big a) { - a.toString().matches("%foo") and + a.toString().endsWith("foo") and ( - a.toString().matches("%foo") // good, `a` is bound on the branch of the conjunction. + a.toString().endsWith("foo") // good, `a` is bound on the branch of the conjunction. or any() ) @@ -146,11 +146,11 @@ predicate good6(Big a) { predicate good7() { exists(Big l, Big r | - l.toString().matches("%foo1") and - r.toString().matches("%foo2") + l.toString().endsWith("foo1") and + r.toString().endsWith("foo2") or - l.toString().matches("%foo3") and - r.toString().matches("%foo4") + l.toString().endsWith("foo3") and + r.toString().endsWith("foo4") | not (l.toString().regexpMatch("%foo5") or r.toString().regexpMatch("%foo6")) and (l.toString().regexpMatch("%foo7") or r.toString().regexpMatch("%foo8")) @@ -163,7 +163,7 @@ class HasField extends Big { HasField() { field = this or - this.toString().matches("%foo") // $ Alert // <- field only defined here. + this.toString().endsWith("foo") // $ Alert // <- field only defined here. } Big getField() { result = field } diff --git a/ruby/ql/lib/codeql/ruby/ApiGraphs.qll b/ruby/ql/lib/codeql/ruby/ApiGraphs.qll index a74b0e081995..b336169c5481 100644 --- a/ruby/ql/lib/codeql/ruby/ApiGraphs.qll +++ b/ruby/ql/lib/codeql/ruby/ApiGraphs.qll @@ -999,7 +999,7 @@ module API { private string resolveTopLevel(ConstantReadAccess read) { result = read.getModule().getQualifiedName() and - not result.matches("%::%") + not result.contains("::") } /** diff --git a/ruby/ql/lib/codeql/ruby/ast/internal/Constant.qll b/ruby/ql/lib/codeql/ruby/ast/internal/Constant.qll index 7c935391ace2..a3f21ed6d1cf 100644 --- a/ruby/ql/lib/codeql/ruby/ast/internal/Constant.qll +++ b/ruby/ql/lib/codeql/ruby/ast/internal/Constant.qll @@ -616,7 +616,7 @@ private class ConstantReadAccessSynth extends ConstantAccess, TConstantReadAcces final override Expr getScopeExpr() { synthChild(this, 0, result) } - final override predicate hasGlobalScope() { value.matches("::%") } + final override predicate hasGlobalScope() { value.startsWith("::") } } overlay[local] @@ -631,5 +631,5 @@ private class ConstantWriteAccessSynth extends ConstantAccess, TConstantWriteAcc final override Expr getScopeExpr() { synthChild(this, 0, result) } - final override predicate hasGlobalScope() { value.matches("::%") } + final override predicate hasGlobalScope() { value.startsWith("::") } } diff --git a/ruby/ql/lib/codeql/ruby/ast/internal/Literal.qll b/ruby/ql/lib/codeql/ruby/ast/internal/Literal.qll index c6f906a87528..7f775a13d13e 100644 --- a/ruby/ql/lib/codeql/ruby/ast/internal/Literal.qll +++ b/ruby/ql/lib/codeql/ruby/ast/internal/Literal.qll @@ -18,15 +18,15 @@ int parseInteger(Ruby::Integer i) { s.charAt(0) != "0" and result = s.toInt() or - s.matches("0b%") and result = parseBinaryInt(s.suffix(2)) + s.startsWith("0b") and result = parseBinaryInt(s.suffix(2)) or - s.matches("0x%") and result = parseHexInt(s.suffix(2)) + s.startsWith("0x") and result = parseHexInt(s.suffix(2)) or s.charAt(0) = "0" and not s.charAt(1) = ["b", "x", "o"] and result = parseOctalInt(s.suffix(1)) or - s.matches("0o%") and + s.startsWith("0o") and result = parseOctalInt(s.suffix(2)) ) } diff --git a/ruby/ql/lib/codeql/ruby/dataflow/internal/FlowSummaryImpl.qll b/ruby/ql/lib/codeql/ruby/dataflow/internal/FlowSummaryImpl.qll index ede0e898bcb3..654779bc61c8 100644 --- a/ruby/ql/lib/codeql/ruby/dataflow/internal/FlowSummaryImpl.qll +++ b/ruby/ql/lib/codeql/ruby/dataflow/internal/FlowSummaryImpl.qll @@ -342,7 +342,7 @@ module ParsePositions { includeUnknown = false or result = arg and - not arg.matches("%!") and + not arg.endsWith("!") and includeUnknown = true } diff --git a/ruby/ql/lib/codeql/ruby/frameworks/ActionController.qll b/ruby/ql/lib/codeql/ruby/frameworks/ActionController.qll index a1d56e5fe15f..2e9c631a0d41 100644 --- a/ruby/ql/lib/codeql/ruby/frameworks/ActionController.qll +++ b/ruby/ql/lib/codeql/ruby/frameworks/ActionController.qll @@ -387,7 +387,7 @@ private string getActionControllerClassRelativePath(ActionControllerClass cls) { pragma[nomagic] private string getErbFileRelativePath(ErbFile templateFile) { result = templateFile.getRelativePath() and - result.matches("%app/views/layouts/%") + result.contains("app/views/layouts/") } bindingset[result] diff --git a/ruby/ql/lib/codeql/ruby/frameworks/GraphQL.qll b/ruby/ql/lib/codeql/ruby/frameworks/GraphQL.qll index a335f406ae00..fbf73c8bb0c7 100644 --- a/ruby/ql/lib/codeql/ruby/frameworks/GraphQL.qll +++ b/ruby/ql/lib/codeql/ruby/frameworks/GraphQL.qll @@ -200,7 +200,7 @@ class GraphqlLoadMethod extends Method, Http::Server::RequestHandler::Range { GraphqlLoadMethod() { this.getEnclosingModule() = resolvableClass and - this.getName().regexpMatch("^load_.*") + this.getName().startsWith("load_") } override Parameter getARoutedParameter() { result = this.getAParameter() } diff --git a/ruby/ql/lib/codeql/ruby/frameworks/Rails.qll b/ruby/ql/lib/codeql/ruby/frameworks/Rails.qll index 4a9f7fa9c87a..918a3f796aef 100644 --- a/ruby/ql/lib/codeql/ruby/frameworks/Rails.qll +++ b/ruby/ql/lib/codeql/ruby/frameworks/Rails.qll @@ -160,7 +160,7 @@ private module Config { */ private module Settings { private predicate isInTestConfiguration(Location loc) { - loc.getFile().getRelativePath().matches("%test/%") or + loc.getFile().getRelativePath().contains("test/") or loc.getFile().getStem() = "test" } diff --git a/ruby/ql/lib/codeql/ruby/frameworks/Sinatra.qll b/ruby/ql/lib/codeql/ruby/frameworks/Sinatra.qll index 3ffdb915c6f3..cc87b42a4c2a 100644 --- a/ruby/ql/lib/codeql/ruby/frameworks/Sinatra.qll +++ b/ruby/ql/lib/codeql/ruby/frameworks/Sinatra.qll @@ -109,7 +109,7 @@ module Sinatra { private ErbFile getTemplateFile(MethodCall erbCall) { erbCall.getMethodName() = "erb" and result.getTemplateName() = erbCall.getArgument(0).getConstantValue().getStringlikeValue() and - result.getRelativePath().matches("%views/%") + result.getRelativePath().contains("views/") } pragma[nomagic] diff --git a/ruby/ql/lib/codeql/ruby/frameworks/actiondispatch/internal/Routing.qll b/ruby/ql/lib/codeql/ruby/frameworks/actiondispatch/internal/Routing.qll index ac545481b9c7..ed1c1f426883 100644 --- a/ruby/ql/lib/codeql/ruby/frameworks/actiondispatch/internal/Routing.qll +++ b/ruby/ql/lib/codeql/ruby/frameworks/actiondispatch/internal/Routing.qll @@ -931,7 +931,7 @@ module Routing { private string singularize(string input) { exists(string prefix | prefix = input.regexpCapture("(.*)ies", 1) | result = prefix + "y") or - not input.matches("%ies") and + not input.endsWith("ies") and exists(string prefix | prefix = input.regexpCapture("(.*)s", 1) | result = prefix) or not input.regexpMatch(".*(ies|s)") and result = input diff --git a/ruby/ql/lib/codeql/ruby/security/SensitiveActions.qll b/ruby/ql/lib/codeql/ruby/security/SensitiveActions.qll index e0dc68e7136e..3531819e1778 100644 --- a/ruby/ql/lib/codeql/ruby/security/SensitiveActions.qll +++ b/ruby/ql/lib/codeql/ruby/security/SensitiveActions.qll @@ -218,7 +218,7 @@ class AuthorizationCall extends SensitiveAction, DataFlow::CallNode { callWithIgnoredReturnValue(c) or // Method names ending in `!` are likely to be actions. - s.matches("%!") + s.endsWith("!") ) ) } diff --git a/ruby/ql/lib/codeql/ruby/security/internal/CleartextSources.qll b/ruby/ql/lib/codeql/ruby/security/internal/CleartextSources.qll index f2867fa14bfe..ccec94eaa278 100644 --- a/ruby/ql/lib/codeql/ruby/security/internal/CleartextSources.qll +++ b/ruby/ql/lib/codeql/ruby/security/internal/CleartextSources.qll @@ -117,7 +117,7 @@ module CleartextSources { // We explicitly exclude element references, element assignments, and // mutation methods. not name = ["[]", "[]="] and - not name.matches("%!") + not name.endsWith("!") } /** diff --git a/ruby/ql/src/queries/modeling/internal/Util.qll b/ruby/ql/src/queries/modeling/internal/Util.qll index a418f8614f42..df383dc12a14 100644 --- a/ruby/ql/src/queries/modeling/internal/Util.qll +++ b/ruby/ql/src/queries/modeling/internal/Util.qll @@ -11,7 +11,7 @@ private import codeql.ruby.ApiGraphs class TestFile extends File { TestFile() { this.getRelativePath().regexpMatch(".*(test|spec|examples).+") and - not this.getAbsolutePath().matches("%/ql/test/%") // allows our test cases to work + not this.getAbsolutePath().contains("/ql/test/") // allows our test cases to work } } diff --git a/ruby/ql/src/queries/security/cwe-798/HardcodedCredentials.ql b/ruby/ql/src/queries/security/cwe-798/HardcodedCredentials.ql index bba71760818d..5599415b9f02 100644 --- a/ruby/ql/src/queries/security/cwe-798/HardcodedCredentials.ql +++ b/ruby/ql/src/queries/security/cwe-798/HardcodedCredentials.ql @@ -65,7 +65,7 @@ predicate maybeCredential(Expr e) { exists(IntegerLiteral lit | lit = e | not exists(lit.getValue()) and /* Not a set of flags or round number */ - not lit.toString().matches("%00%") + not lit.toString().contains("00") ) } @@ -86,7 +86,7 @@ private string getACredentialRegExp() { bindingset[name] private predicate maybeCredentialName(string name) { name.regexpMatch(getACredentialRegExp()) and - not name.matches("%file") + not name.endsWith("file") } // Positional parameter diff --git a/ruby/ql/src/queries/summary/LinesOfUserCode.ql b/ruby/ql/src/queries/summary/LinesOfUserCode.ql index 91471c417ee1..67cea4180086 100644 --- a/ruby/ql/src/queries/summary/LinesOfUserCode.ql +++ b/ruby/ql/src/queries/summary/LinesOfUserCode.ql @@ -14,7 +14,7 @@ import codeql.ruby.AST select sum(RubyFile f | f.fromSource() and exists(f.getRelativePath()) and - not f.getAbsolutePath().matches("%/vendor/%") + not f.getAbsolutePath().contains("/vendor/") | f.getNumberOfLinesOfCode() ) diff --git a/rust/ql/examples/snippets/simple_constant_password.ql b/rust/ql/examples/snippets/simple_constant_password.ql index e43238cedd4f..65e2cd084b0a 100644 --- a/rust/ql/examples/snippets/simple_constant_password.ql +++ b/rust/ql/examples/snippets/simple_constant_password.ql @@ -33,7 +33,7 @@ module ConstantPasswordConfig implements DataFlow::ConfigSig { exists(Call call, Function target, int argIndex, Variable v | call.getStaticTarget() = target and v.getParameter() = target.getParam(argIndex) and - v.getText().matches("pass%") and + v.getText().startsWith("pass") and call.getPositionalArgument(argIndex) = node.asExpr() ) } diff --git a/rust/ql/integration-tests/subst/file.ql b/rust/ql/integration-tests/subst/file.ql index 81573d40c6df..ff1bf442e561 100644 --- a/rust/ql/integration-tests/subst/file.ql +++ b/rust/ql/integration-tests/subst/file.ql @@ -2,6 +2,6 @@ import rust from File f, string relative where - not f.getURL().matches("%/target/intree/%") and + not f.getURL().contains("/target/intree/") and if exists(f.getRelativePath()) then relative = "relative" else relative = "" select f, relative diff --git a/rust/ql/lib/codeql/rust/frameworks/rustcrypto/RustCrypto.qll b/rust/ql/lib/codeql/rust/frameworks/rustcrypto/RustCrypto.qll index 41fdd4abe728..a4bbd725ad70 100644 --- a/rust/ql/lib/codeql/rust/frameworks/rustcrypto/RustCrypto.qll +++ b/rust/ql/lib/codeql/rust/frameworks/rustcrypto/RustCrypto.qll @@ -11,7 +11,7 @@ private import codeql.rust.internal.typeinference.Type bindingset[algorithmName] private string simplifyAlgorithmName(string algorithmName) { // the cipher library gives triple-DES names like "TdesEee2" and "TdesEde2" - if algorithmName.matches("Tdes%") then result = "3des" else result = algorithmName + if algorithmName.startsWith("Tdes") then result = "3des" else result = algorithmName } /** diff --git a/rust/ql/lib/codeql/rust/frameworks/stdlib/Builtins.qll b/rust/ql/lib/codeql/rust/frameworks/stdlib/Builtins.qll index 1a545da0db5c..66b7b8be4692 100644 --- a/rust/ql/lib/codeql/rust/frameworks/stdlib/Builtins.qll +++ b/rust/ql/lib/codeql/rust/frameworks/stdlib/Builtins.qll @@ -209,7 +209,7 @@ class PtrMutType extends PtrTypeImpl { /** A builtin tuple type `(T1, T2, ...)`. */ class TupleType extends BuiltinType { - TupleType() { this.getName().matches("Tuple%") } + TupleType() { this.getName().startsWith("Tuple") } /** Gets the arity of this tuple type. */ int getArity() { diff --git a/rust/ql/lib/codeql/rust/internal/PathResolution.qll b/rust/ql/lib/codeql/rust/internal/PathResolution.qll index 30ddb6f12c36..19b27984d348 100644 --- a/rust/ql/lib/codeql/rust/internal/PathResolution.qll +++ b/rust/ql/lib/codeql/rust/internal/PathResolution.qll @@ -2353,7 +2353,7 @@ private module Debug { Locatable getRelevantLocatable() { exists(string filepath, int startline, int startcolumn, int endline, int endcolumn | result.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) and - filepath.matches("%/main.rs") and + filepath.endsWith("/main.rs") and startline = 52 ) } diff --git a/rust/ql/lib/codeql/rust/internal/typeinference/TypeInference.qll b/rust/ql/lib/codeql/rust/internal/typeinference/TypeInference.qll index c6daffd4007c..d73fed003eb0 100644 --- a/rust/ql/lib/codeql/rust/internal/typeinference/TypeInference.qll +++ b/rust/ql/lib/codeql/rust/internal/typeinference/TypeInference.qll @@ -3176,7 +3176,7 @@ private module Debug { Locatable getRelevantLocatable() { exists(string filepath, int startline, int startcolumn, int endline, int endcolumn | result.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) and - filepath.matches("%/main.rs") and + filepath.endsWith("/main.rs") and startline = 103 ) } diff --git a/rust/ql/lib/utils/test/InlineFlowTest.qll b/rust/ql/lib/utils/test/InlineFlowTest.qll index 2b43ed49bf87..635830a2cd0e 100644 --- a/rust/ql/lib/utils/test/InlineFlowTest.qll +++ b/rust/ql/lib/utils/test/InlineFlowTest.qll @@ -59,7 +59,7 @@ private module FlowTestImpl implements InputSig { result = getSummaryNodeArgString(n) ) and // Don't use the result if it contains spaces - not result.matches("% %") + not result.contains(" ") } bindingset[src, sink] diff --git a/rust/ql/lib/utils/test/PathResolutionInlineExpectationsTest.qll b/rust/ql/lib/utils/test/PathResolutionInlineExpectationsTest.qll index a6ab8cd48cab..ca8ec89bc591 100644 --- a/rust/ql/lib/utils/test/PathResolutionInlineExpectationsTest.qll +++ b/rust/ql/lib/utils/test/PathResolutionInlineExpectationsTest.qll @@ -19,7 +19,7 @@ private module ResolveTest implements TestSig { c.getLocation().hasLocationInfo(filepath, line, _, _, _) and c.getCommentText().trim() = text and c.fromSource() and - not text.matches("$%") + not text.startsWith("$") ) } diff --git a/rust/ql/test/TestUtils.qll b/rust/ql/test/TestUtils.qll index a55c24544b83..d09d733bec1e 100644 --- a/rust/ql/test/TestUtils.qll +++ b/rust/ql/test/TestUtils.qll @@ -26,6 +26,6 @@ predicate commentAt(string text, string filepath, int line) { c.getLocation().hasLocationInfo(filepath, line, _, _, _) and c.getCommentText().trim() = text and c.fromSource() and - not text.matches("$%") + not text.startsWith("$") ) } diff --git a/shared/dataflow/codeql/dataflow/internal/DataFlowImpl.qll b/shared/dataflow/codeql/dataflow/internal/DataFlowImpl.qll index 24aad2ebbce2..deda5e1f0c1b 100644 --- a/shared/dataflow/codeql/dataflow/internal/DataFlowImpl.qll +++ b/shared/dataflow/codeql/dataflow/internal/DataFlowImpl.qll @@ -308,7 +308,7 @@ module MakeImpl Lang> { bindingset[label1, label2] pragma[inline_late] private string mergeLabels(string label1, string label2) { - if label2.matches("Sink:%") + if label2.startsWith("Sink:") then if label1 = "" then result = label2 else result = label1 + " " + label2 else // Big-step, hidden nodes, and summaries all may need to merge labels. diff --git a/shared/regex/codeql/regex/OverlyLargeRangeQuery.qll b/shared/regex/codeql/regex/OverlyLargeRangeQuery.qll index 88645a2abde1..4ec780cb2d9a 100644 --- a/shared/regex/codeql/regex/OverlyLargeRangeQuery.qll +++ b/shared/regex/codeql/regex/OverlyLargeRangeQuery.qll @@ -288,7 +288,7 @@ module Make { pragma[inline] private string escapeRegExpCharacterClassEscape(RegExpCharacterClassEscape escape) { - if escape.toString().matches("%-%") + if escape.toString().contains("-") then result = Strings::escape(escape.toString()) // might contain unicode characters else result = escape.toString() // just a plain `\d` or `\w` etc. Those are already escaped. } diff --git a/shared/util/codeql/util/FilePath.qll b/shared/util/codeql/util/FilePath.qll index ff62ce6ee5e3..2aba81d8ad67 100644 --- a/shared/util/codeql/util/FilePath.qll +++ b/shared/util/codeql/util/FilePath.qll @@ -82,7 +82,7 @@ abstract class NormalizableFilepath extends string { if norm != "" then result = norm else - if this.matches("/%") + if this.startsWith("/") then result = "/" else result = "." ) diff --git a/shared/util/codeql/util/FileSystem.qll b/shared/util/codeql/util/FileSystem.qll index fe724190f746..5dbf94cf8341 100644 --- a/shared/util/codeql/util/FileSystem.qll +++ b/shared/util/codeql/util/FileSystem.qll @@ -171,7 +171,7 @@ module Make { absPath = pref and result = "" or absPath = pref.regexpReplaceAll("/$", "") + "/" + result and - not result.matches("/%") + not result.startsWith("/") ) } @@ -296,7 +296,7 @@ module Make { private string getPathSegmentAsGlobRegexp(string segment) { allowGlobs() and segment = getPathSegment(_, _) and - segment.matches("%*%") and + segment.contains("*") and not segment = ["*", "**"] and // these are special-cased result = segment.regexpReplaceAll("[^a-zA-Z0-9*]", "\\\\$0").replaceAll("*", ".*") } diff --git a/shared/yaml/codeql/serverless/ServerLess.qll b/shared/yaml/codeql/serverless/ServerLess.qll index 009b50c7d1ca..4db75a7f5990 100644 --- a/shared/yaml/codeql/serverless/ServerLess.qll +++ b/shared/yaml/codeql/serverless/ServerLess.qll @@ -113,7 +113,7 @@ module ServerLess { exists(YamlMapping resource | ymlFile = resource.getFile() | // Official AWS API uses "AWS::Serverless::Function" but we've seen that Aliyun uses the same schema ("Aliyun::Serverless::Function"), so we allow any prefix to be used. // Note that "AWS::Serverless::Function" expands to a "AWS::Lambda::Function" when deployed (described here: https://github.com/aws/serverless-application-model#getting-started). Also note that a "AWS::Lambda::Function" requires code in its definition, so needs different handling (see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html) - resource.lookup("Type").(YamlScalar).getValue().regexpMatch(".*::Serverless::Function") and + resource.lookup("Type").(YamlScalar).getValue().endsWith("::Serverless::Function") and framework = lookupValue(resource, "Type") and exists(YamlMapping properties | properties = resource.lookup("Properties") | ( diff --git a/shared/yaml/codeql/yaml/Yaml.qll b/shared/yaml/codeql/yaml/Yaml.qll index f0d9424ca53a..37a22085fec6 100644 --- a/shared/yaml/codeql/yaml/Yaml.qll +++ b/shared/yaml/codeql/yaml/Yaml.qll @@ -453,14 +453,14 @@ module Make { /** Join-order helper for `getTargetPath`. Gets the path but only if it is an absolute path. */ private string getAbsolutePath() { result = this.getValue() and - result.matches("/%") + result.startsWith("/") } /** Join-order helper for `getTargetPath`. Gets the path, but only if it is a relative path. */ pragma[noinline] private string getRelativePath() { result = this.getValue() and - not result.matches("/%") + not result.startsWith("/") } } diff --git a/swift/ql/consistency-queries/UnresolvedAstNodes.ql b/swift/ql/consistency-queries/UnresolvedAstNodes.ql index b77e526c5732..41f46627f1cd 100644 --- a/swift/ql/consistency-queries/UnresolvedAstNodes.ql +++ b/swift/ql/consistency-queries/UnresolvedAstNodes.ql @@ -3,6 +3,6 @@ import swift from AstNode n, string cls where cls = n.getAPrimaryQlClass() and - cls.matches("Unresolved%") and + cls.startsWith("Unresolved") and not n.getLocation() instanceof UnknownLocation select n, cls diff --git a/swift/ql/integration-tests/linux/RegexLiteralExpr/RegexLiteralExpr.ql b/swift/ql/integration-tests/linux/RegexLiteralExpr/RegexLiteralExpr.ql index 88e06d9f781b..ae02fa411949 100644 --- a/swift/ql/integration-tests/linux/RegexLiteralExpr/RegexLiteralExpr.ql +++ b/swift/ql/integration-tests/linux/RegexLiteralExpr/RegexLiteralExpr.ql @@ -3,7 +3,7 @@ import codeql.swift.elements from RegexLiteralExpr x, Type getType, string getPattern, int getVersion where - x.getLocation().getFile().getName().matches("%/regex.swift") and + x.getLocation().getFile().getName().endsWith("/regex.swift") and getType = x.getType() and getPattern = x.getPattern() and getVersion = x.getVersion() diff --git a/swift/ql/integration-tests/posix/deduplication/BuiltinTypes.ql b/swift/ql/integration-tests/posix/deduplication/BuiltinTypes.ql index 6ca09fc77ce0..2f5e97bed64f 100644 --- a/swift/ql/integration-tests/posix/deduplication/BuiltinTypes.ql +++ b/swift/ql/integration-tests/posix/deduplication/BuiltinTypes.ql @@ -4,6 +4,6 @@ from BuiltinType t // FPIEEE16 related stuff is not there on macOS // FPIEEE80 is also missing on some CI runners where - not t.toString().matches("%FPIEEE16") and - not t.toString().matches("%FPIEEE80") + not t.toString().endsWith("FPIEEE16") and + not t.toString().endsWith("FPIEEE80") select t, t.getPrimaryQlClasses() diff --git a/swift/ql/lib/codeql/swift/StringFormat.qll b/swift/ql/lib/codeql/swift/StringFormat.qll index b257c0d03e16..ffbe60e61949 100644 --- a/swift/ql/lib/codeql/swift/StringFormat.qll +++ b/swift/ql/lib/codeql/swift/StringFormat.qll @@ -36,7 +36,7 @@ class StringInitWithFormat extends FormattingFunction, Method { StringInitWithFormat() { exists(string fName | this.hasQualifiedName(["String", "NSString", "NSMutableString"], fName) and - fName.matches("init(format:%") + fName.startsWith("init(format:") ) } diff --git a/swift/ql/lib/codeql/swift/elements/Comments.qll b/swift/ql/lib/codeql/swift/elements/Comments.qll index 47e668cdfbef..12eb44c51a05 100644 --- a/swift/ql/lib/codeql/swift/elements/Comments.qll +++ b/swift/ql/lib/codeql/swift/elements/Comments.qll @@ -2,14 +2,14 @@ import Comment final class SingleLineComment extends Comment { SingleLineComment() { - this.getText().matches("//%") and + this.getText().startsWith("//") and not this instanceof SingleLineDocComment } } final class MultiLineComment extends Comment { MultiLineComment() { - this.getText().matches("/*%") and + this.getText().startsWith("/*") and not this instanceof MultiLineDocComment } } @@ -19,9 +19,9 @@ abstract private class DocCommentImpl extends Comment { } final class DocComment = DocCommentImpl; final class SingleLineDocComment extends DocCommentImpl { - SingleLineDocComment() { this.getText().matches("///%") } + SingleLineDocComment() { this.getText().startsWith("///") } } final class MultiLineDocComment extends DocCommentImpl { - MultiLineDocComment() { this.getText().matches("/**%") } + MultiLineDocComment() { this.getText().startsWith("/**") } } diff --git a/swift/ql/lib/codeql/swift/elements/internal/FileImpl.qll b/swift/ql/lib/codeql/swift/elements/internal/FileImpl.qll index 4369cfb4515d..4a12c99e1cf4 100644 --- a/swift/ql/lib/codeql/swift/elements/internal/FileImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/internal/FileImpl.qll @@ -104,7 +104,7 @@ module Impl { absPath = pref and result = "" or absPath = pref.regexpReplaceAll("/$", "") + "/" + result and - not result.matches("/%") + not result.startsWith("/") ) } } diff --git a/swift/ql/lib/codeql/swift/frameworks/StandardLibrary/Array.qll b/swift/ql/lib/codeql/swift/frameworks/StandardLibrary/Array.qll index f1d0677aa72a..21fdc97d2283 100644 --- a/swift/ql/lib/codeql/swift/frameworks/StandardLibrary/Array.qll +++ b/swift/ql/lib/codeql/swift/frameworks/StandardLibrary/Array.qll @@ -9,7 +9,7 @@ private import codeql.swift.dataflow.ExternalFlow * An instance of the `Array` type. */ class ArrayType extends Type { - ArrayType() { this.getCanonicalType().getName().matches("Array<%") } + ArrayType() { this.getCanonicalType().getName().startsWith("Array<") } } /** diff --git a/swift/ql/lib/codeql/swift/frameworks/StandardLibrary/Dictionary.qll b/swift/ql/lib/codeql/swift/frameworks/StandardLibrary/Dictionary.qll index ca40beb19008..db6182d1c0bd 100644 --- a/swift/ql/lib/codeql/swift/frameworks/StandardLibrary/Dictionary.qll +++ b/swift/ql/lib/codeql/swift/frameworks/StandardLibrary/Dictionary.qll @@ -9,7 +9,7 @@ private import codeql.swift.dataflow.ExternalFlow * An instance of the `Dictionary` type. */ class CanonicalDictionaryType extends BoundGenericType { - CanonicalDictionaryType() { this.getName().matches("Dictionary<%") } + CanonicalDictionaryType() { this.getName().startsWith("Dictionary<") } } /** diff --git a/swift/ql/lib/codeql/swift/frameworks/StandardLibrary/PointerTypes.qll b/swift/ql/lib/codeql/swift/frameworks/StandardLibrary/PointerTypes.qll index d99ab102e436..63e9c2aa2a50 100644 --- a/swift/ql/lib/codeql/swift/frameworks/StandardLibrary/PointerTypes.qll +++ b/swift/ql/lib/codeql/swift/frameworks/StandardLibrary/PointerTypes.qll @@ -36,7 +36,7 @@ class OpaquePointerType extends NominalType { */ class AutoreleasingUnsafeMutablePointerType extends BoundGenericType { AutoreleasingUnsafeMutablePointerType() { - this.getName().matches("AutoreleasingUnsafeMutablePointer<%") + this.getName().startsWith("AutoreleasingUnsafeMutablePointer<") } } @@ -44,7 +44,7 @@ class AutoreleasingUnsafeMutablePointerType extends BoundGenericType { * A Swift `Unmanaged` object reference. */ class UnmanagedType extends BoundGenericType { - UnmanagedType() { this.getName().matches("Unmanaged<%") } + UnmanagedType() { this.getName().startsWith("Unmanaged<") } } /** @@ -58,7 +58,7 @@ class CVaListPointerType extends NominalType { * A Swift `ManagedBufferPointer`. */ class ManagedBufferPointerType extends BoundGenericType { - ManagedBufferPointerType() { this.getName().matches("ManagedBufferPointer<%") } + ManagedBufferPointerType() { this.getName().startsWith("ManagedBufferPointer<") } } /** diff --git a/swift/ql/lib/codeql/swift/regex/Regex.qll b/swift/ql/lib/codeql/swift/regex/Regex.qll index f2abba2e4f2b..7e2a6d2c48fa 100644 --- a/swift/ql/lib/codeql/swift/regex/Regex.qll +++ b/swift/ql/lib/codeql/swift/regex/Regex.qll @@ -505,5 +505,5 @@ private class NSStringCompareOptionsRegexEval extends RegexEval instanceof NSStr result = this.(NSStringCompareOptionsPotentialRegexEval).getAnOptionsInput() } - override predicate isUsedAsReplace() { this.getStaticTarget().getName().matches("replac%") } + override predicate isUsedAsReplace() { this.getStaticTarget().getName().startsWith("replac") } } diff --git a/swift/ql/lib/upgrades/ba43367c819291c264809f13f6c02ddf014dad0a/file_is_successfully_extracted.ql b/swift/ql/lib/upgrades/ba43367c819291c264809f13f6c02ddf014dad0a/file_is_successfully_extracted.ql index 0768851a0578..63b5a4a26425 100644 --- a/swift/ql/lib/upgrades/ba43367c819291c264809f13f6c02ddf014dad0a/file_is_successfully_extracted.ql +++ b/swift/ql/lib/upgrades/ba43367c819291c264809f13f6c02ddf014dad0a/file_is_successfully_extracted.ql @@ -6,7 +6,7 @@ from Element file, string filename where db_files(file) and files(file, filename) and - filename.matches("%.swift") and + filename.endsWith(".swift") and not exists(Element error, Element loc | diagnostics(error, _, 4) and locatable_locations(error, loc) and diff --git a/swift/ql/lib/utils/test/InlineFlowTest.qll b/swift/ql/lib/utils/test/InlineFlowTest.qll index f50930924ebf..644788435251 100644 --- a/swift/ql/lib/utils/test/InlineFlowTest.qll +++ b/swift/ql/lib/utils/test/InlineFlowTest.qll @@ -52,7 +52,7 @@ private predicate defaultSource(DataFlow::Node source) { } private predicate defaultSink(DataFlow::Node sink) { - exists(CallExpr ca | ca.getStaticTarget().(Function).getShortName().matches("sink%") | + exists(CallExpr ca | ca.getStaticTarget().(Function).getShortName().startsWith("sink") | sink.asExpr() = ca.getAnArgument().getExpr() ) } diff --git a/swift/ql/src/diagnostics/internal/UnresolvedAstNodes.ql b/swift/ql/src/diagnostics/internal/UnresolvedAstNodes.ql index 97c14eb4ca76..6736c2ea16af 100644 --- a/swift/ql/src/diagnostics/internal/UnresolvedAstNodes.ql +++ b/swift/ql/src/diagnostics/internal/UnresolvedAstNodes.ql @@ -8,4 +8,4 @@ import swift -select count(AstNode n | n.getAPrimaryQlClass().matches("Unresolved%") | n) +select count(AstNode n | n.getAPrimaryQlClass().startsWith("Unresolved") | n) diff --git a/swift/ql/test/TestUtils.qll b/swift/ql/test/TestUtils.qll index 3cc64e753b37..4ece749a795f 100644 --- a/swift/ql/test/TestUtils.qll +++ b/swift/ql/test/TestUtils.qll @@ -27,7 +27,7 @@ predicate toBeTested(Element e) { not m.isSystemModule() ) or - e.(Locatable).getLocation().getFile().getName().matches("%swift/ql/test%") + e.(Locatable).getLocation().getFile().getName().contains("swift/ql/test") or exists(Element tested | toBeTested(tested) and diff --git a/swift/ql/test/extractor-tests/declarations/all.ql b/swift/ql/test/extractor-tests/declarations/all.ql index 1580a8e60020..9810d42b251f 100644 --- a/swift/ql/test/extractor-tests/declarations/all.ql +++ b/swift/ql/test/extractor-tests/declarations/all.ql @@ -5,5 +5,5 @@ string describe(Decl decl) { } from Decl decl -where decl.getLocation().getFile().getName().matches("%swift/ql/test%") +where decl.getLocation().getFile().getName().contains("swift/ql/test") select decl, concat(describe(decl), ", ") diff --git a/swift/ql/test/extractor-tests/expressions/all.ql b/swift/ql/test/extractor-tests/expressions/all.ql index adad8af7a9f9..59d435b477b2 100644 --- a/swift/ql/test/extractor-tests/expressions/all.ql +++ b/swift/ql/test/extractor-tests/expressions/all.ql @@ -1,5 +1,5 @@ import swift from Expr expr -where expr.getLocation().getFile().getName().matches("%swift/ql/test%") +where expr.getLocation().getFile().getName().contains("swift/ql/test") select expr, expr.getPrimaryQlClasses() diff --git a/swift/ql/test/extractor-tests/expressions/semantics.ql b/swift/ql/test/extractor-tests/expressions/semantics.ql index 60da2dca2bae..c2775460f18c 100644 --- a/swift/ql/test/extractor-tests/expressions/semantics.ql +++ b/swift/ql/test/extractor-tests/expressions/semantics.ql @@ -2,7 +2,7 @@ import swift from Expr e, string semantics where - e.getLocation().getFile().getName().matches("%swift/ql/test%") and + e.getLocation().getFile().getName().contains("swift/ql/test") and ( exists(DeclRefExpr ref | ref = e | ref.hasDirectToImplementationSemantics() and semantics = "DirectToImplementation" diff --git a/swift/ql/test/extractor-tests/patterns/all.ql b/swift/ql/test/extractor-tests/patterns/all.ql index f8c8bc7dc446..01c9a4259f96 100644 --- a/swift/ql/test/extractor-tests/patterns/all.ql +++ b/swift/ql/test/extractor-tests/patterns/all.ql @@ -1,5 +1,5 @@ import codeql.swift.elements from Pattern p -where p.getLocation().getFile().getName().matches("%swift/ql/test%") +where p.getLocation().getFile().getName().contains("swift/ql/test") select p diff --git a/swift/ql/test/extractor-tests/statements/ConditionElements.ql b/swift/ql/test/extractor-tests/statements/ConditionElements.ql index 2415ea38663e..b597a0e8085c 100644 --- a/swift/ql/test/extractor-tests/statements/ConditionElements.ql +++ b/swift/ql/test/extractor-tests/statements/ConditionElements.ql @@ -2,7 +2,7 @@ import swift from ConditionElement e, AstNode underlying where - e.getLocation().getFile().getName().matches("%swift/ql/test%") and + e.getLocation().getFile().getName().contains("swift/ql/test") and ( underlying = e.getBoolean() or underlying = e.getPattern() or diff --git a/swift/ql/test/extractor-tests/statements/LabeledConditionalStmts.ql b/swift/ql/test/extractor-tests/statements/LabeledConditionalStmts.ql index 5ac73349402f..bd492e22834f 100644 --- a/swift/ql/test/extractor-tests/statements/LabeledConditionalStmts.ql +++ b/swift/ql/test/extractor-tests/statements/LabeledConditionalStmts.ql @@ -1,5 +1,5 @@ import swift from LabeledConditionalStmt s -where s.getLocation().getFile().getName().matches("%swift/ql/test%") +where s.getLocation().getFile().getName().contains("swift/ql/test") select s.getAPrimaryQlClass(), s.getCondition() diff --git a/swift/ql/test/extractor-tests/statements/LabeledStmts.ql b/swift/ql/test/extractor-tests/statements/LabeledStmts.ql index de9dc8251bd7..7b1250a3f591 100644 --- a/swift/ql/test/extractor-tests/statements/LabeledStmts.ql +++ b/swift/ql/test/extractor-tests/statements/LabeledStmts.ql @@ -1,5 +1,5 @@ import swift from LabeledStmt stmt -where stmt.getLocation().getFile().getName().matches("%swift/ql/test%") +where stmt.getLocation().getFile().getName().contains("swift/ql/test") select stmt diff --git a/swift/ql/test/extractor-tests/statements/Labels.ql b/swift/ql/test/extractor-tests/statements/Labels.ql index 0ca16a79294a..e85af6d0d2ad 100644 --- a/swift/ql/test/extractor-tests/statements/Labels.ql +++ b/swift/ql/test/extractor-tests/statements/Labels.ql @@ -1,5 +1,5 @@ import swift from LabeledStmt stmt -where stmt.getLocation().getFile().getName().matches("%swift/ql/test%") +where stmt.getLocation().getFile().getName().contains("swift/ql/test") select stmt, stmt.getLabel() diff --git a/swift/ql/test/extractor-tests/statements/YieldStmts.ql b/swift/ql/test/extractor-tests/statements/YieldStmts.ql index 44c484885f7b..67640b9fdf40 100644 --- a/swift/ql/test/extractor-tests/statements/YieldStmts.ql +++ b/swift/ql/test/extractor-tests/statements/YieldStmts.ql @@ -1,5 +1,5 @@ import swift from YieldStmt yield, int i -where yield.getLocation().getFile().getName().matches("%swift/ql/test%") +where yield.getLocation().getFile().getName().contains("swift/ql/test") select yield, i, yield.getResult(i) diff --git a/swift/ql/test/extractor-tests/types/ClassDecls.ql b/swift/ql/test/extractor-tests/types/ClassDecls.ql index 4f389650069d..3da2123cdcc8 100644 --- a/swift/ql/test/extractor-tests/types/ClassDecls.ql +++ b/swift/ql/test/extractor-tests/types/ClassDecls.ql @@ -2,7 +2,7 @@ import codeql.swift.elements from Decl d, ClassType s, string parent where - d.getLocation().getFile().getName().matches("%swift/ql/test%") and + d.getLocation().getFile().getName().contains("swift/ql/test") and d = s.getDeclaration() and ( parent = s.getParent().toString() diff --git a/swift/ql/test/extractor-tests/types/StructDecls.ql b/swift/ql/test/extractor-tests/types/StructDecls.ql index 4e255584b7f1..de56f37662de 100644 --- a/swift/ql/test/extractor-tests/types/StructDecls.ql +++ b/swift/ql/test/extractor-tests/types/StructDecls.ql @@ -2,7 +2,7 @@ import codeql.swift.elements from Decl d, StructType s, string parent where - d.getLocation().getFile().getName().matches("%swift/ql/test%") and + d.getLocation().getFile().getName().contains("swift/ql/test") and d = s.getDeclaration() and ( parent = s.getParent().toString() diff --git a/swift/ql/test/extractor-tests/types/ThrowingAndAsync.ql b/swift/ql/test/extractor-tests/types/ThrowingAndAsync.ql index cfb94bd7d37c..77d53d26821e 100644 --- a/swift/ql/test/extractor-tests/types/ThrowingAndAsync.ql +++ b/swift/ql/test/extractor-tests/types/ThrowingAndAsync.ql @@ -3,7 +3,7 @@ import codeql.swift.elements from Function f, AnyFunctionType t, string s where f.getInterfaceType() = t and - f.getLocation().getFile().getName().matches("%swift/ql/test%") and + f.getLocation().getFile().getName().contains("swift/ql/test") and ( t.isAsync() and s = "async" or diff --git a/swift/ql/test/extractor-tests/types/Types.ql b/swift/ql/test/extractor-tests/types/Types.ql index 96f8f21d557f..c42a16924b23 100644 --- a/swift/ql/test/extractor-tests/types/Types.ql +++ b/swift/ql/test/extractor-tests/types/Types.ql @@ -2,6 +2,6 @@ import codeql.swift.elements from Expr e, Type t where - e.getLocation().getFile().getName().matches("%swift/ql/test%") and + e.getLocation().getFile().getName().contains("swift/ql/test") and t = e.getType() select e, t diff --git a/swift/ql/test/library-tests/controlflow/graph/Cfg.ql b/swift/ql/test/library-tests/controlflow/graph/Cfg.ql index 179e07db064c..623ca8a3823a 100644 --- a/swift/ql/test/library-tests/controlflow/graph/Cfg.ql +++ b/swift/ql/test/library-tests/controlflow/graph/Cfg.ql @@ -2,7 +2,7 @@ import swift import codeql.swift.controlflow.ControlFlowGraph class MyRelevantNode extends ControlFlowNode { - MyRelevantNode() { this.getScope().getLocation().getFile().getName().matches("%swift/ql/test%") } + MyRelevantNode() { this.getScope().getLocation().getFile().getName().contains("swift/ql/test") } } import codeql.swift.controlflow.internal.ControlFlowGraphImpl::TestOutput diff --git a/swift/ql/test/library-tests/dataflow/dataflow/FlowConfig.qll b/swift/ql/test/library-tests/dataflow/dataflow/FlowConfig.qll index abbc0a4972d3..f2e124b257ba 100644 --- a/swift/ql/test/library-tests/dataflow/dataflow/FlowConfig.qll +++ b/swift/ql/test/library-tests/dataflow/dataflow/FlowConfig.qll @@ -9,7 +9,7 @@ import codeql.swift.frameworks.Frameworks module TestConfiguration implements DataFlow::ConfigSig { predicate isSource(DataFlow::Node src) { - src.asExpr().(CallExpr).getStaticTarget().getName().matches("source%") + src.asExpr().(CallExpr).getStaticTarget().getName().startsWith("source") } predicate isSink(DataFlow::Node sink) { diff --git a/swift/ql/test/library-tests/dataflow/flowsources/FlowSourcesInline.ql b/swift/ql/test/library-tests/dataflow/flowsources/FlowSourcesInline.ql index 193a5a748bb0..978d9108da12 100644 --- a/swift/ql/test/library-tests/dataflow/flowsources/FlowSourcesInline.ql +++ b/swift/ql/test/library-tests/dataflow/flowsources/FlowSourcesInline.ql @@ -9,7 +9,7 @@ module TestConfiguration implements DataFlow::ConfigSig { predicate isSink(DataFlow::Node sink) { exists(CallExpr sinkCall | - sinkCall.getStaticTarget().getName().matches("sink%") and + sinkCall.getStaticTarget().getName().startsWith("sink") and sinkCall.getAnArgument().getExpr() = sink.asExpr() ) } diff --git a/swift/ql/test/library-tests/dataflow/taint/core/Taint.qll b/swift/ql/test/library-tests/dataflow/taint/core/Taint.qll index f2559b122cd0..9fac9d7cff56 100644 --- a/swift/ql/test/library-tests/dataflow/taint/core/Taint.qll +++ b/swift/ql/test/library-tests/dataflow/taint/core/Taint.qll @@ -4,12 +4,12 @@ import codeql.swift.dataflow.DataFlow module TestConfiguration implements DataFlow::ConfigSig { predicate isSource(DataFlow::Node src) { - src.asExpr().(CallExpr).getStaticTarget().getName().matches("source%") + src.asExpr().(CallExpr).getStaticTarget().getName().startsWith("source") } predicate isSink(DataFlow::Node sink) { exists(CallExpr sinkCall | - sinkCall.getStaticTarget().getName().matches("sink%") and + sinkCall.getStaticTarget().getName().startsWith("sink") and sinkCall.getAnArgument().getExpr() = sink.asExpr() ) } diff --git a/swift/ql/test/library-tests/elements/decl/function/function.ql b/swift/ql/test/library-tests/elements/decl/function/function.ql index fbd47a20f4bc..ed320f9c82ad 100644 --- a/swift/ql/test/library-tests/elements/decl/function/function.ql +++ b/swift/ql/test/library-tests/elements/decl/function/function.ql @@ -28,5 +28,5 @@ string describe(Function f) { from Function f where exists(f.getFile().getRelativePath()) and - not f.getName().matches("%init%") + not f.getName().contains("init") select f, concat(describe(f), ", ") diff --git a/swift/ql/test/library-tests/regex/regex.ql b/swift/ql/test/library-tests/regex/regex.ql index c1be7a605729..3c411442c908 100644 --- a/swift/ql/test/library-tests/regex/regex.ql +++ b/swift/ql/test/library-tests/regex/regex.ql @@ -6,7 +6,7 @@ import codeql.regex.nfa.ExponentialBackTracking::Make import utils.test.InlineExpectationsTest bindingset[s] -string quote(string s) { if s.matches("% %") then result = "\"" + s + "\"" else result = s } +string quote(string s) { if s.contains(" ") then result = "\"" + s + "\"" else result = s } module RegexTest implements TestSig { string getARelevantTag() { diff --git a/unified/ql/lib/codeql/unified/internal/dev/debugDataFlowGraph.ql b/unified/ql/lib/codeql/unified/internal/dev/debugDataFlowGraph.ql index 7f79b0d151e7..061fca50a8f5 100644 --- a/unified/ql/lib/codeql/unified/internal/dev/debugDataFlowGraph.ql +++ b/unified/ql/lib/codeql/unified/internal/dev/debugDataFlowGraph.ql @@ -13,7 +13,7 @@ private import codeql.unified.internal.dataflow.DataFlowGraph */ predicate relevantNode(AstNode node) { // Match an ancestor node by location so its whole subtree is shown. - node.getParent*().getLocation().toString().matches("%test.swift@13:%") + node.getParent*().getLocation().toString().contains("test.swift@13:") } import DebugGraph diff --git a/unified/ql/lib/codeql/unified/internal/dev/debugLocalNameBindingGraph.ql b/unified/ql/lib/codeql/unified/internal/dev/debugLocalNameBindingGraph.ql index 4c0db3a049df..34fcbb010531 100644 --- a/unified/ql/lib/codeql/unified/internal/dev/debugLocalNameBindingGraph.ql +++ b/unified/ql/lib/codeql/unified/internal/dev/debugLocalNameBindingGraph.ql @@ -13,7 +13,7 @@ private import codeql.unified.internal.NameBinding */ predicate relevantNode(AstNode node) { // Match an ancestor node by location so its whole subtree is shown. - node.getParent*().getLocation().toString().matches("%test.swift@227:%") + node.getParent*().getLocation().toString().contains("test.swift@227:") } import LocalNameBindingOutput::DebugScopeGraph diff --git a/unified/ql/lib/codeql/unified/internal/dev/debugStaticNameBindingGraph.ql b/unified/ql/lib/codeql/unified/internal/dev/debugStaticNameBindingGraph.ql index e8c97ce41852..240f8e06240b 100644 --- a/unified/ql/lib/codeql/unified/internal/dev/debugStaticNameBindingGraph.ql +++ b/unified/ql/lib/codeql/unified/internal/dev/debugStaticNameBindingGraph.ql @@ -13,7 +13,7 @@ private import codeql.unified.internal.NameBinding */ predicate relevantNode(AstNode node) { // Match an ancestor node by location so its whole subtree is shown. - node.getParent*().getLocation().toString().matches("%test.swift@13:%") + node.getParent*().getLocation().toString().contains("test.swift@13:") } import DebugGraph diff --git a/unified/ql/lib/codeql/unified/internal/mad/LegacyMaD.qll b/unified/ql/lib/codeql/unified/internal/mad/LegacyMaD.qll index f20b4e0fdbcf..d1e047198f75 100644 --- a/unified/ql/lib/codeql/unified/internal/mad/LegacyMaD.qll +++ b/unified/ql/lib/codeql/unified/internal/mad/LegacyMaD.qll @@ -124,7 +124,7 @@ private predicate callableSelector( /** Holds if `name` from a model refers to a property, such as `count` in `String.count`. */ private predicate isRawPropertyName(string name) { modelContainsMethodName(name) and - not name.matches("%(%") + not name.contains("(") } /** diff --git a/unified/ql/lib/codeql/unified/internal/typeinference/TypeInference.qll b/unified/ql/lib/codeql/unified/internal/typeinference/TypeInference.qll index bcfa0f38c1bf..d114c0f61182 100644 --- a/unified/ql/lib/codeql/unified/internal/typeinference/TypeInference.qll +++ b/unified/ql/lib/codeql/unified/internal/typeinference/TypeInference.qll @@ -977,7 +977,7 @@ private module Debug { AstNode getRelevantNode() { exists(string filepath, int startline, int startcolumn, int endline, int endcolumn | result.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) and - filepath.matches("%/test.swift") and + filepath.endsWith("/test.swift") and startline = 1 ) } diff --git a/unified/ql/src/queries/unusedentities/UnusedVariable.ql b/unified/ql/src/queries/unusedentities/UnusedVariable.ql index d5747df44863..0d9e8c986b63 100644 --- a/unified/ql/src/queries/unusedentities/UnusedVariable.ql +++ b/unified/ql/src/queries/unusedentities/UnusedVariable.ql @@ -12,7 +12,7 @@ private import unified private predicate isUnusedLocal(LocalName local) { local.getABinding().fromSource() and // ignore unused implicit locals, and ignore locals in built-ins not ignoreDeclaration(local.getABinding().getDeclaration()) and // ignore fields, method, etc - not local.getName().regexpMatch("_.*") and + not local.getName().startsWith("_") and not exists(LocalNameAccess access | access = local.getAnAccess() and not access instanceof NameBinding From 0bda7625bef89a0765162dbd955786bd175be1fa Mon Sep 17 00:00:00 2001 From: aschackmull <28296824+aschackmull@users.noreply.github.com> Date: Fri, 20 Nov 2026 09:53:11 +0000 Subject: [PATCH 2/3] QL: Format string predicate changes Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> --- go/ql/lib/semmle/go/frameworks/stdlib/Regexp.qll | 4 +++- go/ql/lib/semmle/go/security/HardcodedCredentials.qll | 4 +++- java/ql/src/Likely Bugs/Concurrency/BusyWait.ql | 4 +++- .../ql/lib/semmle/javascript/frameworks/ClientRequests.qll | 3 +-- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/go/ql/lib/semmle/go/frameworks/stdlib/Regexp.qll b/go/ql/lib/semmle/go/frameworks/stdlib/Regexp.qll index 71b0537f5394..f13f35810e54 100644 --- a/go/ql/lib/semmle/go/frameworks/stdlib/Regexp.qll +++ b/go/ql/lib/semmle/go/frameworks/stdlib/Regexp.qll @@ -91,7 +91,9 @@ module Regexp { private class ReplaceFunction extends RegexpReplaceFunction::Range, Method { ReplaceFunction() { - exists(string fn | fn.startsWith("ReplaceAll") | this.hasQualifiedName("regexp", "Regexp", fn)) + exists(string fn | fn.startsWith("ReplaceAll") | + this.hasQualifiedName("regexp", "Regexp", fn) + ) } override FunctionInput getRegexpArg() { result.isReceiver() } diff --git a/go/ql/lib/semmle/go/security/HardcodedCredentials.qll b/go/ql/lib/semmle/go/security/HardcodedCredentials.qll index 12c30f6e683a..e374bb001f0d 100644 --- a/go/ql/lib/semmle/go/security/HardcodedCredentials.qll +++ b/go/ql/lib/semmle/go/security/HardcodedCredentials.qll @@ -44,7 +44,9 @@ module HardcodedCredentials { /** A use of a credential. */ private class ExternalCredentialsSink extends Sink { - ExternalCredentialsSink() { exists(string s | s.startsWith("credentials-") | sinkNode(this, s)) } + ExternalCredentialsSink() { + exists(string s | s.startsWith("credentials-") | sinkNode(this, s)) + } } /** A use of a credential. */ diff --git a/java/ql/src/Likely Bugs/Concurrency/BusyWait.ql b/java/ql/src/Likely Bugs/Concurrency/BusyWait.ql index 31e0af006291..a1f94410cb25 100644 --- a/java/ql/src/Likely Bugs/Concurrency/BusyWait.ql +++ b/java/ql/src/Likely Bugs/Concurrency/BusyWait.ql @@ -35,7 +35,9 @@ class WaitMethod extends Method { } class ConcurrentMethod extends Method { - ConcurrentMethod() { this.getDeclaringType().getQualifiedName().startsWith("java.util.concurrent") } + ConcurrentMethod() { + this.getDeclaringType().getQualifiedName().startsWith("java.util.concurrent") + } } class CommunicationMethod extends Method { diff --git a/javascript/ql/lib/semmle/javascript/frameworks/ClientRequests.qll b/javascript/ql/lib/semmle/javascript/frameworks/ClientRequests.qll index 909718f6cf64..07015e328038 100644 --- a/javascript/ql/lib/semmle/javascript/frameworks/ClientRequests.qll +++ b/javascript/ql/lib/semmle/javascript/frameworks/ClientRequests.qll @@ -732,8 +732,7 @@ module ClientRequest { /** Gets an event listener registered on this XHR object. */ DataFlow::FunctionNode getAnEventListener() { - exists(string propertyName | - propertyName.startsWith("on") | + exists(string propertyName | propertyName.startsWith("on") | result = this.getAPropertyWrite(propertyName).getRhs().getAFunctionValue() ) or From 55eeeb4c25aee215bcf5118ca9481e87792a758b Mon Sep 17 00:00:00 2001 From: aschackmull <28296824+aschackmull@users.noreply.github.com> Date: Fri, 20 Nov 2026 11:02:41 +0000 Subject: [PATCH 3/3] QL: Update VarUnusedInDisjunct expected location Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> --- .../VarUnusedInDisjunct/VarUnusedInDisjunct.expected | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ql/ql/test/queries/performance/VarUnusedInDisjunct/VarUnusedInDisjunct.expected b/ql/ql/test/queries/performance/VarUnusedInDisjunct/VarUnusedInDisjunct.expected index 6304bcb7a524..e76051189cb5 100644 --- a/ql/ql/test/queries/performance/VarUnusedInDisjunct/VarUnusedInDisjunct.expected +++ b/ql/ql/test/queries/performance/VarUnusedInDisjunct/VarUnusedInDisjunct.expected @@ -2,7 +2,7 @@ | Test.qll:21:5:23:37 | Disjunction | The $@ is only used in one side of disjunct. | Test.qll:20:10:20:16 | big | variable big | | Test.qll:28:3:30:33 | Disjunction | The $@ is only used in one side of disjunct. | Test.qll:27:12:27:16 | t | variable t | | Test.qll:49:3:53:26 | Disjunction | The $@ is only used in one side of disjunct. | Test.qll:48:30:48:39 | toType | variable toType | -| Test.qll:74:8:74:77 | Disjunction | The $@ is only used in one side of disjunct. | Test.qll:70:9:70:15 | bad | variable bad | +| Test.qll:74:8:74:74 | Disjunction | The $@ is only used in one side of disjunct. | Test.qll:70:9:70:15 | bad | variable bad | | Test.qll:115:26:115:80 | IfFormula | The $@ is only used in one side of disjunct. | Test.qll:115:16:115:21 | bb | variable bb | | Test.qll:127:5:129:9 | Disjunction | The $@ is only used in one side of disjunct. | Test.qll:125:16:125:20 | a | variable a | | Test.qll:132:5:134:9 | Disjunction | The $@ is only used in one side of disjunct. | Test.qll:125:16:125:20 | a | variable a |