From 7f8ab2d2a5fd18dde322a3e37ee6f7161b686e35 Mon Sep 17 00:00:00 2001 From: Renaud Fivet Date: Tue, 2 May 2017 12:15:19 +0800 Subject: [PATCH] Avoid copy to buffer name using same source as destination to accomodate sensitive implementation of str(n)cpy. --- file.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/file.c b/file.c index 50208de..d1bce00 100644 --- a/file.c +++ b/file.c @@ -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);