diff options
-rw-r--r-- | common/ipc-client.c | 9 | ||||
-rw-r--r-- | common/pango.c | 12 | ||||
-rw-r--r-- | meson.build | 1 | ||||
-rw-r--r-- | sway/ipc-server.c | 12 | ||||
-rw-r--r-- | swaybar/ipc.c | 3 | ||||
-rw-r--r-- | swaynag/config.c | 3 | ||||
-rw-r--r-- | swaynag/swaynag.c | 3 |
7 files changed, 32 insertions, 11 deletions
diff --git a/common/ipc-client.c b/common/ipc-client.c index 3515ef0a..13fd8a05 100644 --- a/common/ipc-client.c +++ b/common/ipc-client.c | |||
@@ -61,7 +61,7 @@ int ipc_open_socket(const char *socket_path) { | |||
61 | } | 61 | } |
62 | 62 | ||
63 | struct ipc_response *ipc_recv_response(int socketfd) { | 63 | struct ipc_response *ipc_recv_response(int socketfd) { |
64 | char data[ipc_header_size]; | 64 | char *data = malloc(sizeof(char) * ipc_header_size); |
65 | uint32_t *data32 = (uint32_t *)(data + sizeof(ipc_magic)); | 65 | uint32_t *data32 = (uint32_t *)(data + sizeof(ipc_magic)); |
66 | 66 | ||
67 | size_t total = 0; | 67 | size_t total = 0; |
@@ -81,6 +81,8 @@ struct ipc_response *ipc_recv_response(int socketfd) { | |||
81 | total = 0; | 81 | total = 0; |
82 | memcpy(&response->size, &data32[0], sizeof(data32[0])); | 82 | memcpy(&response->size, &data32[0], sizeof(data32[0])); |
83 | memcpy(&response->type, &data32[1], sizeof(data32[1])); | 83 | memcpy(&response->type, &data32[1], sizeof(data32[1])); |
84 | free(data); | ||
85 | |||
84 | char *payload = malloc(response->size + 1); | 86 | char *payload = malloc(response->size + 1); |
85 | if (!payload) { | 87 | if (!payload) { |
86 | goto error_2; | 88 | goto error_2; |
@@ -99,6 +101,7 @@ struct ipc_response *ipc_recv_response(int socketfd) { | |||
99 | return response; | 101 | return response; |
100 | error_2: | 102 | error_2: |
101 | free(response); | 103 | free(response); |
104 | free(payload); | ||
102 | error_1: | 105 | error_1: |
103 | wlr_log(WLR_ERROR, "Unable to allocate memory for IPC response"); | 106 | wlr_log(WLR_ERROR, "Unable to allocate memory for IPC response"); |
104 | return NULL; | 107 | return NULL; |
@@ -110,7 +113,7 @@ void free_ipc_response(struct ipc_response *response) { | |||
110 | } | 113 | } |
111 | 114 | ||
112 | char *ipc_single_command(int socketfd, uint32_t type, const char *payload, uint32_t *len) { | 115 | char *ipc_single_command(int socketfd, uint32_t type, const char *payload, uint32_t *len) { |
113 | char data[ipc_header_size]; | 116 | char *data = malloc(sizeof(char) * ipc_header_size); |
114 | uint32_t *data32 = (uint32_t *)(data + sizeof(ipc_magic)); | 117 | uint32_t *data32 = (uint32_t *)(data + sizeof(ipc_magic)); |
115 | memcpy(data, ipc_magic, sizeof(ipc_magic)); | 118 | memcpy(data, ipc_magic, sizeof(ipc_magic)); |
116 | memcpy(&data32[0], len, sizeof(*len)); | 119 | memcpy(&data32[0], len, sizeof(*len)); |
@@ -120,6 +123,8 @@ char *ipc_single_command(int socketfd, uint32_t type, const char *payload, uint3 | |||
120 | sway_abort("Unable to send IPC header"); | 123 | sway_abort("Unable to send IPC header"); |
121 | } | 124 | } |
122 | 125 | ||
126 | free(data); | ||
127 | |||
123 | if (write(socketfd, payload, *len) == -1) { | 128 | if (write(socketfd, payload, *len) == -1) { |
124 | sway_abort("Unable to send IPC payload"); | 129 | sway_abort("Unable to send IPC payload"); |
125 | } | 130 | } |
diff --git a/common/pango.c b/common/pango.c index 3bc97808..18b92e9d 100644 --- a/common/pango.c +++ b/common/pango.c | |||
@@ -87,11 +87,11 @@ PangoLayout *get_pango_layout(cairo_t *cairo, const char *font, | |||
87 | 87 | ||
88 | void get_text_size(cairo_t *cairo, const char *font, int *width, int *height, | 88 | void get_text_size(cairo_t *cairo, const char *font, int *width, int *height, |
89 | int *baseline, double scale, bool markup, const char *fmt, ...) { | 89 | int *baseline, double scale, bool markup, const char *fmt, ...) { |
90 | char buf[max_chars]; | 90 | char *buf = malloc(sizeof(char) * max_chars); |
91 | 91 | ||
92 | va_list args; | 92 | va_list args; |
93 | va_start(args, fmt); | 93 | va_start(args, fmt); |
94 | if (vsnprintf(buf, sizeof(buf), fmt, args) >= max_chars) { | 94 | if (vsnprintf(buf, sizeof(char) * max_chars, fmt, args) >= max_chars) { |
95 | strcpy(&buf[sizeof(buf) - sizeof(overflow)], overflow); | 95 | strcpy(&buf[sizeof(buf) - sizeof(overflow)], overflow); |
96 | } | 96 | } |
97 | va_end(args); | 97 | va_end(args); |
@@ -103,15 +103,17 @@ void get_text_size(cairo_t *cairo, const char *font, int *width, int *height, | |||
103 | *baseline = pango_layout_get_baseline(layout) / PANGO_SCALE; | 103 | *baseline = pango_layout_get_baseline(layout) / PANGO_SCALE; |
104 | } | 104 | } |
105 | g_object_unref(layout); | 105 | g_object_unref(layout); |
106 | |||
107 | free(buf); | ||
106 | } | 108 | } |
107 | 109 | ||
108 | void pango_printf(cairo_t *cairo, const char *font, | 110 | void pango_printf(cairo_t *cairo, const char *font, |
109 | double scale, bool markup, const char *fmt, ...) { | 111 | double scale, bool markup, const char *fmt, ...) { |
110 | char buf[max_chars]; | 112 | char *buf = malloc(sizeof(char) * max_chars); |
111 | 113 | ||
112 | va_list args; | 114 | va_list args; |
113 | va_start(args, fmt); | 115 | va_start(args, fmt); |
114 | if (vsnprintf(buf, sizeof(buf), fmt, args) >= max_chars) { | 116 | if (vsnprintf(buf, sizeof(char) * max_chars, fmt, args) >= max_chars) { |
115 | strcpy(&buf[sizeof(buf) - sizeof(overflow)], overflow); | 117 | strcpy(&buf[sizeof(buf) - sizeof(overflow)], overflow); |
116 | } | 118 | } |
117 | va_end(args); | 119 | va_end(args); |
@@ -124,4 +126,6 @@ void pango_printf(cairo_t *cairo, const char *font, | |||
124 | pango_cairo_update_layout(cairo, layout); | 126 | pango_cairo_update_layout(cairo, layout); |
125 | pango_cairo_show_layout(cairo, layout); | 127 | pango_cairo_show_layout(cairo, layout); |
126 | g_object_unref(layout); | 128 | g_object_unref(layout); |
129 | |||
130 | free(buf); | ||
127 | } | 131 | } |
diff --git a/meson.build b/meson.build index 520a87ad..2285cbdf 100644 --- a/meson.build +++ b/meson.build | |||
@@ -17,6 +17,7 @@ add_project_arguments( | |||
17 | '-Wno-unused-parameter', | 17 | '-Wno-unused-parameter', |
18 | '-Wno-unused-result', | 18 | '-Wno-unused-result', |
19 | '-Wundef', | 19 | '-Wundef', |
20 | '-Wvla', | ||
20 | ], | 21 | ], |
21 | language: 'c', | 22 | language: 'c', |
22 | ) | 23 | ) |
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: | |||
860 | bool ipc_send_reply(struct ipc_client *client, const char *payload, uint32_t payload_length) { | 864 | bool 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, |
diff --git a/swaybar/ipc.c b/swaybar/ipc.c index 0dc39439..9fe3e626 100644 --- a/swaybar/ipc.c +++ b/swaybar/ipc.c | |||
@@ -13,9 +13,10 @@ | |||
13 | void ipc_send_workspace_command(struct swaybar *bar, const char *ws) { | 13 | void ipc_send_workspace_command(struct swaybar *bar, const char *ws) { |
14 | const char *fmt = "workspace \"%s\""; | 14 | const char *fmt = "workspace \"%s\""; |
15 | uint32_t size = snprintf(NULL, 0, fmt, ws); | 15 | uint32_t size = snprintf(NULL, 0, fmt, ws); |
16 | char command[size]; | 16 | char *command = malloc(sizeof(char) * size); |
17 | snprintf(command, size, fmt, ws); | 17 | snprintf(command, size, fmt, ws); |
18 | ipc_single_command(bar->ipc_socketfd, IPC_COMMAND, command, &size); | 18 | ipc_single_command(bar->ipc_socketfd, IPC_COMMAND, command, &size); |
19 | free(command); | ||
19 | } | 20 | } |
20 | 21 | ||
21 | char *parse_font(const char *font) { | 22 | char *parse_font(const char *font) { |
diff --git a/swaynag/config.c b/swaynag/config.c index 60bda3e0..b4c22443 100644 --- a/swaynag/config.c +++ b/swaynag/config.c | |||
@@ -365,11 +365,12 @@ int swaynag_load_config(char *path, struct swaynag *swaynag, list_t *types) { | |||
365 | } | 365 | } |
366 | free(name); | 366 | free(name); |
367 | } else { | 367 | } else { |
368 | char flag[nread + 3]; | 368 | char *flag = malloc(sizeof(char) * (nread + 3)); |
369 | sprintf(flag, "--%s", line); | 369 | sprintf(flag, "--%s", line); |
370 | char *argv[] = {"swaynag", flag}; | 370 | char *argv[] = {"swaynag", flag}; |
371 | result = swaynag_parse_options(2, argv, swaynag, types, type, | 371 | result = swaynag_parse_options(2, argv, swaynag, types, type, |
372 | NULL, NULL); | 372 | NULL, NULL); |
373 | free(flag); | ||
373 | if (result != 0) { | 374 | if (result != 0) { |
374 | break; | 375 | break; |
375 | } | 376 | } |
diff --git a/swaynag/swaynag.c b/swaynag/swaynag.c index 674c24b5..ceb795a8 100644 --- a/swaynag/swaynag.c +++ b/swaynag/swaynag.c | |||
@@ -28,9 +28,10 @@ static bool terminal_execute(char *terminal, char *command) { | |||
28 | fprintf(tmp, "#!/bin/sh\nrm %s\n%s", fname, command); | 28 | fprintf(tmp, "#!/bin/sh\nrm %s\n%s", fname, command); |
29 | fclose(tmp); | 29 | fclose(tmp); |
30 | chmod(fname, S_IRUSR | S_IWUSR | S_IXUSR); | 30 | chmod(fname, S_IRUSR | S_IWUSR | S_IXUSR); |
31 | char cmd[strlen(terminal) + strlen(" -e ") + strlen(fname) + 1]; | 31 | char *cmd = malloc(sizeof(char) * (strlen(terminal) + strlen(" -e ") + strlen(fname) + 1)); |
32 | sprintf(cmd, "%s -e %s", terminal, fname); | 32 | sprintf(cmd, "%s -e %s", terminal, fname); |
33 | execl("/bin/sh", "/bin/sh", "-c", cmd, NULL); | 33 | execl("/bin/sh", "/bin/sh", "-c", cmd, NULL); |
34 | free(cmd); | ||
34 | return true; | 35 | return true; |
35 | } | 36 | } |
36 | 37 | ||