system/corennnnn
修订版 | 7697f857cd5f7dcadae78aec84a228c3660124bc (tree) |
---|---|
时间 | 2016-09-16 22:16:38 |
作者 | Christopher R. Palmer <crpalmer@gmai...> |
Commiter | Christopher R. Palmer |
init: Don't crash the system due to an invalid mkdir argument
Prior to this change, if someone write
in one of their init.rc files, this causes init to get a exception
which causes init to exit with no error message to allow you to track
this down which then causes your kernel to panic.
Let's make this a little more user friendly by simply reporting
an error instead of silently crashing the whole damn system.
Change-Id: I2f8c50391e78a9992d33754cf1f1e34e9fcee047
@@ -303,7 +303,12 @@ static int do_mkdir(const std::vector<std::string>& args) { | ||
303 | 303 | /* mkdir <path> [mode] [owner] [group] */ |
304 | 304 | |
305 | 305 | if (args.size() >= 3) { |
306 | - mode = std::stoul(args[2], 0, 8); | |
306 | + unsigned long mode_ul; | |
307 | + if (sscanf(args[2].c_str(), "%lo", &mode_ul) != 1) { | |
308 | + ERROR("mkdir: invalid mode %s\n", args[2].c_str()); | |
309 | + return -EINVAL; | |
310 | + } | |
311 | + mode = (mode_t) mode_ul; | |
307 | 312 | } |
308 | 313 | |
309 | 314 | ret = make_dir(args[1].c_str(), mode); |