Avoid copy to buffer name using same source as destination to accomodate sensitive implementation of str(n)cpy.

This commit is contained in:
Renaud 2017-05-02 12:15:19 +08:00
parent 19e33fef82
commit 7f8ab2d2a5
1 changed files with 4 additions and 2 deletions

6
file.c
View File

@ -283,8 +283,10 @@ int readin(const char *fname, boolean lockfl)
return status ;
bp->b_flag &= ~(BFINVS | BFCHG);
strncpy( bp->b_fname, fname, sizeof( fname_t) - 1) ;
bp->b_fname[ sizeof( fname_t) - 1] = '\0' ;
if( fname != bp->b_fname) { /* Copy if source differs from destination */
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);