Article View: gnu.g++.bug
Article #264gcc-2.1 collect2 problem (AND fix)
From: Joe Linoff
Date: Tue, 14 Apr 1992 22:22
Date: Tue, 14 Apr 1992 22:22
40 lines
1650 bytes
1650 bytes
* VERSION: g++ version 2.1
* SOURCE FILE: collect2.c (from the distribution)
=======================================================================
ORIGINAL VERSION (savestring() #line 393)
/* Make a copy of a string INPUT with size SIZE. */
char *
savestring (input, size)
char *input;
int size;
{
char *output = (char *) xmalloc (size + 1);
- strcpy (output, input);
return output;
}
CORRECTED VERSION (savestring() #line 393)
/* Make a copy of a string INPUT with size SIZE. */
char *
savestring (input, size)
char *input;
int size;
{
char *output = (char *) xmalloc (size + 1);
+ strncpy (output, input, size); /* no NULL terminator in input */
+ output[size]=0;
return output;
}
=======================================================================
* DESCRIPTION OF INCORRECT BEHAVIOR:
Collect2 overwrites the heap and generates a segment violation
when a -f.. or -m... switch is used because input does not have
a NULL terminator and too many bytes are copied. The fix is
shown above.
Technical Details
Message-ID:
<9204142222.AA20880@dharna.crosscheck>Path:
arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!dharna.UUCP!joeShow Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!dharna.UUCP!joe From: joe@dharna.UUCP (Joe Linoff) Subject: gcc-2.1 collect2 problem (AND fix) Message-ID: <9204142222.AA20880@dharna.crosscheck> Sender: gnulists@ai.mit.edu Organization: GNUs Not Usenet Distribution: gnu Date: Tue, 14 Apr 1992 22:22:01 GMT Approved: bug-g++@prep.ai.mit.edu Lines: 43