File tree Expand file tree Collapse file tree 2 files changed +7
-2
lines changed
FairyPlugin/src/main/java/com/limpoxe/fairy Expand file tree Collapse file tree 2 files changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -189,7 +189,7 @@ PluginDescriptor getPluginDescriptorByClassName(String clazzName) {
189
189
synchronized InstallResult installPlugin (String srcPluginFile ) {
190
190
LogUtil .w ("开始安装插件" , srcPluginFile );
191
191
long startAt = System .currentTimeMillis ();
192
- if (TextUtils .isEmpty (srcPluginFile )) {
192
+ if (! FileUtil . checkPathSafe ( srcPluginFile ) || TextUtils .isEmpty (srcPluginFile )) {
193
193
return new InstallResult (PluginManagerHelper .SRC_FILE_NOT_FOUND );
194
194
}
195
195
@@ -209,11 +209,12 @@ synchronized InstallResult installPlugin(String srcPluginFile) {
209
209
// 先将apk复制到宿主程序私有目录,防止在安装过程中文件被篡改
210
210
if (!srcPluginFile .startsWith (FairyGlobal .getHostApplication ().getCacheDir ().getAbsolutePath ())) {
211
211
String tempFilePath = FairyGlobal .getHostApplication ().getCacheDir ().getAbsolutePath ()
212
- + File .separator + System .currentTimeMillis () + "_" + srcFile .getName () + ".apk" ;
212
+ + File .separator + System .currentTimeMillis () + "_" + srcFile .getName ();
213
213
if (FileUtil .copyFile (srcPluginFile , tempFilePath )) {
214
214
srcPluginFile = tempFilePath ;
215
215
} else {
216
216
LogUtil .e ("复制插件文件失败" , srcPluginFile , tempFilePath );
217
+ new File (tempFilePath ).delete ();
217
218
return new InstallResult (PluginManagerHelper .COPY_FILE_FAIL );
218
219
}
219
220
}
Original file line number Diff line number Diff line change @@ -313,4 +313,8 @@ public static String streamToString(InputStream input) throws IOException {
313
313
return sb .toString ();
314
314
}
315
315
316
+ public static boolean checkPathSafe (String path ) {
317
+ return path != null && !path .contains (".." ) && !path .contains (" " );
318
+ }
319
+
316
320
}
You can’t perform that action at this time.
0 commit comments