diff options
author | Ian Lance Taylor <iant@google.com> | 2012-09-17 05:15:36 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2012-09-17 05:15:36 +0000 |
commit | 5dbeb128d9d33ef23e15b65dad1c7cc28793692d (patch) | |
tree | 5324a239d8658af99c9f07bfb4bc67b31c74c90b /gcc/go/gofrontend/gogo.cc | |
parent | f0e1e86d226c40d8f13f1abd1f8fac7017075000 (diff) | |
download | gcc-5dbeb128d9d33ef23e15b65dad1c7cc28793692d.zip gcc-5dbeb128d9d33ef23e15b65dad1c7cc28793692d.tar.gz gcc-5dbeb128d9d33ef23e15b65dad1c7cc28793692d.tar.bz2 |
compile: Detect invalid and likely-bad import statements.
* Make-lang.in (go/gogo.o): Depend on filenames.h.
From-SVN: r191372
Diffstat (limited to 'gcc/go/gofrontend/gogo.cc')
-rw-r--r-- | gcc/go/gofrontend/gogo.cc | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/gcc/go/gofrontend/gogo.cc b/gcc/go/gofrontend/gogo.cc index 6e9b8c1..a434c4d 100644 --- a/gcc/go/gofrontend/gogo.cc +++ b/gcc/go/gofrontend/gogo.cc @@ -6,6 +6,8 @@ #include "go-system.h" +#include "filenames.h" + #include "go-c.h" #include "go-dump.h" #include "lex.h" @@ -385,6 +387,57 @@ Gogo::import_package(const std::string& filename, bool is_local_name_exported, Location location) { + if (filename.empty()) + { + error_at(location, "import path is empty"); + return; + } + + const char *pf = filename.data(); + const char *pend = pf + filename.length(); + while (pf < pend) + { + unsigned int c; + int adv = Lex::fetch_char(pf, &c); + if (adv == 0) + { + error_at(location, "import path contains invalid UTF-8 sequence"); + return; + } + if (c == '\0') + { + error_at(location, "import path contains NUL"); + return; + } + if (c < 0x20 || c == 0x7f) + { + error_at(location, "import path contains control character"); + return; + } + if (c == '\\') + { + error_at(location, "import path contains backslash; use slash"); + return; + } + if (Lex::is_unicode_space(c)) + { + error_at(location, "import path contains space character"); + return; + } + if (c < 0x7f && strchr("!\"#$%&'()*,:;<=>?[]^`{|}", c) != NULL) + { + error_at(location, "import path contains invalid character '%c'", c); + return; + } + pf += adv; + } + + if (IS_ABSOLUTE_PATH(filename.c_str())) + { + error_at(location, "import path cannot be absolute path"); + return; + } + if (filename == "unsafe") { this->import_unsafe(local_name, is_local_name_exported, location); |