Skip to content

Commit 3e88e8f

Browse files
mhaggergitster
authored andcommitted
commit_lock_file(): use a strbuf to manage temporary space
Avoid relying on the filename length restrictions that are currently checked by lock_file(). Signed-off-by: Michael Haggerty <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent daccee3 commit 3e88e8f

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lockfile.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,19 +319,21 @@ int reopen_lock_file(struct lock_file *lk)
319319

320320
int commit_lock_file(struct lock_file *lk)
321321
{
322-
char result_file[PATH_MAX];
322+
static struct strbuf result_file = STRBUF_INIT;
323+
int err;
323324

324325
if (!lk->active)
325326
die("BUG: attempt to commit unlocked object");
326327

327328
if (close_lock_file(lk))
328329
return -1;
329330

330-
strcpy(result_file, lk->filename);
331331
/* remove ".lock": */
332-
result_file[strlen(result_file) - LOCK_SUFFIX_LEN] = 0;
333-
334-
if (rename(lk->filename, result_file)) {
332+
strbuf_add(&result_file, lk->filename,
333+
strlen(lk->filename) - LOCK_SUFFIX_LEN);
334+
err = rename(lk->filename, result_file.buf);
335+
strbuf_reset(&result_file);
336+
if (err) {
335337
int save_errno = errno;
336338
rollback_lock_file(lk);
337339
errno = save_errno;

0 commit comments

Comments
 (0)