From 0b6f7b047e779f762f251f4b9219961627506d99 Mon Sep 17 00:00:00 2001 From: shenpeixing Date: Tue, 24 Jun 2025 17:52:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9miscdevice=E6=9C=8D=E5=8A=A1t?= =?UTF-8?q?dd=E7=9A=84crash=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: shenpeixing --- utils/common/src/file_utils.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/utils/common/src/file_utils.cpp b/utils/common/src/file_utils.cpp index 26400bf..fff2eac 100755 --- a/utils/common/src/file_utils.cpp +++ b/utils/common/src/file_utils.cpp @@ -193,8 +193,17 @@ std::string ReadFd(const RawFileDescriptor &rawFd) MISC_HILOGE("length is invalid, length:%{public}" PRId64, rawFd.length); return {}; } - FILE *fp = fdopen(rawFd.fd, "r"); - CHKPS(fp); + int dupFd = dup(rawFd.fd); + if (dupFd < 0) { + MISC_HILOGE("dup fd failed, fd:%{public}d, errno:%{public}d", rawFd.fd, errno); + return {}; + } + FILE *fp = fdopen(dupFd, "r"); + if (fp == nullptr) { + MISC_HILOGE("fdopen failed, fd:%{public}d, errno:%{public}d", dupFd, errno); + close(dupFd); + return {}; + } if (fseek(fp, rawFd.offset, SEEK_SET) != 0) { MISC_HILOGE("fseek failed, errno:%{public}d", errno); if (fclose(fp) != 0) { -- Gitee