summaryrefslogtreecommitdiff
path: root/src/daemon.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-06 12:38:55 -0300
committerGabriel Schneider <[email protected]>2026-11-06 14:56:36 -0300
commitdde4979f59bec754b7909a81a40763850f3c29c0 (patch)
treec885f4ddc37f0564b4b20345c1a0f02672663252 /src/daemon.zig
parent4c194047d210ad9cf571c6019731d00d1e3615a4 (diff)
downloadpardes-dde4979f59bec754b7909a81a40763850f3c29c0.tar.gz
pardes-dde4979f59bec754b7909a81a40763850f3c29c0.zip
idioms #5, more formats that cannot overflow: /proc paths of a pid, the daemon's pty, close and clients words, a pid or a serial for the environment, a capture's header and status line and a cache's .new name are catch unreachable with their reason, where a catch return, null or continue stood for an overflow no buffer here can have
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/daemon.zig')
-rw-r--r--src/daemon.zig9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/daemon.zig b/src/daemon.zig
index a4e2c2d9..118fa58a 100644
--- a/src/daemon.zig
+++ b/src/daemon.zig
@@ -341,14 +341,14 @@ fn tell(words: []const u8, fds: []const c_int) void {
/// A shell forked on `master` (host_io.forkShell): the daemon keeps a dup.
pub fn pty(pid: libc.pid_t, master: c_int) void {
var buf: [32]u8 = undefined;
- tell(std.fmt.bufPrint(&buf, "pty {d}", .{pid}) catch return, &.{master});
+ tell(std.fmt.bufPrint(&buf, "pty {d}", .{pid}) catch unreachable, &.{master}); // a pid fits 32
}
/// The pty of `pid` closed here: the daemon lets its dup go too.
pub fn closed(pid: libc.pid_t) void {
if (pid <= 0) return;
var buf: [32]u8 = undefined;
- tell(std.fmt.bufPrint(&buf, "close {d}", .{pid}) catch return, &.{});
+ tell(std.fmt.bufPrint(&buf, "close {d}", .{pid}) catch unreachable, &.{}); // a pid fits 32
}
pub fn setState(detached: bool) void {
@@ -360,8 +360,9 @@ pub fn setState(detached: bool) void {
pub fn clients(pids: []const libc.pid_t) void {
var buf: [64]u8 = undefined;
var w: std.Io.Writer = .fixed(&buf);
- w.writeAll("clients") catch return;
- for (pids[0..@min(pids.len, max_clients)]) |pid| w.print(" {d}", .{pid}) catch return;
+ // "clients" and max_clients pids fit 64.
+ w.writeAll("clients") catch unreachable;
+ for (pids[0..@min(pids.len, max_clients)]) |pid| w.print(" {d}", .{pid}) catch unreachable;
tell(w.buffered(), &.{});
}