From 424b3930a299def62501afc7c2b9999fffc99a5c Mon Sep 17 00:00:00 2001 From: grialion <48643945+grialion@users.noreply.github.com> Date: Sat, 17 Jan 2026 17:12:16 +0100 Subject: [PATCH] fix(launch-state): replace last newline with nullbyte --- src/launch_state.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/launch_state.c b/src/launch_state.c index 8fdefbf..1abf71e 100644 --- a/src/launch_state.c +++ b/src/launch_state.c @@ -21,19 +21,17 @@ int read_launch_state(struct LaunchState* NNULLABLE state) { }; size_t num = 0; - if (getline(&state->username, &num, state_fd) < 0) goto fail; - // not sure I can actually prove it but ughh, getline < 0 will ensure there's - // something in the string and then I think strcspn is bounded to the final - // null byte, so it shouldn't go over - // NOLINTNEXTLINE(clang-analyzer-security.ArrayBound) - state->username[strcspn(state->username, "\n")] = 0; + ssize_t chars = getline(&state->username, &num, state_fd); + if (chars < 0) goto fail; + if (state->username[chars] == '\n') state->username[chars] = 0; num = 0; - if (getline(&state->session_opt, &num, state_fd) < 0) { + chars = getline(&state->session_opt, &num, state_fd); + if (chars < 0) { free(state->session_opt); goto fail; } - state->session_opt[strcspn(state->session_opt, "\n")] = 0; + if (state->session_opt[chars] == '\n') state->session_opt[chars] = 0; (void)fclose(state_fd); return 0;