aboutsummaryrefslogtreecommitdiffstats
path: root/sway/ipc-server.c
diff options
context:
space:
mode:
authorLibravatar Connor E <38229097+c-edw@users.noreply.github.com>2019-01-16 01:57:53 +0000
committerLibravatar emersion <contact@emersion.fr>2019-01-16 13:02:26 +0100
commitaa9d7d8ca19f4489839f765ad7f190e8141bd001 (patch)
treea00776437e012fb3f800b60c0bb7c25fdbf261b2 /sway/ipc-server.c
parentbar_cmd_tray_bind: Use mouse button helpers (diff)
downloadsway-aa9d7d8ca19f4489839f765ad7f190e8141bd001.tar.gz
sway-aa9d7d8ca19f4489839f765ad7f190e8141bd001.tar.zst
sway-aa9d7d8ca19f4489839f765ad7f190e8141bd001.zip
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) {
234 return 0; 234 return 0;
235 } 235 }
236 236
237 uint8_t buf[ipc_header_size]; 237 uint8_t *buf = malloc(sizeof(uint8_t) * ipc_header_size);
238 uint32_t *buf32 = (uint32_t*)(buf + sizeof(ipc_magic)); 238 uint32_t *buf32 = (uint32_t*)(buf + sizeof(ipc_magic));
239 // Should be fully available, because read_available >= ipc_header_size 239 // Should be fully available, because read_available >= ipc_header_size
240 ssize_t received = recv(client_fd, buf, ipc_header_size, 0); 240 ssize_t received = recv(client_fd, buf, ipc_header_size, 0);
241 if (received == -1) { 241 if (received == -1) {
242 wlr_log_errno(WLR_INFO, "Unable to receive header from IPC client"); 242 wlr_log_errno(WLR_INFO, "Unable to receive header from IPC client");
243 ipc_client_disconnect(client); 243 ipc_client_disconnect(client);
244 free(buf);
244 return 0; 245 return 0;
245 } 246 }
246 247
247 if (memcmp(buf, ipc_magic, sizeof(ipc_magic)) != 0) { 248 if (memcmp(buf, ipc_magic, sizeof(ipc_magic)) != 0) {
248 wlr_log(WLR_DEBUG, "IPC header check failed"); 249 wlr_log(WLR_DEBUG, "IPC header check failed");
249 ipc_client_disconnect(client); 250 ipc_client_disconnect(client);
251 free(buf);
250 return 0; 252 return 0;
251 } 253 }
252 254
253 memcpy(&client->payload_length, &buf32[0], sizeof(buf32[0])); 255 memcpy(&client->payload_length, &buf32[0], sizeof(buf32[0]));
254 memcpy(&client->current_command, &buf32[1], sizeof(buf32[1])); 256 memcpy(&client->current_command, &buf32[1], sizeof(buf32[1]));
255 257
258 free(buf);
259
256 if (read_available - received >= (long)client->payload_length) { 260 if (read_available - received >= (long)client->payload_length) {
257 ipc_client_handle_command(client); 261 ipc_client_handle_command(client);
258 } 262 }
@@ -860,7 +864,7 @@ exit_cleanup:
860bool ipc_send_reply(struct ipc_client *client, const char *payload, uint32_t payload_length) { 864bool ipc_send_reply(struct ipc_client *client, const char *payload, uint32_t payload_length) {
861 assert(payload); 865 assert(payload);
862 866
863 char data[ipc_header_size]; 867 char *data = malloc(sizeof(char) * ipc_header_size);
864 uint32_t *data32 = (uint32_t*)(data + sizeof(ipc_magic)); 868 uint32_t *data32 = (uint32_t*)(data + sizeof(ipc_magic));
865 869
866 memcpy(data, ipc_magic, sizeof(ipc_magic)); 870 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
875 if (client->write_buffer_size > 4e6) { // 4 MB 879 if (client->write_buffer_size > 4e6) { // 4 MB
876 wlr_log(WLR_ERROR, "Client write buffer too big, disconnecting client"); 880 wlr_log(WLR_ERROR, "Client write buffer too big, disconnecting client");
877 ipc_client_disconnect(client); 881 ipc_client_disconnect(client);
882 free(data);
878 return false; 883 return false;
879 } 884 }
880 885
@@ -882,6 +887,7 @@ bool ipc_send_reply(struct ipc_client *client, const char *payload, uint32_t pay
882 if (!new_buffer) { 887 if (!new_buffer) {
883 wlr_log(WLR_ERROR, "Unable to reallocate ipc client write buffer"); 888 wlr_log(WLR_ERROR, "Unable to reallocate ipc client write buffer");
884 ipc_client_disconnect(client); 889 ipc_client_disconnect(client);
890 free(data);
885 return false; 891 return false;
886 } 892 }
887 client->write_buffer = new_buffer; 893 client->write_buffer = new_buffer;
@@ -891,6 +897,8 @@ bool ipc_send_reply(struct ipc_client *client, const char *payload, uint32_t pay
891 memcpy(client->write_buffer + client->write_buffer_len, payload, payload_length); 897 memcpy(client->write_buffer + client->write_buffer_len, payload, payload_length);
892 client->write_buffer_len += payload_length; 898 client->write_buffer_len += payload_length;
893 899
900 free(data);
901
894 if (!client->writable_event_source) { 902 if (!client->writable_event_source) {
895 client->writable_event_source = wl_event_loop_add_fd( 903 client->writable_event_source = wl_event_loop_add_fd(
896 server.wl_event_loop, client->fd, WL_EVENT_WRITABLE, 904 server.wl_event_loop, client->fd, WL_EVENT_WRITABLE,