File tree Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -124,15 +124,17 @@ static char *resolve_symlink(char *p, size_t s)
124
124
125
125
static int lock_file (struct lock_file * lk , const char * path , int flags )
126
126
{
127
- if (strlen (path ) >= sizeof (lk -> filename ))
128
- return -1 ;
129
- strcpy (lk -> filename , path );
130
127
/*
131
128
* subtract 5 from size to make sure there's room for adding
132
129
* ".lock" for the lock file name
133
130
*/
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 );
134
136
if (!(flags & LOCK_NODEREF ))
135
- resolve_symlink (lk -> filename , sizeof ( lk -> filename ) - 5 );
137
+ resolve_symlink (lk -> filename , max_path_len );
136
138
strcat (lk -> filename , ".lock" );
137
139
lk -> fd = open (lk -> filename , O_RDWR | O_CREAT | O_EXCL , 0666 );
138
140
if (0 <= lk -> fd ) {
You can’t perform that action at this time.
0 commit comments