Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/services/crash-handler/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down
24 changes: 19 additions & 5 deletions src/services/power-helper/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}
Expand All @@ -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;
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/wayland/ime.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down