From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1792) id 6D16B3858D3C; Wed, 26 Apr 2023 23:29:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6D16B3858D3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1682551751; bh=7eTtJAOF2k3xpF5LDtc+nvzj+WQd9c1raqS0vjaqRjs=; h=From:To:Subject:Date:From; b=yXIM5+A1dTYEC17uyna95+epS5gtMTUSo0hJScE0QKURRyFkJxK2tif+phGq9rgYZ qlKNMooEa3zJxMIFbRZl+UT06PcHBz9u+k348XkzulHzfbXwQpWHzxNkFB4Sd0ThDC PjySP66nIbMqYzgGK6f0Ym/O3SF38MiWtJfQP5zw= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Samuel Thibault To: glibc-cvs@sourceware.org Subject: [glibc] Fix Hurd getcwd build with GCC >= 13 X-Act-Checkin: glibc X-Git-Author: Joseph Myers X-Git-Refname: refs/heads/master X-Git-Oldrev: bcca5ae8049efd98ef11f45cf0f1fcea661b3cc1 X-Git-Newrev: af16a59ee1f72392b88d439d8f802c9844f86f4f Message-Id: <20230426232911.6D16B3858D3C@sourceware.org> Date: Wed, 26 Apr 2023 23:29:11 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=af16a59ee1f72392b88d439d8f802c9844f86f4f commit af16a59ee1f72392b88d439d8f802c9844f86f4f Author: Joseph Myers Date: Wed Apr 26 17:14:18 2023 +0000 Fix Hurd getcwd build with GCC >= 13 The build of glibc for i686-gnu has been failing for a while with GCC mainline / GCC 13: ../sysdeps/mach/hurd/getcwd.c: In function '__hurd_canonicalize_directory_name_internal': ../sysdeps/mach/hurd/getcwd.c:242:48: error: pointer 'file_name' may be used after 'realloc' [-Werror=use-after-free] 242 | file_namep = &buf[file_namep - file_name + size / 2]; | ~~~~~~~~~~~^~~~~~~~~~~ ../sysdeps/mach/hurd/getcwd.c:236:25: note: call to 'realloc' here 236 | buf = realloc (file_name, size); | ^~~~~~~~~~~~~~~~~~~~~~~~~ Fix by doing the subtraction before the reallocation. Tested with build-many-glibcs.py for i686-gnu. [samuel.thibault@ens-lyon.rg: Removed mention of this being a bug] Message-Id: <18587337-7815-4056-ebd0-724df262d591@codesourcery.com> Diff: --- sysdeps/mach/hurd/getcwd.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sysdeps/mach/hurd/getcwd.c b/sysdeps/mach/hurd/getcwd.c index f24b35b380..cd3aedd9cd 100644 --- a/sysdeps/mach/hurd/getcwd.c +++ b/sysdeps/mach/hurd/getcwd.c @@ -222,8 +222,9 @@ __hurd_canonicalize_directory_name_internal (file_t thisdir, found: { /* Prepend the directory name just discovered. */ + size_t offset = file_namep - file_name; - if (file_namep - file_name < d->d_namlen + 1) + if (offset < d->d_namlen + 1) { if (orig_size > 0) { @@ -239,7 +240,7 @@ __hurd_canonicalize_directory_name_internal (file_t thisdir, free (file_name); return NULL; } - file_namep = &buf[file_namep - file_name + size / 2]; + file_namep = &buf[offset + size / 2]; file_name = buf; /* Move current contents up to the end of the buffer. This is guaranteed to be non-overlapping. */