Use strncpy instead of strcpy. (CID 39928 eval, 39931 file, 39932 exec, 39938 bind).

This commit is contained in:
Renaud 2015-03-19 12:42:47 +08:00
parent eb7217f8ec
commit 8de64f81be
4 changed files with 11 additions and 6 deletions

3
bind.c
View File

@ -352,7 +352,8 @@ static int buildlist( char *mstring)
continue ;
#endif
/* add in the command name */
strcpy(outseq, nptr->n_name);
strncpy( outseq, nptr->n_name, sizeof outseq - 1) ;
outseq[ sizeof outseq - 1] = '\0' ;
cpos = strlen(outseq);
/* search down any keys bound to this */

8
eval.c
View File

@ -796,9 +796,11 @@ int setvar(int f, int n)
}
/* get the value for that variable */
if (f == TRUE)
strcpy(value, i_to_a(n));
else {
if( f == TRUE) {
/* a bit overcautious here in using strncpy */
strncpy( value, i_to_a( n), sizeof value - 1) ;
value[ sizeof value - 1] = '\0' ;
} else {
status = mlreply( "Value: ", value, sizeof value);
if (status != TRUE)
return status;

3
exec.c
View File

@ -176,7 +176,8 @@ static int docmd( char *cline) {
/* process leadin argument */
if( !is_it_cmd( tkn)) {
f = TRUE;
strcpy(tkn, getval(tkn));
strncpy( tkn, getval( tkn), sizeof tkn - 1) ;
tkn[ sizeof tkn - 1] = '\0' ;
n = atoi(tkn);
/* and now get the command to execute */

3
file.c
View File

@ -325,7 +325,8 @@ int readin(const char *fname, boolean lockfl)
if ((s = bclear(bp)) != TRUE) /* Might be old. */
return s;
bp->b_flag &= ~(BFINVS | BFCHG);
strcpy(bp->b_fname, fname);
strncpy( bp->b_fname, fname, sizeof( fname_t) - 1) ;
bp->b_fname[ sizeof( fname_t) - 1] = '\0' ;
/* let a user macro get hold of things...if he wants */
execute(META | SPEC | 'R', FALSE, 1);