• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/corennnnn


コミットメタ情報

リビジョンba9ec54e6a8c5db3340179b985930a6c300e0a2a (tree)
日時2016-12-09 16:22:10
作者Chih-Wei Huang <cwhuang@linu...>
コミッターChih-Wei Huang

ログメッセージ

ueventd: fix copied string not being freed

Unlike change Id0a5f711e33363082ba201afda6b26043998cb1c,
parse_subsystem and parse_line_subsystem hold points to memory
of the copied string which can't be freed.

To fix the issue, duplicate the strings to be hold.
Then we can parse the std::string data directly without
copying it.

Change-Id: I4dbf543de6880537b419e6c2344ee6a40ce378f1

変更サマリ

差分

--- a/init/ueventd_parser.cpp
+++ b/init/ueventd_parser.cpp
@@ -113,7 +113,7 @@ static void *parse_subsystem(parse_state* state, int /*nargs*/, char** args) {
113113 parse_error(state, "out of memory\n");
114114 return 0;
115115 }
116- s->name = args[1];
116+ s->name = strdup(args[1]);
117117 s->dirname = "/dev";
118118 list_add_tail(&subsystem_list, &s->slist);
119119 return s;
@@ -142,7 +142,7 @@ static void parse_line_subsystem(struct parse_state *state, int nargs,
142142
143143 case K_dirname:
144144 if (args[1][0] == '/')
145- s->dirname = args[1];
145+ s->dirname = strdup(args[1]);
146146 else
147147 parse_error(state, "dirname '%s' does not start with '/'\n",
148148 args[1]);
@@ -191,7 +191,7 @@ static void parse_line(struct parse_state *state, char **args, int nargs)
191191 }
192192 }
193193
194-static void parse_config(const char *fn, const std::string& data)
194+static void parse_config(const char *fn, std::string& data)
195195 {
196196 char *args[UEVENTD_PARSER_MAXARGS];
197197
@@ -199,7 +199,7 @@ static void parse_config(const char *fn, const std::string& data)
199199 parse_state state;
200200 state.filename = fn;
201201 state.line = 1;
202- state.ptr = strdup(data.c_str()); // TODO: fix this code!
202+ state.ptr = &data[0];
203203 state.nexttoken = 0;
204204 state.parse_line = parse_line_no_op;
205205 for (;;) {