From 3af4ee19a2fe2aaa614b0841965759d1a7398acf Mon Sep 17 00:00:00 2001 From: Renaud Fivet Date: Sat, 19 Mar 2016 14:36:27 +0800 Subject: [PATCH] Adjust maximum file length in pklock. --- pklock.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/pklock.c b/pklock.c index dd8db5c..3616cf9 100644 --- a/pklock.c +++ b/pklock.c @@ -20,7 +20,8 @@ #endif #include -#define MAXLOCK 512 +/* Maximum file length name 255 */ +#define MAXLOCK 256 #define MAXNAME 128 #if defined(SVR4) && ! defined(__linux__) @@ -44,11 +45,14 @@ int gethostname(char *name, int namelen) char *dolock( const char *fname) { int fd, n; - static char lname[MAXLOCK], locker[MAXNAME + 1]; + char lname[ MAXLOCK] ; + static char locker[ MAXNAME + 1] ; int mask; struct stat sbuf; - strcat(strcpy(lname, fname), ".lock~"); + strncpy( lname, fname, sizeof lname - 1 - 6) ; + lname[ sizeof lname - 1 - 6] = 0 ; + strcat( lname, ".lock~") ; /* check that we are not being cheated, qname must point to */ /* a regular file - even this code leaves a small window of */ @@ -111,11 +115,12 @@ char *dolock( const char *fname) * *********************/ -char *undolock( const char *fname) -{ - static char lname[MAXLOCK]; +char *undolock( const char *fname) { + char lname[ MAXLOCK] ; - strcat(strcpy(lname, fname), ".lock~"); + strncpy( lname, fname, sizeof lname - 1 - 6) ; + lname[ sizeof lname - 1 - 6] = 0 ; + strcat( lname, ".lock~") ; if (unlink(lname) != 0) { if (errno == EACCES || errno == ENOENT) return NULL;