[PATCH] Check the size before prepare_segment

7 views
Skip to first unread message

Yunfeng Ye

unread,
Jul 9, 2021, 12:08:32 AM7/9/21
to libhug...@googlegroups.com, Hewenliang, wux...@huawei.com
While filesz and extrasz of seg_info is zero, mmap in prepare_segment()
will fail, but in this situation, there is no need to copy data.

So check the size before prepare_segment(), and return success for this
situation.

Signed-off-by: Yunfeng Ye <yeyu...@huawei.com>
---
elflink.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/elflink.c b/elflink.c
index ce2ed248cbab..fbd9bebafa43 100644
--- a/elflink.c
+++ b/elflink.c
@@ -930,6 +930,9 @@ static int fork_and_prepare_segment(struct seg_info *htlb_seg_info)
{
int pid, ret, status;

+ if (htlb_seg_info->filesz + htlb_seg_info->extrasz == 0)
+ return 0;
+
if ((pid = fork()) < 0) {
WARNING("fork failed");
return -1;
--
2.27.0
Reply all
Reply to author
Forward
0 new messages