aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorLibravatar Antonin Décimo <antonin.decimo@gmail.com>2020-06-04 13:00:45 +0200
committerLibravatar Tudor Brindus <me@tbrindus.ca>2020-07-30 22:02:42 -0400
commit8033b575f7f83203371343457c102233b17cfd77 (patch)
tree84572b832802abff2b1ff80dffcbc55b54946579 /common
parentUse wlr_output_layout_output_at to get output for move to cursor (diff)
downloadsway-8033b575f7f83203371343457c102233b17cfd77.tar.gz
sway-8033b575f7f83203371343457c102233b17cfd77.tar.zst
sway-8033b575f7f83203371343457c102233b17cfd77.zip
ipc: fix aligment issue of data buffer
The pointer `data` is cast to a more strictly aligned pointer type. To prevent issues, the `data32` buffer is removed and its occurrences are replaced with an offset from the `data` buffer.
Diffstat (limited to 'common')
-rw-r--r--common/ipc-client.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/common/ipc-client.c b/common/ipc-client.c
index ec0454c9..d30212d2 100644
--- a/common/ipc-client.c
+++ b/common/ipc-client.c
@@ -79,7 +79,6 @@ bool ipc_set_recv_timeout(int socketfd, struct timeval tv) {
79 79
80struct ipc_response *ipc_recv_response(int socketfd) { 80struct ipc_response *ipc_recv_response(int socketfd) {
81 char data[IPC_HEADER_SIZE]; 81 char data[IPC_HEADER_SIZE];
82 uint32_t *data32 = (uint32_t *)(data + sizeof(ipc_magic));
83 82
84 size_t total = 0; 83 size_t total = 0;
85 while (total < IPC_HEADER_SIZE) { 84 while (total < IPC_HEADER_SIZE) {
@@ -95,15 +94,15 @@ struct ipc_response *ipc_recv_response(int socketfd) {
95 goto error_1; 94 goto error_1;
96 } 95 }
97 96
98 total = 0; 97 memcpy(&response->size, data + sizeof(ipc_magic), sizeof(uint32_t));
99 memcpy(&response->size, &data32[0], sizeof(data32[0])); 98 memcpy(&response->type, data + sizeof(ipc_magic) + sizeof(uint32_t), sizeof(uint32_t));
100 memcpy(&response->type, &data32[1], sizeof(data32[1]));
101 99
102 char *payload = malloc(response->size + 1); 100 char *payload = malloc(response->size + 1);
103 if (!payload) { 101 if (!payload) {
104 goto error_2; 102 goto error_2;
105 } 103 }
106 104
105 total = 0;
107 while (total < response->size) { 106 while (total < response->size) {
108 ssize_t received = recv(socketfd, payload + total, response->size - total, 0); 107 ssize_t received = recv(socketfd, payload + total, response->size - total, 0);
109 if (received < 0) { 108 if (received < 0) {
@@ -129,10 +128,9 @@ void free_ipc_response(struct ipc_response *response) {
129 128
130char *ipc_single_command(int socketfd, uint32_t type, const char *payload, uint32_t *len) { 129char *ipc_single_command(int socketfd, uint32_t type, const char *payload, uint32_t *len) {
131 char data[IPC_HEADER_SIZE]; 130 char data[IPC_HEADER_SIZE];
132 uint32_t *data32 = (uint32_t *)(data + sizeof(ipc_magic));
133 memcpy(data, ipc_magic, sizeof(ipc_magic)); 131 memcpy(data, ipc_magic, sizeof(ipc_magic));
134 memcpy(&data32[0], len, sizeof(*len)); 132 memcpy(data + sizeof(ipc_magic), len, sizeof(*len));
135 memcpy(&data32[1], &type, sizeof(type)); 133 memcpy(data + sizeof(ipc_magic) + sizeof(*len), &type, sizeof(type));
136 134
137 if (write(socketfd, data, IPC_HEADER_SIZE) == -1) { 135 if (write(socketfd, data, IPC_HEADER_SIZE) == -1) {
138 sway_abort("Unable to send IPC header"); 136 sway_abort("Unable to send IPC header");