Skip to content

Commit

Permalink
utils: lockfile: avoid stack overflow for lockfile buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
Elegant996 committed May 15, 2023
1 parent c11d613 commit 565f419
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/utils/lockfile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ Lockfile::try_lock() {
int pos = ::gethostname(buf, 255);

if (pos == 0) {
::snprintf(buf + std::strlen(buf), 255, ":+%i\n", ::getpid());
ssize_t len = std::strlen(buf);
::snprintf(buf + len, 255 - len, ":+%i\n", ::getpid());
ssize_t __attribute__((unused)) result = ::write(fd, buf, std::strlen(buf));
}

Expand Down

0 comments on commit 565f419

Please sign in to comment.