summaryrefslogtreecommitdiffstats
path: root/init
diff options
context:
space:
mode:
authorTom Cherry <tomcherry@google.com>2015-05-12 13:54:41 -0700
committerElliott Hughes <enh@google.com>2015-05-12 19:42:38 -0700
commitcce7e93b287835ffe9cdc3dad3fac52972d84560 (patch)
tree85f66bc9b1e39bdf7988e1a841bd6716cab20030 /init
parent30cc3d72498326c77b75cdf02992211d31396b33 (diff)
downloadsystem_core-cce7e93b287835ffe9cdc3dad3fac52972d84560.zip
system_core-cce7e93b287835ffe9cdc3dad3fac52972d84560.tar.gz
system_core-cce7e93b287835ffe9cdc3dad3fac52972d84560.tar.bz2
Fix insmod module size
read_file() used to append a new line character to the end of the buffer it returns, because parse_config() isn't able to cope with input that's not '\n'-terminated. Fix read_file() to be less insane, and push the workarounds into the parse_config() callers. Longer term we should rewrite parse_config(). Bug: http://b/21079470 Change-Id: Ie9d9a7adcd33b66621726aef20c4b8cc51c08be7 (cherry picked from commit eaa3b4ec6f79fe06163b8dd6fe8ba2581d3b9c0b)
Diffstat (limited to 'init')
-rw-r--r--init/builtins.cpp7
-rw-r--r--init/init_parser.cpp7
-rw-r--r--init/property_service.cpp1
-rw-r--r--init/ueventd_parser.cpp7
-rw-r--r--init/util.cpp4
5 files changed, 11 insertions, 15 deletions
diff --git a/init/builtins.cpp b/init/builtins.cpp
index f59d1fe..735033e 100644
--- a/init/builtins.cpp
+++ b/init/builtins.cpp
@@ -57,16 +57,13 @@ extern "C" int init_module(void *, unsigned long, const char *);
static int insmod(const char *filename, char *options)
{
- std::string module;
char filename_val[PROP_VALUE_MAX];
- int ret;
-
- ret = expand_props(filename_val, filename, sizeof(filename_val));
- if (ret) {
+ if (expand_props(filename_val, filename, sizeof(filename_val)) == -1) {
ERROR("insmod: cannot expand '%s'\n", filename);
return -EINVAL;
}
+ std::string module;
if (!read_file(filename_val, &module)) {
return -1;
}
diff --git a/init/init_parser.cpp b/init/init_parser.cpp
index b76b04e..d36995d 100644
--- a/init/init_parser.cpp
+++ b/init/init_parser.cpp
@@ -382,13 +382,13 @@ static void parse_new_section(struct parse_state *state, int kw,
static void parse_config(const char *fn, const std::string& data)
{
- struct parse_state state;
struct listnode import_list;
struct listnode *node;
char *args[INIT_PARSER_MAXARGS];
- int nargs;
- nargs = 0;
+ int nargs = 0;
+
+ parse_state state;
state.filename = fn;
state.line = 0;
state.ptr = strdup(data.c_str()); // TODO: fix this code!
@@ -444,6 +444,7 @@ int init_parse_config_file(const char* path) {
return -1;
}
+ data.push_back('\n'); // TODO: fix parse_config.
parse_config(path, data);
dump_parser_state();
diff --git a/init/property_service.cpp b/init/property_service.cpp
index a52c41d..0ee0351 100644
--- a/init/property_service.cpp
+++ b/init/property_service.cpp
@@ -420,6 +420,7 @@ static void load_properties_from_file(const char* filename, const char* filter)
Timer t;
std::string data;
if (read_file(filename, &data)) {
+ data.push_back('\n');
load_properties(&data[0], filter);
}
NOTICE("(Loading properties from %s took %.2fs.)\n", filename, t.duration());
diff --git a/init/ueventd_parser.cpp b/init/ueventd_parser.cpp
index 7a4841f..497c606 100644
--- a/init/ueventd_parser.cpp
+++ b/init/ueventd_parser.cpp
@@ -193,10 +193,10 @@ static void parse_line(struct parse_state *state, char **args, int nargs)
static void parse_config(const char *fn, const std::string& data)
{
- struct parse_state state;
char *args[UEVENTD_PARSER_MAXARGS];
- int nargs;
- nargs = 0;
+
+ int nargs = 0;
+ parse_state state;
state.filename = fn;
state.line = 1;
state.ptr = strdup(data.c_str()); // TODO: fix this code!
@@ -231,6 +231,7 @@ int ueventd_parse_config_file(const char *fn)
return -1;
}
+ data.push_back('\n'); // TODO: fix parse_config.
parse_config(fn, data);
dump_parser_state();
return 0;
diff --git a/init/util.cpp b/init/util.cpp
index d6fd0fc..df4c25f 100644
--- a/init/util.cpp
+++ b/init/util.cpp
@@ -171,9 +171,6 @@ bool read_file(const char* path, std::string* content) {
bool okay = android::base::ReadFdToString(fd, content);
TEMP_FAILURE_RETRY(close(fd));
- if (okay) {
- content->append("\n", 1);
- }
return okay;
}
@@ -475,4 +472,3 @@ std::string bytes_to_hex(const uint8_t* bytes, size_t bytes_len) {
android::base::StringAppendF(&hex, "%02x", bytes[i]);
return hex;
}
-