From 3b942fed99d5b54244e1874d18c30457280382ae Mon Sep 17 00:00:00 2001 From: dsmith Date: Thu, 29 Mar 2007 16:17:12 +0000 Subject: 2007-03-29 David Smith PR 4281 * main.cxx (main): Validates '-m NAME' option. Chops off '.ko' if present. Makes sure name isn't empty. Makes sure name is only composed of characters [_a-zA-Z0-9]. --- main.cxx | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'main.cxx') diff --git a/main.cxx b/main.cxx index e2226e48..b15c9185 100644 --- a/main.cxx +++ b/main.cxx @@ -320,6 +320,38 @@ main (int argc, char * const argv []) case 'm': s.module_name = string (optarg); + { + string::size_type len = s.module_name.length(); + + // If the module name ends with '.ko', chop it off since + // modutils doesn't like modules named 'foo.ko.ko'. + if (len > 3 && s.module_name.substr(len - 3, 3) == ".ko") + { + s.module_name.erase(len - 3); + len -= 3; + cerr << "Truncating module name to '" << s.module_name + << "'" << endl; + } + + // Make sure an empty module name wasn't specified (-m "") + if (len == 0) + { + cerr << "Module name cannot be empty." << endl; + usage (s, 1); + } + + // Make sure the module name is only composed of the + // following chars: [_a-zA-Z0-9] + const string identchars("_" "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789"); + if (s.module_name.find_first_not_of(identchars) != string::npos) + { + cerr << "Invalid module name (must only be composed of" + " characters [_a-zA-Z0-9])." << endl; + usage (s, 1); + } + } + cerr << "Warning: using '-m' disables cache support." << endl; s.use_cache = false; break; -- cgit