--- /dev/null
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+@@
+expression x;
+@@
+- strdupa(x)
++ strdupa_safe(x)
+@@
+expression x, n;
+@@
+- strndupa(x, n)
++ strndupa_safe(x, n)
if (!sysname)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Requires a subsystem and sysname pair specifying a backlight device.");
- ss = strndupa(argv[2], sysname - argv[2]);
+ ss = strndupa_safe(argv[2], sysname - argv[2]);
sysname++;
__builtin_types_compatible_p(typeof(x), typeof(&*(x))), \
MALLOC_SIZEOF_SAFE(x)/sizeof((x)[0]), \
VOID_0))
+
+
+/* These are like strdupa()/strndupa(), but honour ALLOCA_MAX */
+#define strdupa_safe(s) \
+ ({ \
+ const char *_t = (s); \
+ (char*) memdupa_suffix0(_t, strlen(_t)); \
+ })
+
+#define strndupa_safe(s, n) \
+ ({ \
+ const char *_t = (s); \
+ (char*) memdupa_suffix0(_t, strnlen(_t, (n))); \
+ })
+
+#include "memory-util.h"
if (n < 3)
return -ENXIO;
- c = strndupa(cgroup, n);
+ c = strndupa_safe(cgroup, n);
c = cg_unescape(c);
if (!unit_name_is_valid(c, UNIT_NAME_PLAIN|UNIT_NAME_INSTANCE))
return -EINVAL;
}
- name = strndupa(p, t - p);
+ name = strndupa_safe(p, t - p);
STRV_FOREACH(f, *l)
if (env_entry_has_name(*f, name)) {
if (flags & REPLACE_ENV_USE_ENVIRONMENT) {
const char *t;
- t = strndupa(name, k);
+ t = strndupa_safe(name, k);
return getenv(t);
};
if (!e)
return -EINVAL;
- n = strndupa(assignment, e - assignment);
+ n = strndupa_safe(assignment, e - assignment);
/* This is like putenv(), but uses setenv() so that our memory doesn't become part of environ[]. */
if (setenv(n, e + 1, override) < 0)
if (!path_is_safe(stop))
return -EINVAL;
- p = strdupa(path);
+ p = strdupa_safe(path);
for (;;) {
char *slash = NULL;
for (size_t i = 0; i < n_input_iovec; i++)
if (memory_startswith(input_iovec[i].iov_base, input_iovec[i].iov_len, "MESSAGE=")) {
- char *m = strndupa(input_iovec[i].iov_base + STRLEN("MESSAGE="),
- input_iovec[i].iov_len - STRLEN("MESSAGE="));
+ char *m;
+
+ m = strndupa_safe((char*) input_iovec[i].iov_base + STRLEN("MESSAGE="),
+ input_iovec[i].iov_len - STRLEN("MESSAGE="));
return log_dispatch_internal(level, error, file, line, func, NULL, NULL, NULL, NULL, m);
}
assert(*e == '/');
/* drop the last component */
- path = strndupa(path, e - path);
+ path = strndupa_safe(path, e - path);
r = is_dir(path, true);
if (r > 0)
return 0;
if (slash[strspn(slash, "/")] != 0) /* Check that the suffix consist only of one or more slashes */
return false;
- copied = strndupa(s, slash - s);
+ copied = strndupa_safe(s, slash - s);
return filename_is_valid(copied);
}
if (s[n] != ':')
return -EINVAL;
- major = strndupa(s, n);
+ major = strndupa_safe(s, n);
r = safe_atou(major, &x);
if (r < 0)
return r;
if (!d)
return -EINVAL;
- i_str = strndupa(s, d - s);
+ i_str = strndupa_safe(s, d - s);
f_str = d + 1;
r = safe_atolu_full(i_str, 10, &i);
k = endswith(e, ":");
if (k) {
- e = strndupa(e, k - e);
+ e = strndupa_safe(e, k - e);
*append = true;
}
if (!pc)
return -EINVAL;
- n = strndupa(p, pc - p);
+ n = strndupa_safe(p, pc - p);
r = safe_atoi(n, &v);
if (r < 0)
return r;
if (dot[1] < '0' || dot[1] > '9')
return -EINVAL;
q = dot[1] - '0';
- n = strndupa(p, dot - p);
+ n = strndupa_safe(p, dot - p);
} else {
q = 0;
- n = strndupa(p, pc - p);
+ n = strndupa_safe(p, pc - p);
}
r = safe_atoi(n, &v);
if (r < 0)
/* We do not support zero or more than two places */
return -EINVAL;
- n = strndupa(p, dot - p);
+ n = strndupa_safe(p, dot - p);
} else {
q = 0;
- n = strndupa(p, pc - p);
+ n = strndupa_safe(p, pc - p);
}
r = safe_atoi(n, &v);
if (r < 0)
p++;
n = strspn(p, DIGITS);
- nr = strndupa(p, n);
+ nr = strndupa_safe(p, n);
return safe_atou64(nr, ret);
}
goto finish;
} else if ((k = endswith(t, " ago"))) {
- t = strndupa(t, k - t);
+ t = strndupa_safe(t, k - t);
r = parse_sec(t, &minus);
if (r < 0)
goto finish;
} else if ((k = endswith(t, " left"))) {
- t = strndupa(t, k - t);
+ t = strndupa_safe(t, k - t);
r = parse_sec(t, &plus);
if (r < 0)
/* See if the timestamp is suffixed with UTC */
utc = endswith_no_case(t, " UTC");
if (utc)
- t = strndupa(t, utc - t);
+ t = strndupa_safe(t, utc - t);
else {
const char *e = NULL;
int j;
if (IN_SET(j, 0, 1)) {
/* Found one of the two timezones specified. */
- t = strndupa(t, e - t - 1);
+ t = strndupa_safe(t, e - t - 1);
dst = j;
tzn = tzname[j];
}
/* Cut off the timezone if we don't need it. */
if (with_tz)
- t = strndupa(t, last_space - t);
+ t = strndupa_safe(t, last_space - t);
shared->return_value = parse_timestamp_impl(t, &shared->usec, with_tz);
"Can't parse empty 'tries left' counter from LoaderBootCountPath: %s",
path);
- z = strndupa(e, k);
+ z = strndupa_safe(e, k);
r = safe_atou64(z, &left);
if (r < 0)
return log_error_errno(r, "Failed to parse 'tries left' counter from LoaderBootCountPath: %s", path);
"Can't parse empty 'tries done' counter from LoaderBootCountPath: %s",
path);
- z = strndupa(e, k);
+ z = strndupa_safe(e, k);
r = safe_atou64(z, &done);
if (r < 0)
return log_error_errno(r, "Failed to parse 'tries done' counter from LoaderBootCountPath: %s", path);
if (u)
return u;
- p = strdupa(cgroup);
+ p = strdupa_safe(cgroup);
for (;;) {
char *e;
if (soft) {
const char *n;
- n = strndupa(suffix, soft - suffix);
+ n = strndupa_safe(suffix, soft - suffix);
ri = rlimit_from_string(n);
if (ri >= 0)
name = strjoina("Limit", n);
else
*p = v;
- char *n = strndupa(name, strlen(name) - 4);
+ char *n = strndupa_safe(name, strlen(name) - 4);
unit_write_settingf(u, flags, name, "%sSec=%s", n, FORMAT_TIMESPAN(v, USEC_PER_MSEC));
}
assert(fds);
n = strcspn(v, " ");
- id = strndupa(v, n);
+ id = strndupa_safe(v, n);
if (v[n] != ' ')
goto finalize;
p = v + n + 1;
char *buf;
n = strcspn(v, " ");
- buf = strndupa(v, n);
+ buf = strndupa_safe(v, n);
r = safe_atoi(buf, &netns_fdpair[0]);
if (r < 0)
char *buf;
n = strcspn(v, " ");
- buf = strndupa(v, n);
+ buf = strndupa_safe(v, n);
r = safe_atoi(buf, &netns_fdpair[1]);
if (r < 0)
char *buf;
n = strcspn(v, " ");
- buf = strndupa(v, n);
+ buf = strndupa_safe(v, n);
r = safe_atoi(buf, &ipcns_fdpair[0]);
if (r < 0)
char *buf;
n = strcspn(v, " ");
- buf = strndupa(v, n);
+ buf = strndupa_safe(v, n);
r = safe_atoi(buf, &ipcns_fdpair[1]);
if (r < 0)
if (!e)
return -EINVAL;
- u = strndupa(p, e-p);
+ u = strndupa_safe(p, e - p);
return parse_uid(u, uid);
}
if (!e)
return 0;
- n = strndupa(event->name, e - event->name);
+ n = strndupa_safe(event->name, e - event->name);
if (!suitable_user_name(n))
return 0;
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "User record lacks CIFS service, refusing.");
assert_se(hdo = user_record_home_directory(h));
- hd = strdupa(hdo); /* copy the string out, since it might change later in the home record object */
+ hd = strdupa_safe(hdo); /* copy the string out, since it might change later in the home record object */
r = home_prepare_cifs(h, false, &setup);
if (r < 0)
assert(ret_home);
assert_se(ipo = user_record_image_path(h));
- ip = strdupa(ipo); /* copy out, since reconciliation might cause changing of the field */
+ ip = strdupa_safe(ipo); /* copy out, since reconciliation might cause changing of the field */
assert_se(hdo = user_record_home_directory(h));
- hd = strdupa(hdo);
+ hd = strdupa_safe(hdo);
r = home_prepare(h, false, cache, &setup, &header_home);
if (r < 0)
e = strchr(cipher_mode, '-');
if (e)
- cipher_mode = strndupa(cipher_mode, e - cipher_mode);
+ cipher_mode = strndupa_safe(cipher_mode, e - cipher_mode);
r = sym_crypt_get_volume_key_size(cd);
if (r <= 0)
return r;
assert_se(hdo = user_record_home_directory(h));
- hd = strdupa(hdo); /* copy the string out, since it might change later in the home record object */
+ hd = strdupa_safe(hdo); /* copy the string out, since it might change later in the home record object */
r = make_dm_names(h->user_name, &setup.dm_name, &setup.dm_node);
if (r < 0)
return r;
assert_se(ipo = user_record_image_path(h));
- ip = strdupa(ipo); /* copy out since original might change later in home record object */
+ ip = strdupa_safe(ipo); /* copy out since original might change later in home record object */
image_fd = open(ip, O_RDWR|O_CLOEXEC|O_NOCTTY|O_NONBLOCK);
if (image_fd < 0)
else
url = strjoina(arg_url, "/entries");
} else
- url = strdupa(arg_url);
+ url = strdupa_safe(arg_url);
log_info("Spawning curl %s...", url);
fd = spawn_curl(url);
if (!hostname)
hostname = arg_url;
- hostname = strndupa(hostname, strcspn(hostname, "/:"));
+ hostname = strndupa_safe(hostname, strcspn(hostname, "/:"));
r = journal_remote_add_source(s, fd, (char *) hostname, false);
if (r < 0)
char *t;
size_t x;
- t = strdupa(url);
+ t = strdupa_safe(url);
x = strlen(t);
while (x > 0 && t[x - 1] == '/')
t[x - 1] = '\0';
} else if (strlen(x) >= SD_ID128_STRING_MAX - 1) {
char *t;
- t = strndupa(x, SD_ID128_STRING_MAX - 1);
+ t = strndupa_safe(x, SD_ID128_STRING_MAX - 1);
r = sd_id128_from_string(t, &id);
if (r >= 0)
x += SD_ID128_STRING_MAX - 1;
if (r < 0)
return r;
- types = strndupa(c->signature + c->index, l);
+ types = strndupa_safe(c->signature + c->index, l);
}
switch (*types) {
e = strrchr(path, '/');
assert(e);
- p = strndupa(path, MAX(1, e - path));
+ p = strndupa_safe(path, MAX(1, e - path));
parent = bus_node_allocate(bus, p);
if (!parent)
}
/* Make sure the path is NUL terminated */
- p = strndupa(b->sockaddr.un.sun_path, sizeof(b->sockaddr.un.sun_path));
+ p = strndupa_safe(b->sockaddr.un.sun_path,
+ sizeof(b->sockaddr.un.sun_path));
/* Make sure the path is absolute */
r = path_make_absolute_cwd(p, &absolute);
rbracket = strchr(host, ']');
if (!rbracket)
return -EINVAL;
- t = strndupa(host + 1, rbracket - host - 1);
+ t = strndupa_safe(host + 1, rbracket - host - 1);
e = bus_address_escape(t);
if (!e)
return -ENOMEM;
t = strchr(p, '/');
if (t) {
- p = strndupa(p, t - p);
+ p = strndupa_safe(p, t - p);
got_forward_slash = true;
}
if (!e) {
char *t;
- t = strndupa(host, strcspn(host, ":/"));
+ t = strndupa_safe(host, strcspn(host, ":/"));
e = bus_address_escape(t);
if (!e)
}
/* translate sysname back to sysfs filename */
- name = strdupa(sysname);
+ name = strdupa_safe(sysname);
for (size_t i = 0; name[i]; i++)
if (name[i] == '/')
name[i] = '!';
if (!log_namespace_name_valid(e + 1))
return false;
- k = strndupa(fn, e - fn);
+ k = strndupa_safe(fn, e - fn);
r = sd_id128_from_string(k, &id);
} else
r = sd_id128_from_string(fn, &id);
if (!streq(e + 1, namespace))
return false;
- k = strndupa(fn, e - fn);
+ k = strndupa_safe(fn, e - fn);
return id128_is_valid(k);
}
if (!e)
return id128_is_valid(de->d_name); /* No namespace */
- n = strndupa(de->d_name, e - de->d_name);
+ n = strndupa_safe(de->d_name, e - de->d_name);
if (!id128_is_valid(n))
return false;
*/
char *l, *v = NULL, *converted;
- l = strndupa(c->x11_layout, strcspn(c->x11_layout, ","));
+ l = strndupa_safe(c->x11_layout, strcspn(c->x11_layout, ","));
if (c->x11_variant)
- v = strndupa(c->x11_variant, strcspn(c->x11_variant, ","));
+ v = strndupa_safe(c->x11_variant,
+ strcspn(c->x11_variant, ","));
r = find_converted_keymap(l, v, &converted);
if (r < 0)
return r;
host_basename = basename(host_path);
container_basename = basename(container_path);
- t = strdupa(container_path);
+ t = strdupa_safe(container_path);
container_dirname = dirname(t);
hostfd = open_parent(host_path, O_CLOEXEC, 0);
if (!p)
mtu = value;
else
- mtu = strndupa(value, p - value);
+ mtu = strndupa_safe(value, p - value);
r = network_set_mtu(context, ifname, family, mtu);
if (r < 0)
if (q[1] != ':')
return -EINVAL;
- buf = strndupa(p + 1, q - p - 1);
+ buf = strndupa_safe(p + 1, q - p - 1);
p = q + 2;
} else {
q = strchr(p, ':');
if (!q)
return -EINVAL;
- buf = strndupa(p, q - p);
+ buf = strndupa_safe(p, q - p);
p = q + 1;
}
if (!p)
return -EINVAL;
- q = strndupa(*value, p - *value);
+ q = strndupa_safe(*value, p - *value);
r = safe_atou8(q, ret);
if (r < 0)
return r;
return -EINVAL;
if (p != value) {
- hostname = strndupa(value, p - value);
+ hostname = strndupa_safe(value, p - value);
if (!hostname_is_valid(hostname, 0))
return -EINVAL;
}
if (!p)
return -EINVAL;
- ifname = strndupa(value, p - value);
+ ifname = strndupa_safe(value, p - value);
value = p + 1;
if (!p)
dhcp_type = value;
else
- dhcp_type = strndupa(value, p - value);
+ dhcp_type = strndupa_safe(value, p - value);
r = network_set_dhcp_type(context, ifname, dhcp_type);
if (r < 0)
if (r < 0)
return r;
} else {
- dns = strndupa(value, p - value);
+ dns = strndupa_safe(value, p - value);
r = network_set_dns(context, ifname, dns);
if (r < 0)
return r;
if (!p)
return -EINVAL;
- ifname = strndupa(value, p - value);
+ ifname = strndupa_safe(value, p - value);
value = p + 1;
p = strchr(value, ':');
if (!p)
dhcp_type = value;
else
- dhcp_type = strndupa(value, p - value);
+ dhcp_type = strndupa_safe(value, p - value);
r = network_set_dhcp_type(context, ifname, dhcp_type);
if (r < 0)
if (p[1] != ':')
return -EINVAL;
- buf = strndupa(value + 1, p - value - 1);
+ buf = strndupa_safe(value + 1, p - value - 1);
value = p + 2;
family = AF_INET6;
} else {
if (!p)
return -EINVAL;
- buf = strndupa(value, p - value);
+ buf = strndupa_safe(value, p - value);
value = p + 1;
family = AF_INET;
}
if (!p)
return -EINVAL;
- name = strndupa(value, p - value);
+ name = strndupa_safe(value, p - value);
netdev = netdev_get(context, name);
if (!netdev) {
if (!p)
return -EINVAL;
- name = strndupa(value, p - value);
+ name = strndupa_safe(value, p - value);
netdev = netdev_get(context, name);
if (!netdev) {
if (!p)
return -EINVAL;
- name = strndupa(value, p - value);
+ name = strndupa_safe(value, p - value);
netdev = netdev_get(context, name);
if (!netdev) {
if (!p)
slaves = value;
else
- slaves = strndupa(value, p - value);
+ slaves = strndupa_safe(value, p - value);
if (isempty(slaves))
return -EINVAL;
if (!p)
return -EINVAL;
- name = strndupa(value, p - value);
+ name = strndupa_safe(value, p - value);
r = ether_addr_from_string(p + 1, &mac);
if (r < 0)
range = strchr(rvalue, ':');
if (range) {
- shift = strndupa(rvalue, range - rvalue);
+ shift = strndupa_safe(rvalue, range - rvalue);
range++;
r = safe_atou32(range, &rn);
at = strchr(name, '@');
assert(at);
- prefix = strndupa(name, at + 1 - name);
+ prefix = strndupa_safe(name, at + 1 - name);
joined = strjoina(prefix, "*", at + 1);
r = sd_bus_message_append_strv(m, STRV_MAKE(joined));
q = strchr(p, '?');
if (q) {
- n = strndupa(p, q - p);
+ n = strndupa_safe(p, q - p);
q++;
for (;;) {
if (r < 0)
return log_error_errno(r, "Invalid port \"%s\".", port + 1);
- address = strndupa(address, port - address);
+ address = strndupa_safe(address, port - address);
}
r = asprintf(&full, "_%u._%s.%s",
int z;
/* Chop off "Soft" suffix */
- s = is_soft ? strndupa(property, is_soft - property) : property;
+ s = is_soft ? strndupa_safe(property, is_soft - property) : property;
/* Skip over any prefix, such as "Default" */
assert_se(p = strstr(s, "Limit"));
if (!e)
return -EINVAL;
- pp = strndupa(path, e - path);
+ pp = strndupa_safe(path, e - path);
r = add_cgroup(cgroups, pp, false, &parent);
if (r < 0)
e = strchr(eq, ' ');
if (e) {
- path = strndupa(eq, e - eq);
+ path = strndupa_safe(eq, e - eq);
rwm = e+1;
}
"Failed to parse %s value %s.",
field, eq);
- path = strndupa(eq, e - eq);
+ path = strndupa_safe(eq, e - eq);
bandwidth = e+1;
if (streq(bandwidth, "infinity"))
"Failed to parse %s value %s.",
field, eq);
- path = strndupa(eq, e - eq);
+ path = strndupa_safe(eq, e - eq);
weight = e+1;
r = safe_atou64(weight, &u);
"Failed to parse %s value %s.",
field, eq);
- path = strndupa(eq, e - eq);
+ path = strndupa_safe(eq, e - eq);
target = e+1;
r = parse_sec(target, &usec);
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Not an assignment: %s", assignment);
- field = strndupa(assignment, eq - assignment);
+ field = strndupa_safe(assignment, eq - assignment);
eq++;
switch (t) {
}
/* Found it! Now generate the new name */
- prefix = strndupa(name, saved_before - name);
+ prefix = strndupa_safe(name, saved_before - name);
r = dns_name_concat(prefix, new_suffix, 0, ret);
if (r < 0)
if (memchr(label, 0, n))
return false;
- s = strndupa(label, n);
+ s = strndupa_safe(label, n);
return dns_service_name_is_valid(s);
}
if (!journal_field_valid(line, sep - line, true)) {
char buf[64], *t;
- t = strndupa(line, sep - line);
+ t = strndupa_safe(line, sep - line);
log_debug("Ignoring invalid field: \"%s\"",
cellescape(buf, sizeof buf, t));
if (!journal_field_valid(line, n - 1, true)) {
char buf[64], *t;
- t = strndupa(line, n - 1);
+ t = strndupa_safe(line, n - 1);
log_debug("Ignoring invalid field: \"%s\"",
cellescape(buf, sizeof buf, t));
if (!fields)
return 1;
- s = strndupa(name, n);
+ s = strndupa_safe(name, n);
return set_contains(fields, s);
}
if (!journal_field_valid(data, fieldlen, true))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Invalid field.");
- name = strndupa(data, fieldlen);
+ name = strndupa_safe(data, fieldlen);
if (output_fields && !set_contains(output_fields, name))
return 0;
if (e) {
char *page = NULL, *section = NULL;
- page = strndupa(desc, e - desc);
- section = strndupa(e + 1, desc + k - e - 2);
+ page = strndupa_safe(desc, e - desc);
+ section = strndupa_safe(e + 1, desc + k - e - 2);
args[1] = section;
args[2] = page;
if (un->sun_path[0] == 0)
goto skipped;
- path = strndupa(un->sun_path, addrlen - offsetof(struct sockaddr_un, sun_path));
+ path = strndupa_safe(un->sun_path,
+ addrlen - offsetof(struct sockaddr_un, sun_path));
/* Check for policy reload so 'label_hnd' is kept up-to-date by callbacks */
mac_selinux_maybe_reload();
param = strchr(device, ':');
if (param) {
- driver = strndupa(device, param - device);
+ driver = strndupa_safe(device, param - device);
param++;
} else {
driver = "device";
char *b;
uid_t end;
- b = strndupa(s, t - s);
+ b = strndupa_safe(s, t - s);
r = parse_uid(b, &start);
if (r < 0)
return r;
service = strrchr(arg_remote_host, ':');
if (service) {
- node = strndupa(arg_remote_host, service - arg_remote_host);
+ node = strndupa_safe(arg_remote_host,
+ service - arg_remote_host);
service++;
} else {
node = arg_remote_host;
}
/* Strip ".sh" suffix from file name for comparison */
- filename_no_sh = strdupa(filename);
+ filename_no_sh = strdupa_safe(filename);
e = endswith(filename_no_sh, ".sh");
if (e) {
*e = '\0';
old_tz = getenv("TZ");
if (old_tz)
- old_tz = strdupa(old_tz);
+ old_tz = strdupa_safe(old_tz);
if (!isempty(new_tz))
new_tz = strjoina(":", new_tz);
l = strlen(s);
assert_se(hex = hexmem(mem, len));
- answer = strndupa(strempty(s), l);
+ answer = strndupa_safe(strempty(s), l);
assert_se(streq(delete_chars(answer, WHITESPACE), hex));
}
}
if (retval == 0) {
char *str;
- str = strndupa(mem, len);
+ str = strndupa_safe(mem, len);
assert_se(streq(str, ans));
}
}
log_info("/* %s */", __func__);
- s = strdupa("foobar");
+ s = strdupa_safe("foobar");
assert_se(streq(hostname_cleanup(s), "foobar"));
- s = strdupa("foobar.com");
+ s = strdupa_safe("foobar.com");
assert_se(streq(hostname_cleanup(s), "foobar.com"));
- s = strdupa("foobar.com.");
+ s = strdupa_safe("foobar.com.");
assert_se(streq(hostname_cleanup(s), "foobar.com"));
- s = strdupa("foo-bar.-com-.");
+ s = strdupa_safe("foo-bar.-com-.");
assert_se(streq(hostname_cleanup(s), "foo-bar.com"));
- s = strdupa("foo-bar-.-com-.");
+ s = strdupa_safe("foo-bar-.-com-.");
assert_se(streq(hostname_cleanup(s), "foo-bar--com"));
- s = strdupa("--foo-bar.-com");
+ s = strdupa_safe("--foo-bar.-com");
assert_se(streq(hostname_cleanup(s), "foo-bar.com"));
- s = strdupa("fooBAR");
+ s = strdupa_safe("fooBAR");
assert_se(streq(hostname_cleanup(s), "fooBAR"));
- s = strdupa("fooBAR.com");
+ s = strdupa_safe("fooBAR.com");
assert_se(streq(hostname_cleanup(s), "fooBAR.com"));
- s = strdupa("fooBAR.");
+ s = strdupa_safe("fooBAR.");
assert_se(streq(hostname_cleanup(s), "fooBAR"));
- s = strdupa("fooBAR.com.");
+ s = strdupa_safe("fooBAR.com.");
assert_se(streq(hostname_cleanup(s), "fooBAR.com"));
- s = strdupa("fööbar");
+ s = strdupa_safe("fööbar");
assert_se(streq(hostname_cleanup(s), "fbar"));
- s = strdupa("");
+ s = strdupa_safe("");
assert_se(isempty(hostname_cleanup(s)));
- s = strdupa(".");
+ s = strdupa_safe(".");
assert_se(isempty(hostname_cleanup(s)));
- s = strdupa("..");
+ s = strdupa_safe("..");
assert_se(isempty(hostname_cleanup(s)));
- s = strdupa("foobar.");
+ s = strdupa_safe("foobar.");
assert_se(streq(hostname_cleanup(s), "foobar"));
- s = strdupa(".foobar");
+ s = strdupa_safe(".foobar");
assert_se(streq(hostname_cleanup(s), "foobar"));
- s = strdupa("foo..bar");
+ s = strdupa_safe("foo..bar");
assert_se(streq(hostname_cleanup(s), "foo.bar"));
- s = strdupa("foo.bar..");
+ s = strdupa_safe("foo.bar..");
assert_se(streq(hostname_cleanup(s), "foo.bar"));
- s = strdupa("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
+ s = strdupa_safe("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
assert_se(streq(hostname_cleanup(s), "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"));
- s = strdupa("xxxx........xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
+ s = strdupa_safe("xxxx........xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
assert_se(streq(hostname_cleanup(s), "xxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"));
}
static void test_path_simplify_one(const char *in, const char *out) {
char *p;
- p = strdupa(in);
+ p = strdupa_safe(in);
path_simplify(p);
log_debug("/* test_path_simplify(%s) → %s (expected: %s) */", in, p, out);
assert_se(streq(p, out));
log_info("/* %s */", __func__);
char *x;
- x = strdupa("");
+ x = strdupa_safe("");
assert_se(streq(string_erase(x), ""));
- x = strdupa("1");
+ x = strdupa_safe("1");
assert_se(streq(string_erase(x), ""));
- x = strdupa("123456789");
+ x = strdupa_safe("123456789");
assert_se(streq(string_erase(x), ""));
assert_se(x[1] == '\0');
/* Save the old $TZ */
tz = getenv("TZ");
if (tz)
- old_tz = strdupa(tz);
+ old_tz = strdupa_safe(tz);
/* Set the new $TZ */
tz_colon = strjoina(":", isempty(i->timezone) ? "UTC" : i->timezone);
const struct dmi_header *h, uint8_t s) {
char *str;
- str = strdupa(dmi_string(h, s));
+ str = strdupa_safe(dmi_string(h, s));
str = strstrip(str);
if (!isempty(str))
printf("MEMORY_DEVICE_%u_%s=%s\n", slot_num, attr_suffix, str);
if (!pos)
return NULL;
- base = strndupa(base, pos - base);
+ base = strndupa_safe(base, pos - base);
dir = opendir(base);
if (!dir)
return NULL;
p = endswith(s, "+");
if (p)
- s = strndupa(s, p - s);
+ s = strndupa_safe(s, p - s);
r = safe_atou(s, ret);
if (r < 0)