Skip to content

Commit

Permalink
utils: lockfile: avoid stack overflow for lockfile buffer
Browse files Browse the repository at this point in the history
There appears to have been some change on openSUSE (likely some new
hardening flags for builds, or some glibc hardening) such that incorrect
buffer handling results in a segfault even if the buffer is never
overflowed.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
  • Loading branch information
cyphar authored and jesec committed Jul 21, 2023
1 parent e9303f6 commit 199e8f8
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/utils/lockfile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ Lockfile::try_lock() {
int pos = ::gethostname(buf, 255);

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

::close(fd);
Expand Down

0 comments on commit 199e8f8

Please sign in to comment.