Skip to content

Commit

Permalink
Don't write trailing nulls to pidfile (#107)
Browse files Browse the repository at this point in the history
As written we would always write a 64 byte pidfile with dozens of
null terminator characters (or even garbage characters from non-zeroed
memory). With this change we only write the decimal PID, a newline,
and a single null terminator.
  • Loading branch information
yabberyabber authored Jan 10, 2025
1 parent fada3bd commit 219bca9
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion enter.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ int enter(struct entry_settings *opts)
if ((size_t) snprintf(data, sizeof (data), "%d\n", pid) >= sizeof (data)) {
errx(1, "'%d\n' takes more than %zu bytes.", pid, sizeof (data));
}
size_t remain = sizeof (data);
size_t remain = strlen (data);
char *ptr = data;
while (remain > 0) {
ssize_t written = write(pidfile, ptr, remain);
Expand Down

0 comments on commit 219bca9

Please sign in to comment.