From d3f0a2456924e7c95528d4e609e7af457b71d0cd Mon Sep 17 00:00:00 2001 From: Nathan Patrizi Date: Tue, 27 Jan 2026 22:09:17 +0000 Subject: [PATCH] strace: Fix handling of statMask when building stat string MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix a crash caused by decoding stat arguments when the statMask is only B_STAT_MODE or all 0. Change-Id: Ic57c5494fbf4d20605955d3cc4c21f96e380fab1 Reviewed-on: https://review.haiku-os.org/c/haiku/+/10283 Reviewed-by: waddlesplash Haiku-Format: Haiku-format Bot Tested-by: Commit checker robot Reviewed-by: Jérôme Duval --- src/bin/debug/strace/file.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/bin/debug/strace/file.cpp b/src/bin/debug/strace/file.cpp index 251b5d194d..ce6cb4db47 100644 --- a/src/bin/debug/strace/file.cpp +++ b/src/bin/debug/strace/file.cpp @@ -64,15 +64,18 @@ read_stat(Context &context, Parameter *param, void *data) string r; if ((statMask & 0xffffffff) == 0xffffffff) { - char mode[12]; r += ", st_dev = " + format_unsigned(s.st_dev); r += ", st_ino = " + format_unsigned(s.st_ino); + } + if ((statMask & B_STAT_MODE) != 0) { + char mode[12]; snprintf(mode, sizeof(mode), "%03" B_PRIo32, (uint32)(s.st_mode & ~(S_IFMT | S_ISUID | S_ISGID | S_ISVTX))); r += ", st_mode = " + format_mode(context, s.st_mode & S_IFMT) + "|"; r += mode; - r += ", st_nlink = " + format_unsigned(s.st_nlink); } + if ((statMask & 0xffffffff) == 0xffffffff) + r += ", st_nlink = " + format_unsigned(s.st_nlink); if ((statMask & B_STAT_UID) != 0) r += ", st_uid = " + format_unsigned(s.st_uid); if ((statMask & B_STAT_GID) != 0) @@ -93,6 +96,10 @@ read_stat(Context &context, Parameter *param, void *data) r += ", st_type = " + format_unsigned(s.st_type); r += ", st_blocks = " + format_unsigned(s.st_blocks); } + + if (r.size() == 0) + return "{}"; + return "{" + r.substr(2) + "}"; }