From e6a57b22a21e31e6368fce63236e8f19d273c756 Mon Sep 17 00:00:00 2001 From: Owen Mansel-Chan Date: Sun, 31 Oct 2021 13:57:59 +0000 Subject: [PATCH] Add isVariadic() on FuncDecl and Function --- ql/lib/semmle/go/Decls.qll | 2 ++ ql/lib/semmle/go/Scopes.qll | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/ql/lib/semmle/go/Decls.qll b/ql/lib/semmle/go/Decls.qll index 8cfb78ccc9c..515e3f7b9ef 100644 --- a/ql/lib/semmle/go/Decls.qll +++ b/ql/lib/semmle/go/Decls.qll @@ -137,6 +137,8 @@ class FuncDef extends @funcdef, StmtParent, ExprParent { */ DataFlow::CallNode getACall() { result.getACallee() = this } + predicate isVariadic() { getType().isVariadic() } + override string getAPrimaryQlClass() { result = "FuncDef" } } diff --git a/ql/lib/semmle/go/Scopes.qll b/ql/lib/semmle/go/Scopes.qll index 159f0b6bc5d..d10f5d80919 100644 --- a/ql/lib/semmle/go/Scopes.qll +++ b/ql/lib/semmle/go/Scopes.qll @@ -377,6 +377,12 @@ class Function extends ValueEntity, @functionobject { /** Gets the declaration of this function, if any. */ FuncDecl getFuncDecl() { none() } + predicate isVariadic() { + this.(BuiltinFunction).getName() = ["append", "make", "print", "println"] + or + this.(DeclaredFunction).getFuncDecl().isVariadic() + } + /** Holds if this function has no observable side effects. */ predicate mayHaveSideEffects() { none() }