diff options
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); |