From b3797cee4701b3f4828e8c2844f76847d06d4a90 Mon Sep 17 00:00:00 2001 From: zhuhongtao66 Date: Thu, 22 Dec 2022 17:36:36 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90Beta4=E3=80=91Bug=20fix=20for=20dir.re?= =?UTF-8?q?ad=20of=20out=20of=20memory?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhuhongtao66 --- .../kits/js/src/mod_fileio/class_dir/dir_n_exporter.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.cpp b/interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.cpp index e1041c87e..99572cda7 100644 --- a/interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.cpp +++ b/interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.cpp @@ -181,7 +181,9 @@ napi_value DirNExporter::Read(napi_env env, napi_callback_info info) } else if (string(res->d_name) == "." || string(res->d_name) == "..") { continue; } else { - tmpDirent = *res; + if (EOK != memcpy_s(&tmpDirent, sizeof(dirent), res, res->d_reclen)) { + return UniError(errno); + } break; } } while (true); @@ -231,7 +233,10 @@ napi_value DirNExporter::ReadSync(napi_env env, napi_callback_info info) } else if (string(res->d_name) == "." || string(res->d_name) == "..") { continue; } else { - tmpDirent = *res; + if (EOK != memcpy_s(&tmpDirent, sizeof(dirent), res, res->d_reclen)) { + UniError(errno).ThrowErr(env); + return nullptr; + } break; } } while (true); -- Gitee