mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-12 09:17:44 +03:00
Merge pull request #20256 from keszybz/one-alloca-too-many
basic/unit-name: do not use strdupa() on a path
This commit is contained in:
commit
b34a4f0e67
@ -378,12 +378,13 @@ int unit_name_unescape(const char *f, char **ret) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int unit_name_path_escape(const char *f, char **ret) {
|
int unit_name_path_escape(const char *f, char **ret) {
|
||||||
char *p, *s;
|
_cleanup_free_ char *p = NULL;
|
||||||
|
char *s;
|
||||||
|
|
||||||
assert(f);
|
assert(f);
|
||||||
assert(ret);
|
assert(ret);
|
||||||
|
|
||||||
p = strdupa(f);
|
p = strdup(f);
|
||||||
if (!p)
|
if (!p)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
@ -395,13 +396,9 @@ int unit_name_path_escape(const char *f, char **ret) {
|
|||||||
if (!path_is_normalized(p))
|
if (!path_is_normalized(p))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
/* Truncate trailing slashes */
|
/* Truncate trailing slashes and skip leading slashes */
|
||||||
delete_trailing_chars(p, "/");
|
delete_trailing_chars(p, "/");
|
||||||
|
s = unit_name_escape(skip_leading_chars(p, "/"));
|
||||||
/* Truncate leading slashes */
|
|
||||||
p = skip_leading_chars(p, "/");
|
|
||||||
|
|
||||||
s = unit_name_escape(p);
|
|
||||||
}
|
}
|
||||||
if (!s)
|
if (!s)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
@ -531,7 +528,7 @@ int unit_name_from_path(const char *path, const char *suffix, char **ret) {
|
|||||||
if (strlen(s) >= UNIT_NAME_MAX) /* Return a slightly more descriptive error for this specific condition */
|
if (strlen(s) >= UNIT_NAME_MAX) /* Return a slightly more descriptive error for this specific condition */
|
||||||
return -ENAMETOOLONG;
|
return -ENAMETOOLONG;
|
||||||
|
|
||||||
/* Refuse this if this got too long or for some other reason didn't result in a valid name */
|
/* Refuse if this for some other reason didn't result in a valid name */
|
||||||
if (!unit_name_is_valid(s, UNIT_NAME_PLAIN))
|
if (!unit_name_is_valid(s, UNIT_NAME_PLAIN))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
@ -565,7 +562,7 @@ int unit_name_from_path_instance(const char *prefix, const char *path, const cha
|
|||||||
if (strlen(s) >= UNIT_NAME_MAX) /* Return a slightly more descriptive error for this specific condition */
|
if (strlen(s) >= UNIT_NAME_MAX) /* Return a slightly more descriptive error for this specific condition */
|
||||||
return -ENAMETOOLONG;
|
return -ENAMETOOLONG;
|
||||||
|
|
||||||
/* Refuse this if this got too long or for some other reason didn't result in a valid name */
|
/* Refuse if this for some other reason didn't result in a valid name */
|
||||||
if (!unit_name_is_valid(s, UNIT_NAME_INSTANCE))
|
if (!unit_name_is_valid(s, UNIT_NAME_INSTANCE))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user