invoke_swaybar: fix message length header size

size_t/ssize_t are 8 bytes on 64bit systems, so use the proper size to
transmit that information.
This could lead to ridiculously large alloc as len is not initialized to zero

Found through static analysis
master
Dominique Martinet 6 years ago
parent 1b7f554474
commit 9c8fb7d025

@ -174,7 +174,7 @@ void invoke_swaybar(struct bar_config *bar) {
if (!command) { if (!command) {
const char msg[] = "Unable to allocate swaybar command string"; const char msg[] = "Unable to allocate swaybar command string";
size_t msg_len = sizeof(msg); size_t msg_len = sizeof(msg);
if (write(filedes[1], &msg_len, sizeof(int))) {}; if (write(filedes[1], &msg_len, sizeof(size_t))) {};
if (write(filedes[1], msg, msg_len)) {}; if (write(filedes[1], msg, msg_len)) {};
close(filedes[1]); close(filedes[1]);
exit(1); exit(1);
@ -189,8 +189,8 @@ void invoke_swaybar(struct bar_config *bar) {
} }
wlr_log(L_DEBUG, "Spawned swaybar %d", bar->pid); wlr_log(L_DEBUG, "Spawned swaybar %d", bar->pid);
close(filedes[0]); close(filedes[0]);
ssize_t len; size_t len;
if (read(filedes[1], &len, sizeof(int)) == sizeof(int)) { if (read(filedes[1], &len, sizeof(size_t)) == sizeof(size_t)) {
char *buf = malloc(len); char *buf = malloc(len);
if(!buf) { if(!buf) {
wlr_log(L_ERROR, "Cannot allocate error string"); wlr_log(L_ERROR, "Cannot allocate error string");

Loading…
Cancel
Save