From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id DEB7A3858D1E; Tue, 18 Apr 2023 08:13:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DEB7A3858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681805599; bh=+jGk9BD32qYzPl0gIHsCSTZ/f6cIRpZtrIPU09oSAP8=; h=From:To:Subject:Date:From; b=ZPr59Pxaa1HfQpVZl23rEEq3C/1QiliiPxEyPr5Cgn7dkCCjcU3KfTGZtlJkTUtcz rlzg8/9UUP88mTIYIsQZnDSrUiRW0aS7hnPRvUZTHRquInFlULg39x9imGsOMTfiIL BYGyZRC8ZPZ0uWOPFhljfsHkjZltRG/uiR8yvIYk= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin/cygwin-3_4-branch] Cygwin: cygheap: fix fork error after heap has grown X-Act-Checkin: newlib-cygwin X-Git-Author: David McFarland X-Git-Refname: refs/heads/cygwin-3_4-branch X-Git-Oldrev: 595fcb21ffc01b3469dad6484c11ebfd263d7f3c X-Git-Newrev: 6fbca24f33c2430b51c5413a7b4c85f4784b4d4c Message-Id: <20230418081319.DEB7A3858D1E@sourceware.org> Date: Tue, 18 Apr 2023 08:13:19 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D6fbca24f33c= 2430b51c5413a7b4c85f4784b4d4c commit 6fbca24f33c2430b51c5413a7b4c85f4784b4d4c Author: David McFarland AuthorDate: Mon Apr 17 21:41:55 2023 -0300 Commit: Corinna Vinschen CommitDate: Tue Apr 18 10:12:43 2023 +0200 Cygwin: cygheap: fix fork error after heap has grown =20 2f9b8ff0 introduced a problem where forks would sometimes fail with: =20 child_copy: cygheap read copy failed, 0x0..0x80044C750, done 0, windows= pid 14032, Win32 error 299 =20 When cygheap_max was > CYGHEAP_STORAGE_INITIAL, commit_size would be se= t to allocsize(cygheap_max), which is an address, not a size. VirtualAlloc = would be called to commit commit_size bytes, which would fail, and then child_co= py would be called with zero as the base address. =20 Fixes: 2f9b8ff00cce ("Cygwin: decouple cygheap from Cygwin DLL") Signed-off-by: David McFarland Diff: --- winsup/cygwin/mm/cygheap.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/winsup/cygwin/mm/cygheap.cc b/winsup/cygwin/mm/cygheap.cc index 609407656cdd..4fda29d117a7 100644 --- a/winsup/cygwin/mm/cygheap.cc +++ b/winsup/cygwin/mm/cygheap.cc @@ -87,7 +87,8 @@ cygheap_fixup_in_child (bool execed) SIZE_T commit_size =3D CYGHEAP_STORAGE_INITIAL - CYGHEAP_STORAGE_LOW; =20 if (child_proc_info->cygheap_max > (void *) CYGHEAP_STORAGE_INITIAL) - commit_size =3D allocsize (child_proc_info->cygheap_max); + commit_size =3D allocsize ((char *) child_proc_info->cygheap_max + - CYGHEAP_STORAGE_LOW); cygheap =3D (init_cygheap *) VirtualAlloc ((LPVOID) CYGHEAP_STORAGE_LOW, CYGHEAP_STORAGE_HIGH - CYGHEAP_STORAGE_LOW,