diff options
author | taiyu <taiyu.len@gmail.com> | 2018-09-02 17:07:12 -0700 |
---|---|---|
committer | taiyu <taiyu.len@gmail.com> | 2018-09-02 17:07:12 -0700 |
commit | d625d68d4a64ccf277663b26c52f4ca51d494e6a (patch) | |
tree | c7ede86177a4ccdaffc9e8cc52b8d0827674b9fb /common | |
parent | Merge pull request #2544 from RyanDwyer/fix-deferred-cmd-crash (diff) | |
download | sway-d625d68d4a64ccf277663b26c52f4ca51d494e6a.tar.gz sway-d625d68d4a64ccf277663b26c52f4ca51d494e6a.tar.zst sway-d625d68d4a64ccf277663b26c52f4ca51d494e6a.zip |
prevent ub caused by misaligned stores/loads
Diffstat (limited to 'common')
-rw-r--r-- | common/ipc-client.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/common/ipc-client.c b/common/ipc-client.c index 24a2f9c2..496fd131 100644 --- a/common/ipc-client.c +++ b/common/ipc-client.c | |||
@@ -78,8 +78,8 @@ struct ipc_response *ipc_recv_response(int socketfd) { | |||
78 | } | 78 | } |
79 | 79 | ||
80 | total = 0; | 80 | total = 0; |
81 | response->size = data32[0]; | 81 | memcpy(&response->size, &data32[0], sizeof(data32[0])); |
82 | response->type = data32[1]; | 82 | memcpy(&response->type, &data32[1], sizeof(data32[1])); |
83 | char *payload = malloc(response->size + 1); | 83 | char *payload = malloc(response->size + 1); |
84 | if (!payload) { | 84 | if (!payload) { |
85 | goto error_2; | 85 | goto error_2; |
@@ -112,8 +112,8 @@ char *ipc_single_command(int socketfd, uint32_t type, const char *payload, uint3 | |||
112 | char data[ipc_header_size]; | 112 | char data[ipc_header_size]; |
113 | uint32_t *data32 = (uint32_t *)(data + sizeof(ipc_magic)); | 113 | uint32_t *data32 = (uint32_t *)(data + sizeof(ipc_magic)); |
114 | memcpy(data, ipc_magic, sizeof(ipc_magic)); | 114 | memcpy(data, ipc_magic, sizeof(ipc_magic)); |
115 | data32[0] = *len; | 115 | memcpy(&data32[0], len, sizeof(*len)); |
116 | data32[1] = type; | 116 | memcpy(&data32[1], &type, sizeof(type)); |
117 | 117 | ||
118 | if (write(socketfd, data, ipc_header_size) == -1) { | 118 | if (write(socketfd, data, ipc_header_size) == -1) { |
119 | sway_abort("Unable to send IPC header"); | 119 | sway_abort("Unable to send IPC header"); |