aboutsummaryrefslogtreecommitdiff
path: root/sway/ipc-server.c
diff options
context:
space:
mode:
authorConnor E <38229097+c-edw@users.noreply.github.com>2019-01-16 01:57:53 +0000
committeremersion <contact@emersion.fr>2019-01-16 13:02:26 +0100
commitaa9d7d8ca19f4489839f765ad7f190e8141bd001 (patch)
treea00776437e012fb3f800b60c0bb7c25fdbf261b2 /sway/ipc-server.c
parent02bbefda20b9a4f86e740d33bbaa21c661bb2fac (diff)
Remove usage of VLAs.
Diffstat (limited to 'sway/ipc-server.c')
-rw-r--r--sway/ipc-server.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/sway/ipc-server.c b/sway/ipc-server.c
index ff1bc89f..73fa8ae5 100644
--- a/sway/ipc-server.c
+++ b/sway/ipc-server.c
@@ -234,25 +234,29 @@ int ipc_client_handle_readable(int client_fd, uint32_t mask, void *data) {
return 0;
}
- uint8_t buf[ipc_header_size];
+ uint8_t *buf = malloc(sizeof(uint8_t) * ipc_header_size);
uint32_t *buf32 = (uint32_t*)(buf + sizeof(ipc_magic));
// Should be fully available, because read_available >= ipc_header_size
ssize_t received = recv(client_fd, buf, ipc_header_size, 0);
if (received == -1) {
wlr_log_errno(WLR_INFO, "Unable to receive header from IPC client");
ipc_client_disconnect(client);
+ free(buf);
return 0;
}
if (memcmp(buf, ipc_magic, sizeof(ipc_magic)) != 0) {
wlr_log(WLR_DEBUG, "IPC header check failed");
ipc_client_disconnect(client);
+ free(buf);
return 0;
}
memcpy(&client->payload_length, &buf32[0], sizeof(buf32[0]));
memcpy(&client->current_command, &buf32[1], sizeof(buf32[1]));
+ free(buf);
+
if (read_available - received >= (long)client->payload_length) {
ipc_client_handle_command(client);
}
@@ -860,7 +864,7 @@ exit_cleanup:
bool ipc_send_reply(struct ipc_client *client, const char *payload, uint32_t payload_length) {
assert(payload);
- char data[ipc_header_size];
+ char *data = malloc(sizeof(char) * ipc_header_size);
uint32_t *data32 = (uint32_t*)(data + sizeof(ipc_magic));
memcpy(data, ipc_magic, sizeof(ipc_magic));
@@ -875,6 +879,7 @@ bool ipc_send_reply(struct ipc_client *client, const char *payload, uint32_t pay
if (client->write_buffer_size > 4e6) { // 4 MB
wlr_log(WLR_ERROR, "Client write buffer too big, disconnecting client");
ipc_client_disconnect(client);
+ free(data);
return false;
}
@@ -882,6 +887,7 @@ bool ipc_send_reply(struct ipc_client *client, const char *payload, uint32_t pay
if (!new_buffer) {
wlr_log(WLR_ERROR, "Unable to reallocate ipc client write buffer");
ipc_client_disconnect(client);
+ free(data);
return false;
}
client->write_buffer = new_buffer;
@@ -891,6 +897,8 @@ bool ipc_send_reply(struct ipc_client *client, const char *payload, uint32_t pay
memcpy(client->write_buffer + client->write_buffer_len, payload, payload_length);
client->write_buffer_len += payload_length;
+ free(data);
+
if (!client->writable_event_source) {
client->writable_event_source = wl_event_loop_add_fd(
server.wl_event_loop, client->fd, WL_EVENT_WRITABLE,