X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fshared%2Futil.c;h=594f8de755c7a767b698187b50b67fe68e0d7185;hp=e643cd367c95b98b8f31fbe811b00b3a54370e77;hb=a740c14c59907f370a6b3a3ba5a86fada88cb07e;hpb=37d3ab1b7e114f0fb6dfb2e7273569b42794b76a diff --git a/src/shared/util.c b/src/shared/util.c index e643cd367..594f8de75 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -1325,16 +1325,24 @@ char *bus_path_escape(const char *s) { assert(s); /* Escapes all chars that D-Bus' object path cannot deal - * with. Can be reverse with bus_path_unescape() */ + * with. Can be reverse with bus_path_unescape(). We special + * case the empty string. */ - if (!(r = new(char, strlen(s)*3+1))) + if (*s == 0) + return strdup("_"); + + r = new(char, strlen(s)*3 + 1); + if (!r) return NULL; for (f = s, t = r; *f; f++) { + /* Escape everything that is not a-zA-Z0-9. We also + * escape 0-9 if it's the first character */ + if (!(*f >= 'A' && *f <= 'Z') && !(*f >= 'a' && *f <= 'z') && - !(*f >= '0' && *f <= '9')) { + !(f > s && *f >= '0' && *f <= '9')) { *(t++) = '_'; *(t++) = hexchar(*f >> 4); *(t++) = hexchar(*f); @@ -1352,7 +1360,12 @@ char *bus_path_unescape(const char *f) { assert(f); - if (!(r = strdup(f))) + /* Special case for the empty string */ + if (streq(f, "_")) + return strdup(""); + + r = new(char, strlen(f) + 1); + if (!r) return NULL; for (t = r; *f; f++) { @@ -3594,8 +3607,8 @@ void execute_directory(const char *directory, DIR *d, char *argv[]) { assert(directory); - /* Executes all binaries in a directory in parallel and waits - * until all they all finished. */ + /* Executes all binaries in a directory in parallel and + * waits for them to finish. */ if (!d) { if (!(_d = opendir(directory))) { @@ -5224,10 +5237,6 @@ int get_shell(char **_sh) { return 0; } -void freep(void *p) { - free(*(void**) p); -} - void fclosep(FILE **f) { if (*f) fclose(*f); @@ -5248,10 +5257,6 @@ void closedirp(DIR **d) { closedir(*d); } -void umaskp(mode_t *u) { - umask(*u); -} - bool filename_is_safe(const char *p) { if (isempty(p))