>>> On 9/24/2008 at 11:28 PM, in message <[EMAIL PROTECTED]>, <[EMAIL PROTECTED]> wrote: > Revision: 1824 > http://ganglia.svn.sourceforge.net/ganglia/?rev=1824&view=rev > Author: carenas > Date: 2008-09-25 05:28:37 +0000 (Thu, 25 Sep 2008) > > Log Message: > ----------- > gmond: replace strcpy calls with equivalent strncpy calls > > Modified Paths: > -------------- > trunk/monitor-core/gmond/gmond.c > > Modified: trunk/monitor-core/gmond/gmond.c > =================================================================== > --- trunk/monitor-core/gmond/gmond.c 2008-09-23 18:48:32 UTC (rev 1823) > +++ trunk/monitor-core/gmond/gmond.c 2008-09-25 05:28:37 UTC (rev 1824) > @@ -658,7 +658,7 @@ > { > name_len = strlen(firstName); > buff = malloc(name_len+1); > - strcpy(buff, firstName); > + strncpy(buff, firstName, name_len + 1); > firstName = buff; > secondName = strchr(buff+1,':'); > if(secondName) > @@ -705,7 +705,7 @@ > > spoof_info_len = strlen(metric_id->host); > buff = malloc(spoof_info_len+1); > - strcpy(buff,metric_id->host); > + strncpy(buff, metric_id->host, spoof_info_len + 1); > spoofIP = buff; > if( !(spoofName = strchr(buff+1,':')) ){ > err_msg("Incorrect format for spoof argument. exiting.\n"); > >
Shouldn't the length passed into the strncpy() functions be the actual length rather than the length + 1? The reason for allocating the buffer as length + 1 is to accommodate the NULL terminator. If the strncpy() function allows a string of the same size as the allocated buffer, it will still overrun with the NULL terminator or be left without a NULL terminator. Brad ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Ganglia-developers mailing list Ganglia-developers@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ganglia-developers