From 8eeb019b5caa090304cffa7c3e662e8cf8786928 Mon Sep 17 00:00:00 2001 From: Slavomir Date: Sat, 12 Sep 2020 12:26:13 +0200 Subject: [PATCH] Move existing `OS` (all caps name) module classes to stdlib.Os module (notice the camelcase name) --- ql/src/semmle/go/frameworks/Stdlib.qll | 81 ----------------------- ql/src/semmle/go/frameworks/stdlib/Os.qll | 60 +++++++++++++++++ 2 files changed, 60 insertions(+), 81 deletions(-) diff --git a/ql/src/semmle/go/frameworks/Stdlib.qll b/ql/src/semmle/go/frameworks/Stdlib.qll index fd0c6d132af..f9dfbaad4ea 100644 --- a/ql/src/semmle/go/frameworks/Stdlib.qll +++ b/ql/src/semmle/go/frameworks/Stdlib.qll @@ -395,87 +395,6 @@ module IoUtil { } } -/** Provides models of commonly used functions in the `os` package. */ -module OS { - /** - * A call to a function in `os` that accesses the file system. - */ - private class OsFileSystemAccess extends FileSystemAccess::Range, DataFlow::CallNode { - int pathidx; - - OsFileSystemAccess() { - exists(string fn | getTarget().hasQualifiedName("os", fn) | - fn = "Chdir" and pathidx = 0 - or - fn = "Chmod" and pathidx = 0 - or - fn = "Chown" and pathidx = 0 - or - fn = "Chtimes" and pathidx = 0 - or - fn = "Create" and pathidx = 0 - or - fn = "Lchown" and pathidx = 0 - or - fn = "Link" and pathidx in [0 .. 1] - or - fn = "Lstat" and pathidx = 0 - or - fn = "Mkdir" and pathidx = 0 - or - fn = "MkdirAll" and pathidx = 0 - or - fn = "NewFile" and pathidx = 1 - or - fn = "Open" and pathidx = 0 - or - fn = "OpenFile" and pathidx = 0 - or - fn = "Readlink" and pathidx = 0 - or - fn = "Remove" and pathidx = 0 - or - fn = "RemoveAll" and pathidx = 0 - or - fn = "Rename" and pathidx in [0 .. 1] - or - fn = "Stat" and pathidx = 0 - or - fn = "Symlink" and pathidx in [0 .. 1] - or - fn = "Truncate" and pathidx = 0 - ) - } - - override DataFlow::Node getAPathArgument() { result = getArgument(pathidx) } - } - - /** The `Expand` function. */ - class Expand extends TaintTracking::FunctionModel { - Expand() { hasQualifiedName("os", "Expand") } - - override predicate hasTaintFlow(FunctionInput inp, FunctionOutput outp) { - inp.isParameter(0) and outp.isResult() - } - } - - /** The `ExpandEnv` function. */ - class ExpandEnv extends TaintTracking::FunctionModel { - ExpandEnv() { hasQualifiedName("os", "ExpandEnv") } - - override predicate hasTaintFlow(FunctionInput inp, FunctionOutput outp) { - inp.isParameter(0) and outp.isResult() - } - } - - /** The `os.Exit` function, which ends the process. */ - private class Exit extends Function { - Exit() { hasQualifiedName("os", "Exit") } - - override predicate mayReturnNormally() { none() } - } -} - /** Provides a class for modeling functions which convert strings into integers. */ module IntegerParser { /** diff --git a/ql/src/semmle/go/frameworks/stdlib/Os.qll b/ql/src/semmle/go/frameworks/stdlib/Os.qll index 4d9da3ad54a..e5d8b91c148 100644 --- a/ql/src/semmle/go/frameworks/stdlib/Os.qll +++ b/ql/src/semmle/go/frameworks/stdlib/Os.qll @@ -6,6 +6,66 @@ import go /** Provides models of commonly used functions in the `os` package. */ module Os { + /** + * A call to a function in `os` that accesses the file system. + */ + private class OsFileSystemAccess extends FileSystemAccess::Range, DataFlow::CallNode { + int pathidx; + + OsFileSystemAccess() { + exists(string fn | getTarget().hasQualifiedName("os", fn) | + fn = "Chdir" and pathidx = 0 + or + fn = "Chmod" and pathidx = 0 + or + fn = "Chown" and pathidx = 0 + or + fn = "Chtimes" and pathidx = 0 + or + fn = "Create" and pathidx = 0 + or + fn = "Lchown" and pathidx = 0 + or + fn = "Link" and pathidx in [0 .. 1] + or + fn = "Lstat" and pathidx = 0 + or + fn = "Mkdir" and pathidx = 0 + or + fn = "MkdirAll" and pathidx = 0 + or + fn = "NewFile" and pathidx = 1 + or + fn = "Open" and pathidx = 0 + or + fn = "OpenFile" and pathidx = 0 + or + fn = "Readlink" and pathidx = 0 + or + fn = "Remove" and pathidx = 0 + or + fn = "RemoveAll" and pathidx = 0 + or + fn = "Rename" and pathidx in [0 .. 1] + or + fn = "Stat" and pathidx = 0 + or + fn = "Symlink" and pathidx in [0 .. 1] + or + fn = "Truncate" and pathidx = 0 + ) + } + + override DataFlow::Node getAPathArgument() { result = getArgument(pathidx) } + } + + /** The `os.Exit` function, which ends the process. */ + private class Exit extends Function { + Exit() { hasQualifiedName("os", "Exit") } + + override predicate mayReturnNormally() { none() } + } + private class FunctionModels extends TaintTracking::FunctionModel { FunctionInput inp; FunctionOutput outp;