From d1143623f254b6ffea4daf6c8157bd8ba8c614cb Mon Sep 17 00:00:00 2001 From: ml Date: Mon, 11 Nov 2024 15:56:48 +0800 Subject: [PATCH] Signed-off-by: ml --- entry/src/main/ets/pages/changeEncryption.ets | 9 +++++++++ entry/src/main/ets/pages/encryptionProtection.ets | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/entry/src/main/ets/pages/changeEncryption.ets b/entry/src/main/ets/pages/changeEncryption.ets index ba13820..770d927 100644 --- a/entry/src/main/ets/pages/changeEncryption.ets +++ b/entry/src/main/ets/pages/changeEncryption.ets @@ -33,6 +33,7 @@ import { toggleShow, directionStatus, getTime, + isValidPath, sendDlpManagerFileConfiguration } from '../common/utils'; import { DlpAlertDialog } from '../common/components/dlp_alert_dialog'; @@ -216,6 +217,10 @@ struct changeEncryption { HiLog.info(TAG, `Decrypt DLP file: ${this.srcFileName}`); try { let srcFileUri: string = GlobalContext.load('uri'); + if (!isValidPath(srcFileUri)) { + HiLog.error(TAG, `uri is invalid`); + return; + } let srcFileMsg: FileMsg = FileUtils.getAllSuffixByUri(srcFileUri); let documentSaveOptions = new picker.DocumentSaveOptions(); documentSaveOptions.newFileNames = [decodeURIComponent(plaintextFile)]; @@ -245,6 +250,10 @@ struct changeEncryption { async fileDecryption(saveRes: Array): Promise { let plainUri = saveRes[0]; + if (!isValidPath(plainUri)) { + HiLog.error(TAG, `pick save uri is invalid`); + return; + } let uriInfo: fileUri.FileUri | undefined = undefined; let file: fs.File | undefined = undefined; try { diff --git a/entry/src/main/ets/pages/encryptionProtection.ets b/entry/src/main/ets/pages/encryptionProtection.ets index d2c637b..1d30924 100644 --- a/entry/src/main/ets/pages/encryptionProtection.ets +++ b/entry/src/main/ets/pages/encryptionProtection.ets @@ -37,6 +37,7 @@ import { getFileUriByPath, sendDlpFileCreateProperties, sendDlpManagerFileConfiguration, + isValidPath, getFileSizeByUri } from '../common/utils'; import Constants from '../common/constant'; @@ -366,6 +367,10 @@ struct DlpDialog { await this.setUserStat(); try { let srcFileUri: string = GlobalContext.load('uri'); + if (!isValidPath(srcFileUri)) { + HiLog.error(TAG, `uri is invalid`); + return; + } let srcFileMsg: FileMsg = FileUtils.getSuffixFileMsgByUri(srcFileUri); let srcFileSize: number = await getFileSizeByUri(srcFileUri); AppStorage.setOrCreate('hiFileSize', srcFileSize); @@ -385,6 +390,10 @@ struct DlpDialog { } HiLog.info(TAG, `get uri success`); uri = saveRes[0]; + if (!isValidPath(uri)) { + HiLog.error(TAG, `pick save uri is invalid`); + return; + } let uriInfo: fileUri.FileUri = new fileUri.FileUri(''); try { uriInfo = new fileUri.FileUri(uri);