This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] gcc: fix segfault from calling free on non-malloc'd area


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]