🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gdb.bug
Article #8833

GDB 4.7 gdb/environ.c uses memcpy on overlapping regions

#8833
From: Paul Eggert
Date: Sun, 25 Oct 1992 17:53
37 lines
1748 bytes
GDB 4.7's gdb/environ.c applies the memcpy routine to overlapping regions of
memory.  This isn't portable -- the ANSI C standard says that the results are
undefined when applying memcpy to overlapping regions.  environ.c should use
memmove instead (it's defined just for that purpose), but I suppose that
memmove is too much of a pain to configure, so here is a patch that avoids
memcpy entirely.

I reported this bug for GDB 4.6 but it wasn't fixed in GDB 4.7.
Since environ.c didn't change, the same patch works for GDB 4.7.


===================================================================
RCS file: gdb/environ.c,v
retrieving revision 4.6
diff -c -r4.6 gdb/environ.c
*** gdb/environ.c	1992/07/06 17:10:46	4.6
--- gdb/environ.c	1992/07/23 23:27:13
***************
*** 179,187 ****
  	&& s[len] == '=')
        {
  	free (s);
! 	memcpy (vector, vector + 1,
! 		(e->allocated - (vector - e->vector)) * sizeof (char *));
! 	e->vector[e->allocated - 1] = 0;
  	return;
        }
  }
--- 179,186 ----
  	&& s[len] == '=')
        {
  	free (s);
! 	while ((vector[0] = vector[1]) != NULL)
! 	  vector++;
  	return;
        }
  }
Technical Details
Message-ID: <9210251753.AA10207@bi.twinsun.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!bi.TWinsun.COM!eggert

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f5053,8138ac49fb3e0be1,start
X-Google-Attributes: gidf5053,public
X-Google-ArrivalTime: 1992-10-25 15:12:22 PST
Newsgroups: gnu.gdb.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!bi.TWinsun.COM!eggert
From: eggert@bi.TWinsun.COM (Paul Eggert)
Subject: GDB 4.7 gdb/environ.c uses memcpy on overlapping regions
Message-ID: <9210251753.AA10207@bi.twinsun.com>
Sender: gnulists@ai.mit.edu
Organization: GNUs Not Usenet
Distribution: gnu
Date: Sun, 25 Oct 1992 17:53:23 GMT
Approved: bug-gdb@prep.ai.mit.edu
Lines: 38