summaryrefslogtreecommitdiff
path: root/src/escape/escape.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-04-30 20:21:00 +0200
committerLennart Poettering <lennart@poettering.net>2015-05-05 15:06:42 -0700
commit7410616cd9dbbec97cf98d75324da5cda2b2f7a2 (patch)
tree6d968995b3bdf961603ab4853bf078c0dbdce27c /src/escape/escape.c
parent6442185ab674cc202d63c18605057b9a51ca2722 (diff)
core: rework unit name validation and manipulation logic
A variety of changes: - Make sure all our calls distuingish OOM from other errors if OOM is not the only error possible. - Be much stricter when parsing escaped paths, do not accept trailing or leading escaped slashes. - Change unit validation to take a bit mask for allowing plain names, instance names or template names or an combination thereof. - Refuse manipulating invalid unit name
Diffstat (limited to 'src/escape/escape.c')
-rw-r--r--src/escape/escape.c40
1 files changed, 22 insertions, 18 deletions
diff --git a/src/escape/escape.c b/src/escape/escape.c
index f2a0721861..9ccb015538 100644
--- a/src/escape/escape.c
+++ b/src/escape/escape.c
@@ -99,7 +99,7 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_TEMPLATE:
- if (!unit_name_is_valid(optarg, true) || !unit_name_is_template(optarg)) {
+ if (!unit_name_is_valid(optarg, UNIT_NAME_TEMPLATE)) {
log_error("Template name %s is not valid.", optarg);
return -EINVAL;
}
@@ -166,22 +166,26 @@ int main(int argc, char *argv[]) {
switch (arg_action) {
case ACTION_ESCAPE:
- if (arg_path)
- e = unit_name_path_escape(*i);
- else
+ if (arg_path) {
+ r = unit_name_path_escape(*i, &e);
+ if (r < 0) {
+ log_error_errno(r, "Failed to escape string: %m");
+ goto finish;
+ }
+ } else {
e = unit_name_escape(*i);
-
- if (!e) {
- r = log_oom();
- goto finish;
+ if (!e) {
+ r = log_oom();
+ goto finish;
+ }
}
if (arg_template) {
char *x;
- x = unit_name_replace_instance(arg_template, e);
- if (!x) {
- r = log_oom();
+ r = unit_name_replace_instance(arg_template, e, &x);
+ if (r < 0) {
+ log_error_errno(r, "Failed to replace instance: %m");
goto finish;
}
@@ -204,20 +208,20 @@ int main(int argc, char *argv[]) {
case ACTION_UNESCAPE:
if (arg_path)
- e = unit_name_path_unescape(*i);
+ r = unit_name_path_unescape(*i, &e);
else
- e = unit_name_unescape(*i);
+ r = unit_name_unescape(*i, &e);
- if (!e) {
- r = log_oom();
+ if (r < 0) {
+ log_error_errno(r, "Failed to unescape string: %m");
goto finish;
}
break;
case ACTION_MANGLE:
- e = unit_name_mangle(*i, MANGLE_NOGLOB);
- if (!e) {
- r = log_oom();
+ r = unit_name_mangle(*i, UNIT_NAME_NOGLOB, &e);
+ if (r < 0) {
+ log_error_errno(r, "Failed to mangle name: %m");
goto finish;
}
break;