This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] gcc: fix segfault from calling free on non-malloc'd area
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Jeff Law <law at redhat dot com>, Matthias Klose <doko at ubuntu dot com>
- Cc: Tobias Burnus <burnus at net-b dot de>, Paul Gortmaker <paul dot gortmaker at windriver dot com>, gcc-patches at gcc dot gnu dot org
- Date: Mon, 23 Jun 2014 22:42:41 +0200
- Subject: Re: [PATCH] gcc: fix segfault from calling free on non-malloc'd area
- Authentication-results: sourceware.org; auth=none
- References: <1403534578-41451-1-git-send-email-paul dot gortmaker at windriver dot com> <53A88976 dot 1030608 at net-b dot de> <53A88EE5 dot 1060405 at redhat dot com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Mon, Jun 23, 2014 at 02:32:37PM -0600, Jeff Law wrote:
> On 06/23/14 14:09, Tobias Burnus wrote:
> >This patch broke bootstrapping for me on x86-64-gnu-linux:
> >
> >/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld:
> >i386 architecture of input file `/usr/lib/crti.o' is incompatible with
> >i386:x86-64 output
>
> >
> >If I revert the patch, it works for me.
> Reverted. Will have to look deeper. Paul, did you bootstrap with this
> patch on the trunk?
I can see one spot where multilib_os_dir is set to non-malloced string
literal, and at that point we also leak memory.
So, supposedly:
new_multilib_os_dir = XNEWVEC (char, ml_end - q);
memcpy (new_multilib_os_dir, q + 1, ml_end - q - 1);
new_multilib_os_dir[ml_end - q - 1] = '\0';
multilib_os_dir = *new_multilib_os_dir ? new_multilib_os_dir : ".";
should be instead:
if (ml_end - q == 1)
multilib_os_dir = xstrdup (".");
else
{
new_multilib_os_dir = XNEWVEC (char, ml_end - q);
memcpy (new_multilib_os_dir, q + 1, ml_end - q - 1);
new_multilib_os_dir[ml_end - q - 1] = '\0';
multilib_os_dir = new_multilib_os_dir;
}
or so (completely untested). Bet this got broken when the multiarch support
has been added, before that multilib_os_dir has always been malloced.
Alternatively, multilib_os_dir could be set to NULL instead of setting it to
".".
Jakub