utils: lockfile: avoid stack overflow for lockfile buffer

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>
This commit is contained in:
Aleksa Sarai
2022-06-20 19:09:57 +10:00
committed by Jari Sundell
parent d067bd802e
commit 92bec88d09
+2 -1
View File
@@ -98,7 +98,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());
int __UNUSED result = ::write(fd, buf, std::strlen(buf));
}