summaryrefslogtreecommitdiff
path: root/init/builtins.cpp
diff options
context:
space:
mode:
authorTom Cherry <tomcherry@google.com>2017-03-31 15:47:33 -0700
committerTom Cherry <tomcherry@google.com>2017-04-03 16:41:22 -0700
commit53089aa25ca9707e22e45e862f794bfc958d302a (patch)
treebb78a67882aa672a81ee503088df958e22a518b5 /init/builtins.cpp
parent8bc5c8521ad67f63116aa11318a9bed3446499f8 (diff)
init: Use std::string for write_file()
The content parameter of write_file() previously took a char* that was then converted to a std::string in WriteStringToFd(). One unfortunate effect of this, is that it is impossible to write data that contains '\0' within it, as the new string will only contain characters up until the '\0'. This changes write_file() to take an std::string, such that std::string::size() is used to determine the length of the string, allowing it to contain null characters. Also change the path parameter of read_file() and write_file() for consistency. Lastly, add a test for handling strings with '\0' in them. Bug: 36726045 Test: Boot bullhead, run unit tests Change-Id: Idad60e4228ee2de741ab3ab6a4917065b5e63cd8
Diffstat (limited to 'init/builtins.cpp')
-rw-r--r--init/builtins.cpp8
1 files changed, 3 insertions, 5 deletions
diff --git a/init/builtins.cpp b/init/builtins.cpp
index dc2bda644..4ad36e078 100644
--- a/init/builtins.cpp
+++ b/init/builtins.cpp
@@ -155,7 +155,7 @@ static int do_class_restart(const std::vector<std::string>& args) {
}
static int do_domainname(const std::vector<std::string>& args) {
- return write_file("/proc/sys/kernel/domainname", args[1].c_str()) ? 0 : 1;
+ return write_file("/proc/sys/kernel/domainname", args[1]) ? 0 : 1;
}
static int do_enable(const std::vector<std::string>& args) {
@@ -179,7 +179,7 @@ static int do_export(const std::vector<std::string>& args) {
}
static int do_hostname(const std::vector<std::string>& args) {
- return write_file("/proc/sys/kernel/hostname", args[1].c_str()) ? 0 : 1;
+ return write_file("/proc/sys/kernel/hostname", args[1]) ? 0 : 1;
}
static int do_ifup(const std::vector<std::string>& args) {
@@ -696,9 +696,7 @@ static int do_verity_update_state(const std::vector<std::string>& args) {
}
static int do_write(const std::vector<std::string>& args) {
- const char* path = args[1].c_str();
- const char* value = args[2].c_str();
- return write_file(path, value) ? 0 : 1;
+ return write_file(args[1], args[2]) ? 0 : 1;
}
static int do_copy(const std::vector<std::string>& args) {