File: | build-scan/../src/libsystemd/sd-bus/bus-internal.c |
Warning: | line 326, column 32 Use of zero-allocated memory |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* SPDX-License-Identifier: LGPL-2.1+ */ | |||
2 | /*** | |||
3 | ***/ | |||
4 | ||||
5 | #include "alloc-util.h" | |||
6 | #include "bus-internal.h" | |||
7 | #include "bus-message.h" | |||
8 | #include "hexdecoct.h" | |||
9 | #include "string-util.h" | |||
10 | ||||
11 | bool_Bool object_path_is_valid(const char *p) { | |||
12 | const char *q; | |||
13 | bool_Bool slash; | |||
14 | ||||
15 | if (!p) | |||
16 | return false0; | |||
17 | ||||
18 | if (p[0] != '/') | |||
19 | return false0; | |||
20 | ||||
21 | if (p[1] == 0) | |||
22 | return true1; | |||
23 | ||||
24 | for (slash = true1, q = p+1; *q; q++) | |||
25 | if (*q == '/') { | |||
26 | if (slash) | |||
27 | return false0; | |||
28 | ||||
29 | slash = true1; | |||
30 | } else { | |||
31 | bool_Bool good; | |||
32 | ||||
33 | good = | |||
34 | (*q >= 'a' && *q <= 'z') || | |||
35 | (*q >= 'A' && *q <= 'Z') || | |||
36 | (*q >= '0' && *q <= '9') || | |||
37 | *q == '_'; | |||
38 | ||||
39 | if (!good) | |||
40 | return false0; | |||
41 | ||||
42 | slash = false0; | |||
43 | } | |||
44 | ||||
45 | if (slash) | |||
46 | return false0; | |||
47 | ||||
48 | return (q - p) <= BUS_PATH_SIZE_MAX(64*1024); | |||
49 | } | |||
50 | ||||
51 | char* object_path_startswith(const char *a, const char *b) { | |||
52 | const char *p; | |||
53 | ||||
54 | if (!object_path_is_valid(a) || | |||
55 | !object_path_is_valid(b)) | |||
56 | return NULL((void*)0); | |||
57 | ||||
58 | if (streq(b, "/")(strcmp((b),("/")) == 0)) | |||
59 | return (char*) a + 1; | |||
60 | ||||
61 | p = startswith(a, b); | |||
62 | if (!p) | |||
63 | return NULL((void*)0); | |||
64 | ||||
65 | if (*p == 0) | |||
66 | return (char*) p; | |||
67 | ||||
68 | if (*p == '/') | |||
69 | return (char*) p + 1; | |||
70 | ||||
71 | return NULL((void*)0); | |||
72 | } | |||
73 | ||||
74 | bool_Bool interface_name_is_valid(const char *p) { | |||
75 | const char *q; | |||
76 | bool_Bool dot, found_dot = false0; | |||
77 | ||||
78 | if (isempty(p)) | |||
79 | return false0; | |||
80 | ||||
81 | for (dot = true1, q = p; *q; q++) | |||
82 | if (*q == '.') { | |||
83 | if (dot) | |||
84 | return false0; | |||
85 | ||||
86 | found_dot = dot = true1; | |||
87 | } else { | |||
88 | bool_Bool good; | |||
89 | ||||
90 | good = | |||
91 | (*q >= 'a' && *q <= 'z') || | |||
92 | (*q >= 'A' && *q <= 'Z') || | |||
93 | (!dot && *q >= '0' && *q <= '9') || | |||
94 | *q == '_'; | |||
95 | ||||
96 | if (!good) | |||
97 | return false0; | |||
98 | ||||
99 | dot = false0; | |||
100 | } | |||
101 | ||||
102 | if (q - p > 255) | |||
103 | return false0; | |||
104 | ||||
105 | if (dot) | |||
106 | return false0; | |||
107 | ||||
108 | if (!found_dot) | |||
109 | return false0; | |||
110 | ||||
111 | return true1; | |||
112 | } | |||
113 | ||||
114 | bool_Bool service_name_is_valid(const char *p) { | |||
115 | const char *q; | |||
116 | bool_Bool dot, found_dot = false0, unique; | |||
117 | ||||
118 | if (isempty(p)) | |||
119 | return false0; | |||
120 | ||||
121 | unique = p[0] == ':'; | |||
122 | ||||
123 | for (dot = true1, q = unique ? p+1 : p; *q; q++) | |||
124 | if (*q == '.') { | |||
125 | if (dot) | |||
126 | return false0; | |||
127 | ||||
128 | found_dot = dot = true1; | |||
129 | } else { | |||
130 | bool_Bool good; | |||
131 | ||||
132 | good = | |||
133 | (*q >= 'a' && *q <= 'z') || | |||
134 | (*q >= 'A' && *q <= 'Z') || | |||
135 | ((!dot || unique) && *q >= '0' && *q <= '9') || | |||
136 | IN_SET(*q, '_', '-')({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended [20 - sizeof((int[]){'_', '-'})/sizeof(int)]; switch(*q) { case '_': case '-': _found = 1; break; default: break; } _found; } ); | |||
137 | ||||
138 | if (!good) | |||
139 | return false0; | |||
140 | ||||
141 | dot = false0; | |||
142 | } | |||
143 | ||||
144 | if (q - p > 255) | |||
145 | return false0; | |||
146 | ||||
147 | if (dot) | |||
148 | return false0; | |||
149 | ||||
150 | if (!found_dot) | |||
151 | return false0; | |||
152 | ||||
153 | return true1; | |||
154 | } | |||
155 | ||||
156 | char* service_name_startswith(const char *a, const char *b) { | |||
157 | const char *p; | |||
158 | ||||
159 | if (!service_name_is_valid(a) || | |||
160 | !service_name_is_valid(b)) | |||
161 | return NULL((void*)0); | |||
162 | ||||
163 | p = startswith(a, b); | |||
164 | if (!p) | |||
165 | return NULL((void*)0); | |||
166 | ||||
167 | if (*p == 0) | |||
168 | return (char*) p; | |||
169 | ||||
170 | if (*p == '.') | |||
171 | return (char*) p + 1; | |||
172 | ||||
173 | return NULL((void*)0); | |||
174 | } | |||
175 | ||||
176 | bool_Bool member_name_is_valid(const char *p) { | |||
177 | const char *q; | |||
178 | ||||
179 | if (isempty(p)) | |||
180 | return false0; | |||
181 | ||||
182 | for (q = p; *q; q++) { | |||
183 | bool_Bool good; | |||
184 | ||||
185 | good = | |||
186 | (*q >= 'a' && *q <= 'z') || | |||
187 | (*q >= 'A' && *q <= 'Z') || | |||
188 | (*q >= '0' && *q <= '9') || | |||
189 | *q == '_'; | |||
190 | ||||
191 | if (!good) | |||
192 | return false0; | |||
193 | } | |||
194 | ||||
195 | if (q - p > 255) | |||
196 | return false0; | |||
197 | ||||
198 | return true1; | |||
199 | } | |||
200 | ||||
201 | /* | |||
202 | * Complex pattern match | |||
203 | * This checks whether @a is a 'complex-prefix' of @b, or @b is a | |||
204 | * 'complex-prefix' of @a, based on strings that consist of labels with @c as | |||
205 | * spearator. This function returns true if: | |||
206 | * - both strings are equal | |||
207 | * - either is a prefix of the other and ends with @c | |||
208 | * The second rule makes sure that either string needs to be fully included in | |||
209 | * the other, and the string which is considered the prefix needs to end with a | |||
210 | * separator. | |||
211 | */ | |||
212 | static bool_Bool complex_pattern_check(char c, const char *a, const char *b) { | |||
213 | bool_Bool separator = false0; | |||
214 | ||||
215 | if (!a && !b) | |||
216 | return true1; | |||
217 | ||||
218 | if (!a || !b) | |||
219 | return false0; | |||
220 | ||||
221 | for (;;) { | |||
222 | if (*a != *b) | |||
223 | return (separator && (*a == 0 || *b == 0)); | |||
224 | ||||
225 | if (*a == 0) | |||
226 | return true1; | |||
227 | ||||
228 | separator = *a == c; | |||
229 | ||||
230 | a++, b++; | |||
231 | } | |||
232 | } | |||
233 | ||||
234 | bool_Bool namespace_complex_pattern(const char *pattern, const char *value) { | |||
235 | return complex_pattern_check('.', pattern, value); | |||
236 | } | |||
237 | ||||
238 | bool_Bool path_complex_pattern(const char *pattern, const char *value) { | |||
239 | return complex_pattern_check('/', pattern, value); | |||
240 | } | |||
241 | ||||
242 | /* | |||
243 | * Simple pattern match | |||
244 | * This checks whether @a is a 'simple-prefix' of @b, based on strings that | |||
245 | * consist of labels with @c as separator. This function returns true, if: | |||
246 | * - if @a and @b are equal | |||
247 | * - if @a is a prefix of @b, and the first following character in @b (or the | |||
248 | * last character in @a) is @c | |||
249 | * The second rule basically makes sure that if @a is a prefix of @b, then @b | |||
250 | * must follow with a new label separated by @c. It cannot extend the label. | |||
251 | */ | |||
252 | static bool_Bool simple_pattern_check(char c, const char *a, const char *b) { | |||
253 | bool_Bool separator = false0; | |||
254 | ||||
255 | if (!a && !b) | |||
256 | return true1; | |||
257 | ||||
258 | if (!a || !b) | |||
259 | return false0; | |||
260 | ||||
261 | for (;;) { | |||
262 | if (*a != *b) | |||
263 | return *a == 0 && (*b == c || separator); | |||
264 | ||||
265 | if (*a == 0) | |||
266 | return true1; | |||
267 | ||||
268 | separator = *a == c; | |||
269 | ||||
270 | a++, b++; | |||
271 | } | |||
272 | } | |||
273 | ||||
274 | bool_Bool namespace_simple_pattern(const char *pattern, const char *value) { | |||
275 | return simple_pattern_check('.', pattern, value); | |||
276 | } | |||
277 | ||||
278 | bool_Bool path_simple_pattern(const char *pattern, const char *value) { | |||
279 | return simple_pattern_check('/', pattern, value); | |||
280 | } | |||
281 | ||||
282 | int bus_message_type_from_string(const char *s, uint8_t *u) { | |||
283 | if (streq(s, "signal")(strcmp((s),("signal")) == 0)) | |||
284 | *u = SD_BUS_MESSAGE_SIGNAL; | |||
285 | else if (streq(s, "method_call")(strcmp((s),("method_call")) == 0)) | |||
286 | *u = SD_BUS_MESSAGE_METHOD_CALL; | |||
287 | else if (streq(s, "error")(strcmp((s),("error")) == 0)) | |||
288 | *u = SD_BUS_MESSAGE_METHOD_ERROR; | |||
289 | else if (streq(s, "method_return")(strcmp((s),("method_return")) == 0)) | |||
290 | *u = SD_BUS_MESSAGE_METHOD_RETURN; | |||
291 | else | |||
292 | return -EINVAL22; | |||
293 | ||||
294 | return 0; | |||
295 | } | |||
296 | ||||
297 | const char *bus_message_type_to_string(uint8_t u) { | |||
298 | if (u == SD_BUS_MESSAGE_SIGNAL) | |||
299 | return "signal"; | |||
300 | else if (u == SD_BUS_MESSAGE_METHOD_CALL) | |||
301 | return "method_call"; | |||
302 | else if (u == SD_BUS_MESSAGE_METHOD_ERROR) | |||
303 | return "error"; | |||
304 | else if (u == SD_BUS_MESSAGE_METHOD_RETURN) | |||
305 | return "method_return"; | |||
306 | else | |||
307 | return NULL((void*)0); | |||
308 | } | |||
309 | ||||
310 | char *bus_address_escape(const char *v) { | |||
311 | const char *a; | |||
312 | char *r, *b; | |||
313 | ||||
314 | r = new(char, strlen(v)*3+1)((char*) malloc_multiply(sizeof(char), (strlen(v)*3+1))); | |||
| ||||
315 | if (!r) | |||
316 | return NULL((void*)0); | |||
317 | ||||
318 | for (a = v, b = r; *a; a++) { | |||
319 | ||||
320 | if ((*a >= '0' && *a <= '9') || | |||
321 | (*a >= 'a' && *a <= 'z') || | |||
322 | (*a >= 'A' && *a <= 'Z') || | |||
323 | strchr("_-/.", *a)) | |||
324 | *(b++) = *a; | |||
325 | else { | |||
326 | *(b++) = '%'; | |||
| ||||
327 | *(b++) = hexchar(*a >> 4); | |||
328 | *(b++) = hexchar(*a & 0xF); | |||
329 | } | |||
330 | } | |||
331 | ||||
332 | *b = 0; | |||
333 | return r; | |||
334 | } | |||
335 | ||||
336 | int bus_maybe_reply_error(sd_bus_message *m, int r, sd_bus_error *error) { | |||
337 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/libsystemd/sd-bus/bus-internal.c" , 337, __PRETTY_FUNCTION__); } while (0); | |||
338 | ||||
339 | if (r < 0) { | |||
340 | if (m->header->type == SD_BUS_MESSAGE_METHOD_CALL) | |||
341 | sd_bus_reply_method_errno(m, r, error); | |||
342 | ||||
343 | } else if (sd_bus_error_is_set(error)) { | |||
344 | if (m->header->type == SD_BUS_MESSAGE_METHOD_CALL) | |||
345 | sd_bus_reply_method_error(m, error); | |||
346 | } else | |||
347 | return r; | |||
348 | ||||
349 | log_debug("Failed to process message type=%s sender=%s destination=%s path=%s interface=%s member=%s cookie=%" PRIu64 " reply_cookie=%" PRIu64 " signature=%s error-name=%s error-message=%s: %s",({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/libsystemd/sd-bus/bus-internal.c", 361, __func__, "Failed to process message type=%s sender=%s destination=%s path=%s interface=%s member=%s cookie=%" "l" "u" " reply_cookie=%" "l" "u" " signature=%s error-name=%s error-message=%s: %s" , bus_message_type_to_string(m->header->type), strna(sd_bus_message_get_sender (m)), strna(sd_bus_message_get_destination(m)), strna(sd_bus_message_get_path (m)), strna(sd_bus_message_get_interface(m)), strna(sd_bus_message_get_member (m)), BUS_MESSAGE_COOKIE(m), m->reply_cookie, strna(m-> root_container.signature), strna(m->error.name), strna(m-> error.message), bus_error_message(error, r)) : -abs(_e); }) | |||
350 | bus_message_type_to_string(m->header->type),({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/libsystemd/sd-bus/bus-internal.c", 361, __func__, "Failed to process message type=%s sender=%s destination=%s path=%s interface=%s member=%s cookie=%" "l" "u" " reply_cookie=%" "l" "u" " signature=%s error-name=%s error-message=%s: %s" , bus_message_type_to_string(m->header->type), strna(sd_bus_message_get_sender (m)), strna(sd_bus_message_get_destination(m)), strna(sd_bus_message_get_path (m)), strna(sd_bus_message_get_interface(m)), strna(sd_bus_message_get_member (m)), BUS_MESSAGE_COOKIE(m), m->reply_cookie, strna(m-> root_container.signature), strna(m->error.name), strna(m-> error.message), bus_error_message(error, r)) : -abs(_e); }) | |||
351 | strna(sd_bus_message_get_sender(m)),({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/libsystemd/sd-bus/bus-internal.c", 361, __func__, "Failed to process message type=%s sender=%s destination=%s path=%s interface=%s member=%s cookie=%" "l" "u" " reply_cookie=%" "l" "u" " signature=%s error-name=%s error-message=%s: %s" , bus_message_type_to_string(m->header->type), strna(sd_bus_message_get_sender (m)), strna(sd_bus_message_get_destination(m)), strna(sd_bus_message_get_path (m)), strna(sd_bus_message_get_interface(m)), strna(sd_bus_message_get_member (m)), BUS_MESSAGE_COOKIE(m), m->reply_cookie, strna(m-> root_container.signature), strna(m->error.name), strna(m-> error.message), bus_error_message(error, r)) : -abs(_e); }) | |||
352 | strna(sd_bus_message_get_destination(m)),({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/libsystemd/sd-bus/bus-internal.c", 361, __func__, "Failed to process message type=%s sender=%s destination=%s path=%s interface=%s member=%s cookie=%" "l" "u" " reply_cookie=%" "l" "u" " signature=%s error-name=%s error-message=%s: %s" , bus_message_type_to_string(m->header->type), strna(sd_bus_message_get_sender (m)), strna(sd_bus_message_get_destination(m)), strna(sd_bus_message_get_path (m)), strna(sd_bus_message_get_interface(m)), strna(sd_bus_message_get_member (m)), BUS_MESSAGE_COOKIE(m), m->reply_cookie, strna(m-> root_container.signature), strna(m->error.name), strna(m-> error.message), bus_error_message(error, r)) : -abs(_e); }) | |||
353 | strna(sd_bus_message_get_path(m)),({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/libsystemd/sd-bus/bus-internal.c", 361, __func__, "Failed to process message type=%s sender=%s destination=%s path=%s interface=%s member=%s cookie=%" "l" "u" " reply_cookie=%" "l" "u" " signature=%s error-name=%s error-message=%s: %s" , bus_message_type_to_string(m->header->type), strna(sd_bus_message_get_sender (m)), strna(sd_bus_message_get_destination(m)), strna(sd_bus_message_get_path (m)), strna(sd_bus_message_get_interface(m)), strna(sd_bus_message_get_member (m)), BUS_MESSAGE_COOKIE(m), m->reply_cookie, strna(m-> root_container.signature), strna(m->error.name), strna(m-> error.message), bus_error_message(error, r)) : -abs(_e); }) | |||
354 | strna(sd_bus_message_get_interface(m)),({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/libsystemd/sd-bus/bus-internal.c", 361, __func__, "Failed to process message type=%s sender=%s destination=%s path=%s interface=%s member=%s cookie=%" "l" "u" " reply_cookie=%" "l" "u" " signature=%s error-name=%s error-message=%s: %s" , bus_message_type_to_string(m->header->type), strna(sd_bus_message_get_sender (m)), strna(sd_bus_message_get_destination(m)), strna(sd_bus_message_get_path (m)), strna(sd_bus_message_get_interface(m)), strna(sd_bus_message_get_member (m)), BUS_MESSAGE_COOKIE(m), m->reply_cookie, strna(m-> root_container.signature), strna(m->error.name), strna(m-> error.message), bus_error_message(error, r)) : -abs(_e); }) | |||
355 | strna(sd_bus_message_get_member(m)),({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/libsystemd/sd-bus/bus-internal.c", 361, __func__, "Failed to process message type=%s sender=%s destination=%s path=%s interface=%s member=%s cookie=%" "l" "u" " reply_cookie=%" "l" "u" " signature=%s error-name=%s error-message=%s: %s" , bus_message_type_to_string(m->header->type), strna(sd_bus_message_get_sender (m)), strna(sd_bus_message_get_destination(m)), strna(sd_bus_message_get_path (m)), strna(sd_bus_message_get_interface(m)), strna(sd_bus_message_get_member (m)), BUS_MESSAGE_COOKIE(m), m->reply_cookie, strna(m-> root_container.signature), strna(m->error.name), strna(m-> error.message), bus_error_message(error, r)) : -abs(_e); }) | |||
356 | BUS_MESSAGE_COOKIE(m),({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/libsystemd/sd-bus/bus-internal.c", 361, __func__, "Failed to process message type=%s sender=%s destination=%s path=%s interface=%s member=%s cookie=%" "l" "u" " reply_cookie=%" "l" "u" " signature=%s error-name=%s error-message=%s: %s" , bus_message_type_to_string(m->header->type), strna(sd_bus_message_get_sender (m)), strna(sd_bus_message_get_destination(m)), strna(sd_bus_message_get_path (m)), strna(sd_bus_message_get_interface(m)), strna(sd_bus_message_get_member (m)), BUS_MESSAGE_COOKIE(m), m->reply_cookie, strna(m-> root_container.signature), strna(m->error.name), strna(m-> error.message), bus_error_message(error, r)) : -abs(_e); }) | |||
357 | m->reply_cookie,({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/libsystemd/sd-bus/bus-internal.c", 361, __func__, "Failed to process message type=%s sender=%s destination=%s path=%s interface=%s member=%s cookie=%" "l" "u" " reply_cookie=%" "l" "u" " signature=%s error-name=%s error-message=%s: %s" , bus_message_type_to_string(m->header->type), strna(sd_bus_message_get_sender (m)), strna(sd_bus_message_get_destination(m)), strna(sd_bus_message_get_path (m)), strna(sd_bus_message_get_interface(m)), strna(sd_bus_message_get_member (m)), BUS_MESSAGE_COOKIE(m), m->reply_cookie, strna(m-> root_container.signature), strna(m->error.name), strna(m-> error.message), bus_error_message(error, r)) : -abs(_e); }) | |||
358 | strna(m->root_container.signature),({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/libsystemd/sd-bus/bus-internal.c", 361, __func__, "Failed to process message type=%s sender=%s destination=%s path=%s interface=%s member=%s cookie=%" "l" "u" " reply_cookie=%" "l" "u" " signature=%s error-name=%s error-message=%s: %s" , bus_message_type_to_string(m->header->type), strna(sd_bus_message_get_sender (m)), strna(sd_bus_message_get_destination(m)), strna(sd_bus_message_get_path (m)), strna(sd_bus_message_get_interface(m)), strna(sd_bus_message_get_member (m)), BUS_MESSAGE_COOKIE(m), m->reply_cookie, strna(m-> root_container.signature), strna(m->error.name), strna(m-> error.message), bus_error_message(error, r)) : -abs(_e); }) | |||
359 | strna(m->error.name),({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/libsystemd/sd-bus/bus-internal.c", 361, __func__, "Failed to process message type=%s sender=%s destination=%s path=%s interface=%s member=%s cookie=%" "l" "u" " reply_cookie=%" "l" "u" " signature=%s error-name=%s error-message=%s: %s" , bus_message_type_to_string(m->header->type), strna(sd_bus_message_get_sender (m)), strna(sd_bus_message_get_destination(m)), strna(sd_bus_message_get_path (m)), strna(sd_bus_message_get_interface(m)), strna(sd_bus_message_get_member (m)), BUS_MESSAGE_COOKIE(m), m->reply_cookie, strna(m-> root_container.signature), strna(m->error.name), strna(m-> error.message), bus_error_message(error, r)) : -abs(_e); }) | |||
360 | strna(m->error.message),({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/libsystemd/sd-bus/bus-internal.c", 361, __func__, "Failed to process message type=%s sender=%s destination=%s path=%s interface=%s member=%s cookie=%" "l" "u" " reply_cookie=%" "l" "u" " signature=%s error-name=%s error-message=%s: %s" , bus_message_type_to_string(m->header->type), strna(sd_bus_message_get_sender (m)), strna(sd_bus_message_get_destination(m)), strna(sd_bus_message_get_path (m)), strna(sd_bus_message_get_interface(m)), strna(sd_bus_message_get_member (m)), BUS_MESSAGE_COOKIE(m), m->reply_cookie, strna(m-> root_container.signature), strna(m->error.name), strna(m-> error.message), bus_error_message(error, r)) : -abs(_e); }) | |||
361 | bus_error_message(error, r))({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/libsystemd/sd-bus/bus-internal.c", 361, __func__, "Failed to process message type=%s sender=%s destination=%s path=%s interface=%s member=%s cookie=%" "l" "u" " reply_cookie=%" "l" "u" " signature=%s error-name=%s error-message=%s: %s" , bus_message_type_to_string(m->header->type), strna(sd_bus_message_get_sender (m)), strna(sd_bus_message_get_destination(m)), strna(sd_bus_message_get_path (m)), strna(sd_bus_message_get_interface(m)), strna(sd_bus_message_get_member (m)), BUS_MESSAGE_COOKIE(m), m->reply_cookie, strna(m-> root_container.signature), strna(m->error.name), strna(m-> error.message), bus_error_message(error, r)) : -abs(_e); }); | |||
362 | ||||
363 | return 1; | |||
364 | } |
1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
2 | #pragma once |
3 | |
4 | #include <alloca.h> |
5 | #include <stddef.h> |
6 | #include <stdlib.h> |
7 | #include <string.h> |
8 | |
9 | #include "macro.h" |
10 | |
11 | #define new(t, n)((t*) malloc_multiply(sizeof(t), (n))) ((t*) malloc_multiply(sizeof(t), (n))) |
12 | |
13 | #define new0(t, n)((t*) calloc((n), sizeof(t))) ((t*) calloc((n), sizeof(t))) |
14 | |
15 | #define newa(t, n)({ do { if ((__builtin_expect(!!(!(!size_multiply_overflow(sizeof (t), n))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!size_multiply_overflow(sizeof(t), n)" ), "../src/basic/alloc-util.h", 15, __PRETTY_FUNCTION__); } while (0); (t*) __builtin_alloca (sizeof(t)*(n)); }) \ |
16 | ({ \ |
17 | assert(!size_multiply_overflow(sizeof(t), n))do { if ((__builtin_expect(!!(!(!size_multiply_overflow(sizeof (t), n))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!size_multiply_overflow(sizeof(t), n)" ), "../src/basic/alloc-util.h", 17, __PRETTY_FUNCTION__); } while (0); \ |
18 | (t*) alloca(sizeof(t)*(n))__builtin_alloca (sizeof(t)*(n)); \ |
19 | }) |
20 | |
21 | #define newa0(t, n)({ do { if ((__builtin_expect(!!(!(!size_multiply_overflow(sizeof (t), n))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!size_multiply_overflow(sizeof(t), n)" ), "../src/basic/alloc-util.h", 21, __PRETTY_FUNCTION__); } while (0); (t*) ({ char *_new_; size_t _len_ = sizeof(t)*(n); _new_ = __builtin_alloca (_len_); (void *) memset(_new_, 0, _len_) ; }); }) \ |
22 | ({ \ |
23 | assert(!size_multiply_overflow(sizeof(t), n))do { if ((__builtin_expect(!!(!(!size_multiply_overflow(sizeof (t), n))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!size_multiply_overflow(sizeof(t), n)" ), "../src/basic/alloc-util.h", 23, __PRETTY_FUNCTION__); } while (0); \ |
24 | (t*) alloca0(sizeof(t)*(n))({ char *_new_; size_t _len_ = sizeof(t)*(n); _new_ = __builtin_alloca (_len_); (void *) memset(_new_, 0, _len_); }); \ |
25 | }) |
26 | |
27 | #define newdup(t, p, n)((t*) memdup_multiply(p, sizeof(t), (n))) ((t*) memdup_multiply(p, sizeof(t), (n))) |
28 | |
29 | #define newdup_suffix0(t, p, n)((t*) memdup_suffix0_multiply(p, sizeof(t), (n))) ((t*) memdup_suffix0_multiply(p, sizeof(t), (n))) |
30 | |
31 | #define malloc0(n)(calloc(1, (n))) (calloc(1, (n))) |
32 | |
33 | static inline void *mfree(void *memory) { |
34 | free(memory); |
35 | return NULL((void*)0); |
36 | } |
37 | |
38 | #define free_and_replace(a, b)({ free(a); (a) = (b); (b) = ((void*)0); 0; }) \ |
39 | ({ \ |
40 | free(a); \ |
41 | (a) = (b); \ |
42 | (b) = NULL((void*)0); \ |
43 | 0; \ |
44 | }) |
45 | |
46 | void* memdup(const void *p, size_t l) _alloc_(2); |
47 | void* memdup_suffix0(const void *p, size_t l) _alloc_(2); |
48 | |
49 | static inline void freep(void *p) { |
50 | free(*(void**) p); |
51 | } |
52 | |
53 | #define _cleanup_free___attribute__((cleanup(freep))) _cleanup_(freep)__attribute__((cleanup(freep))) |
54 | |
55 | static inline bool_Bool size_multiply_overflow(size_t size, size_t need) { |
56 | return _unlikely_(need != 0 && size > (SIZE_MAX / need))(__builtin_expect(!!(need != 0 && size > ((18446744073709551615UL ) / need)),0)); |
57 | } |
58 | |
59 | _malloc___attribute__ ((malloc)) _alloc_(1, 2) static inline void *malloc_multiply(size_t size, size_t need) { |
60 | if (size_multiply_overflow(size, need)) |
61 | return NULL((void*)0); |
62 | |
63 | return malloc(size * need); |
64 | } |
65 | |
66 | #if !HAVE_REALLOCARRAY1 |
67 | _alloc_(2, 3) static inline void *reallocarray(void *p, size_t need, size_t size) { |
68 | if (size_multiply_overflow(size, need)) |
69 | return NULL((void*)0); |
70 | |
71 | return realloc(p, size * need); |
72 | } |
73 | #endif |
74 | |
75 | _alloc_(2, 3) static inline void *memdup_multiply(const void *p, size_t size, size_t need) { |
76 | if (size_multiply_overflow(size, need)) |
77 | return NULL((void*)0); |
78 | |
79 | return memdup(p, size * need); |
80 | } |
81 | |
82 | _alloc_(2, 3) static inline void *memdup_suffix0_multiply(const void *p, size_t size, size_t need) { |
83 | if (size_multiply_overflow(size, need)) |
84 | return NULL((void*)0); |
85 | |
86 | return memdup_suffix0(p, size * need); |
87 | } |
88 | |
89 | void* greedy_realloc(void **p, size_t *allocated, size_t need, size_t size); |
90 | void* greedy_realloc0(void **p, size_t *allocated, size_t need, size_t size); |
91 | |
92 | #define GREEDY_REALLOC(array, allocated, need)greedy_realloc((void**) &(array), &(allocated), (need ), sizeof((array)[0])) \ |
93 | greedy_realloc((void**) &(array), &(allocated), (need), sizeof((array)[0])) |
94 | |
95 | #define GREEDY_REALLOC0(array, allocated, need)greedy_realloc0((void**) &(array), &(allocated), (need ), sizeof((array)[0])) \ |
96 | greedy_realloc0((void**) &(array), &(allocated), (need), sizeof((array)[0])) |
97 | |
98 | #define alloca0(n)({ char *_new_; size_t _len_ = n; _new_ = __builtin_alloca (_len_ ); (void *) memset(_new_, 0, _len_); }) \ |
99 | ({ \ |
100 | char *_new_; \ |
101 | size_t _len_ = n; \ |
102 | _new_ = alloca(_len_)__builtin_alloca (_len_); \ |
103 | (void *) memset(_new_, 0, _len_); \ |
104 | }) |
105 | |
106 | /* It's not clear what alignment glibc/gcc alloca() guarantee, hence provide a guaranteed safe version */ |
107 | #define alloca_align(size, align)({ void *_ptr_; size_t _mask_ = (align) - 1; _ptr_ = __builtin_alloca ((size) + _mask_); (void*)(((uintptr_t)_ptr_ + _mask_) & ~_mask_); }) \ |
108 | ({ \ |
109 | void *_ptr_; \ |
110 | size_t _mask_ = (align) - 1; \ |
111 | _ptr_ = alloca((size) + _mask_)__builtin_alloca ((size) + _mask_); \ |
112 | (void*)(((uintptr_t)_ptr_ + _mask_) & ~_mask_); \ |
113 | }) |
114 | |
115 | #define alloca0_align(size, align)({ void *_new_; size_t _size_ = (size); _new_ = ({ void *_ptr_ ; size_t _mask_ = ((align)) - 1; _ptr_ = __builtin_alloca ((_size_ ) + _mask_); (void*)(((uintptr_t)_ptr_ + _mask_) & ~_mask_ ); }); (void*)memset(_new_, 0, _size_); }) \ |
116 | ({ \ |
117 | void *_new_; \ |
118 | size_t _size_ = (size); \ |
119 | _new_ = alloca_align(_size_, (align))({ void *_ptr_; size_t _mask_ = ((align)) - 1; _ptr_ = __builtin_alloca ((_size_) + _mask_); (void*)(((uintptr_t)_ptr_ + _mask_) & ~_mask_); }); \ |
120 | (void*)memset(_new_, 0, _size_); \ |
121 | }) |
122 | |
123 | /* Takes inspiration from Rusts's Option::take() method: reads and returns a pointer, but at the same time resets it to |
124 | * NULL. See: https://doc.rust-lang.org/std/option/enum.Option.html#method.take */ |
125 | #define TAKE_PTR(ptr)({ typeof(ptr) _ptr_ = (ptr); (ptr) = ((void*)0); _ptr_; }) \ |
126 | ({ \ |
127 | typeof(ptr) _ptr_ = (ptr); \ |
128 | (ptr) = NULL((void*)0); \ |
129 | _ptr_; \ |
130 | }) |