File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -124,15 +124,17 @@ static char *resolve_symlink(char *p, size_t s)
124124
125125static int lock_file (struct lock_file * lk , const char * path , int flags )
126126{
127- if (strlen (path ) >= sizeof (lk -> filename ))
128- return -1 ;
129- strcpy (lk -> filename , path );
130127 /*
131128 * subtract 5 from size to make sure there's room for adding
132129 * ".lock" for the lock file name
133130 */
131+ static const size_t max_path_len = sizeof (lk -> filename ) - 5 ;
132+
133+ if (strlen (path ) >= max_path_len )
134+ return -1 ;
135+ strcpy (lk -> filename , path );
134136 if (!(flags & LOCK_NODEREF ))
135- resolve_symlink (lk -> filename , sizeof ( lk -> filename ) - 5 );
137+ resolve_symlink (lk -> filename , max_path_len );
136138 strcat (lk -> filename , ".lock" );
137139 lk -> fd = open (lk -> filename , O_RDWR | O_CREAT | O_EXCL , 0666 );
138140 if (0 <= lk -> fd ) {
You can’t perform that action at this time.
0 commit comments