diff options
author | Daniel Kolesa <d.kolesa@osg.samsung.com> | 2015-06-09 14:01:25 +0100 |
---|---|---|
committer | Daniel Kolesa <d.kolesa@osg.samsung.com> | 2015-06-09 14:01:25 +0100 |
commit | b90c1bf90e67f1838152185dce5a270f3f824f6b (patch) | |
tree | 0255638c4cc55bb616076c3d72b616c875602bc4 /src/lib/elua/elua.c | |
parent | 6692319c7873e0fbb797f01bc2ca41c2d12824b4 (diff) |
elua lib: sanitize all file paths before writing them
This will prevent random nonsense from being written in.
It changes semantics slightly (documented) and also fixes
CID 1267463.
@fix
Diffstat (limited to 'src/lib/elua/elua.c')
-rw-r--r-- | src/lib/elua/elua.c | 48 |
1 files changed, 41 insertions, 7 deletions
diff --git a/src/lib/elua/elua.c b/src/lib/elua/elua.c index a7c86f9a91..0056cf0080 100644 --- a/src/lib/elua/elua.c +++ b/src/lib/elua/elua.c | |||
@@ -108,10 +108,29 @@ EAPI void | |||
108 | elua_state_dirs_set(Elua_State *es, const char *core, const char *mods, | 108 | elua_state_dirs_set(Elua_State *es, const char *core, const char *mods, |
109 | const char *apps) | 109 | const char *apps) |
110 | { | 110 | { |
111 | char *spath = NULL; | ||
111 | EINA_SAFETY_ON_NULL_RETURN(es); | 112 | EINA_SAFETY_ON_NULL_RETURN(es); |
112 | if (core) es->coredir = eina_stringshare_add(core); | 113 | if (core) |
113 | if (mods) es->moddir = eina_stringshare_add(mods); | 114 | { |
114 | if (apps) es->appsdir = eina_stringshare_add(apps); | 115 | eina_stringshare_del(es->coredir); |
116 | spath = eina_file_path_sanitize(core); | ||
117 | es->coredir = eina_stringshare_add(spath); | ||
118 | free(spath); | ||
119 | } | ||
120 | if (mods) | ||
121 | { | ||
122 | eina_stringshare_del(es->moddir); | ||
123 | spath = eina_file_path_sanitize(mods); | ||
124 | es->moddir = eina_stringshare_add(spath); | ||
125 | free(spath); | ||
126 | } | ||
127 | if (apps) | ||
128 | { | ||
129 | eina_stringshare_del(es->appsdir); | ||
130 | spath = eina_file_path_sanitize(apps); | ||
131 | es->appsdir = eina_stringshare_add(spath); | ||
132 | free(spath); | ||
133 | } | ||
115 | } | 134 | } |
116 | 135 | ||
117 | EAPI void | 136 | EAPI void |
@@ -128,7 +147,11 @@ elua_state_dirs_fill(Elua_State *es, Eina_Bool ignore_env) | |||
128 | snprintf(coredirbuf, sizeof(coredirbuf), "%s/core", | 147 | snprintf(coredirbuf, sizeof(coredirbuf), "%s/core", |
129 | eina_prefix_data_get(_elua_pfx)); | 148 | eina_prefix_data_get(_elua_pfx)); |
130 | } | 149 | } |
131 | if (coredir) es->coredir = eina_stringshare_add(coredir); | 150 | if (coredir) { |
151 | char *sdir = eina_file_path_sanitize(coredir); | ||
152 | es->coredir = eina_stringshare_add(sdir); | ||
153 | free(sdir); | ||
154 | } | ||
132 | } | 155 | } |
133 | if (!(moddir = es->moddir)) | 156 | if (!(moddir = es->moddir)) |
134 | { | 157 | { |
@@ -138,7 +161,11 @@ elua_state_dirs_fill(Elua_State *es, Eina_Bool ignore_env) | |||
138 | snprintf(moddirbuf, sizeof(moddirbuf), "%s/modules", | 161 | snprintf(moddirbuf, sizeof(moddirbuf), "%s/modules", |
139 | eina_prefix_data_get(_elua_pfx)); | 162 | eina_prefix_data_get(_elua_pfx)); |
140 | } | 163 | } |
141 | if (moddir) es->moddir = eina_stringshare_add(moddir); | 164 | if (moddir) { |
165 | char *sdir = eina_file_path_sanitize(moddir); | ||
166 | es->moddir = eina_stringshare_add(sdir); | ||
167 | free(sdir); | ||
168 | } | ||
142 | } | 169 | } |
143 | if (!(appsdir = es->appsdir)) | 170 | if (!(appsdir = es->appsdir)) |
144 | { | 171 | { |
@@ -148,7 +175,11 @@ elua_state_dirs_fill(Elua_State *es, Eina_Bool ignore_env) | |||
148 | snprintf(appsdirbuf, sizeof(appsdirbuf), "%s/apps", | 175 | snprintf(appsdirbuf, sizeof(appsdirbuf), "%s/apps", |
149 | eina_prefix_data_get(_elua_pfx)); | 176 | eina_prefix_data_get(_elua_pfx)); |
150 | } | 177 | } |
151 | if (appsdir) es->appsdir = eina_stringshare_add(appsdir); | 178 | if (appsdir) { |
179 | char *sdir = eina_file_path_sanitize(appsdir); | ||
180 | es->appsdir = eina_stringshare_add(sdir); | ||
181 | free(sdir); | ||
182 | } | ||
152 | } | 183 | } |
153 | } | 184 | } |
154 | 185 | ||
@@ -183,10 +214,13 @@ elua_state_prog_name_get(const Elua_State *es) | |||
183 | EAPI void | 214 | EAPI void |
184 | elua_state_include_path_add(Elua_State *es, const char *path) | 215 | elua_state_include_path_add(Elua_State *es, const char *path) |
185 | { | 216 | { |
217 | char *spath = NULL; | ||
186 | EINA_SAFETY_ON_NULL_RETURN(es); | 218 | EINA_SAFETY_ON_NULL_RETURN(es); |
187 | EINA_SAFETY_ON_NULL_RETURN(path); | 219 | EINA_SAFETY_ON_NULL_RETURN(path); |
188 | EINA_SAFETY_ON_FALSE_RETURN(path[0]); | 220 | EINA_SAFETY_ON_FALSE_RETURN(path[0]); |
189 | es->lincs = eina_list_append(es->lincs, eina_stringshare_add(path)); | 221 | spath = eina_file_path_sanitize(path); |
222 | es->lincs = eina_list_append(es->lincs, eina_stringshare_add(spath)); | ||
223 | free(spath); | ||
190 | } | 224 | } |
191 | 225 | ||
192 | EAPI Eina_Bool | 226 | EAPI Eina_Bool |