From dafda13099352b79182e5bd947707d86fc06e696 Mon Sep 17 00:00:00 2001 From: Jason Perlow Date: Thu, 26 Nov 2026 20:45:59 -0500 Subject: [PATCH 1/3] crash-handler: validate numeric arguments and bound allocations Assisted-by: codex:gpt-6-luna AI-Scope: Generated the range checks on the numeric arguments and the allocation growth guard from a list of static-analysis sites; reviewed by a human before submission. --- src/services/crash-handler/main.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/services/crash-handler/main.c b/src/services/crash-handler/main.c index aec13da2..6c52558f 100644 --- a/src/services/crash-handler/main.c +++ b/src/services/crash-handler/main.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -127,7 +128,7 @@ load_config(struct config *cfg) if (cfg->max_cores < 0) { cfg->max_cores = 0; } - if (cfg->max_core_mb < 0) { + if (cfg->max_core_mb < 0 || cfg->max_core_mb > LONG_MAX / (1024L * 1024L)) { cfg->max_core_mb = 0; } } @@ -310,6 +311,9 @@ prune(int dir, const char *suffix, long keep) continue; } if (count == cap) { + if (cap > SIZE_MAX / 2 / sizeof(*list)) { + break; + } size_t ncap = cap ? cap * 2 : 32; struct entry *grown = realloc(list, ncap * sizeof(*list)); if (!grown) { @@ -442,7 +446,8 @@ main(int argc, char **argv) long pid, uid_l, gid_l, sig, when, dumpable; if (parse_long(argv[1], &pid) < 0 || parse_long(argv[2], &uid_l) < 0 || parse_long(argv[3], &gid_l) < 0 || parse_long(argv[4], &sig) < 0 || parse_long(argv[5], &when) < 0 || - parse_long(argv[6], &dumpable) < 0 || pid <= 0 || uid_l < 0 || gid_l < 0) { + parse_long(argv[6], &dumpable) < 0 || pid <= 0 || uid_l < 0 || gid_l < 0 || when < 0 || + (uintmax_t)uid_l > (uintmax_t)(uid_t)-1 || (uintmax_t)gid_l > (uintmax_t)(gid_t)-1) { fprintf(stderr, "singularity-crash-handler: invalid arguments\n"); return 2; } From f2076d41e3d57e7a438830a3339fae2c74366b8e Mon Sep 17 00:00:00 2001 From: Jason Perlow Date: Thu, 26 Nov 2026 20:45:59 -0500 Subject: [PATCH 2/3] power-helper: check path lengths and numeric input Assisted-by: codex:gpt-6-luna AI-Scope: Generated the path-length and strtol error checks from a list of static-analysis sites; reviewed by a human before submission. --- src/services/power-helper/main.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/services/power-helper/main.c b/src/services/power-helper/main.c index 564d6279..b6e5e12f 100644 --- a/src/services/power-helper/main.c +++ b/src/services/power-helper/main.c @@ -40,7 +40,9 @@ static int read_attr(const char *dir, const char *attr, char *buf, size_t size) { char path[512]; - snprintf(path, sizeof(path), "%s/%s", dir, attr); + if (size < 2 || snprintf(path, sizeof(path), "%s/%s", dir, attr) >= (int)sizeof(path)) { + return -1; + } int fd = open(path, O_RDONLY | O_CLOEXEC | O_NOFOLLOW); if (fd < 0) { return -1; @@ -62,7 +64,9 @@ write_attr(const char *dir, const char *attr, int value) { char path[512]; char text[16]; - snprintf(path, sizeof(path), "%s/%s", dir, attr); + if (snprintf(path, sizeof(path), "%s/%s", dir, attr) >= (int)sizeof(path)) { + return -1; + } int fd = open(path, O_WRONLY | O_CLOEXEC | O_NOFOLLOW | O_TRUNC); if (fd < 0) { return -1; @@ -79,8 +83,9 @@ static int charge_limit(const char *battery, const char *percent_text) { char *end = NULL; + errno = 0; long percent = strtol(percent_text, &end, 10); - if (!end || *end != '\0' || percent < 50 || percent > 100) { + if (errno != 0 || end == percent_text || !end || *end != '\0' || percent < 50 || percent > 100) { fprintf(stderr, "The charge limit must be between 50 and 100\n"); return 2; } @@ -90,7 +95,10 @@ charge_limit(const char *battery, const char *percent_text) } char dir[384]; char buf[64]; - snprintf(dir, sizeof(dir), "%s/%s", sysfs_root(), battery); + if (snprintf(dir, sizeof(dir), "%s/%s", sysfs_root(), battery) >= (int)sizeof(dir)) { + fprintf(stderr, "Battery path is too long\n"); + return 2; + } if (read_attr(dir, "type", buf, sizeof(buf)) != 0 || strcmp(buf, "Battery") != 0) { fprintf(stderr, "%s is not a battery\n", battery); return 2; @@ -100,7 +108,13 @@ charge_limit(const char *battery, const char *percent_text) return 3; } if (read_attr(dir, "charge_control_start_threshold", buf, sizeof(buf)) == 0) { - long start = strtol(buf, NULL, 10); + char *end = NULL; + errno = 0; + long start = strtol(buf, &end, 10); + if (errno != 0 || end == buf || *end != '\0') { + fprintf(stderr, "Invalid charge start threshold\n"); + return 2; + } if (start >= percent && write_attr(dir, "charge_control_start_threshold", (int)percent - 5) != 0) { fprintf(stderr, "Cannot lower the charge start threshold: %s\n", strerror(errno)); return 4; From 07ab4796680d889086b19b496b4e98e01b7ee5e2 Mon Sep 17 00:00:00 2001 From: Jason Perlow Date: Thu, 26 Nov 2026 20:45:59 -0500 Subject: [PATCH 3/3] ime: validate popup buffer dimensions Assisted-by: codex:gpt-6-luna AI-Scope: Generated the stride and size bounds check from a list of static-analysis sites; reviewed by a human before submission. --- src/wayland/ime.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wayland/ime.c b/src/wayland/ime.c index 98cc4e62..05e44113 100644 --- a/src/wayland/ime.c +++ b/src/wayland/ime.c @@ -443,7 +443,8 @@ static void buffer_release(void *data, struct wl_buffer *buffer) { static const struct wl_buffer_listener buffer_listener = { buffer_release }; void singularity_ime_popup_show(const guint8 *pixels, int width, int height, int stride, int scale) { - if (input_method == NULL || pixels == NULL || width <= 0 || height <= 0) return; + if (input_method == NULL || pixels == NULL || width <= 0 || height <= 0 || stride <= 0 || + width > INT32_MAX / 4 || stride < width * 4 || height > INT32_MAX / stride) return; if (popup_surface == NULL) { popup_surface = wl_compositor_create_surface(compositor); popup = zwp_input_method_v2_get_input_popup_surface(input_method, popup_surface);