mirror of
https://github.com/systemd/systemd.git
synced 2025-01-11 09:18:07 +03:00
udev: move util_path_encode() and rename it to escape_path()
This commit is contained in:
parent
5953d8b910
commit
9a56b87717
@ -75,40 +75,6 @@ int util_resolve_subsys_kernel(const char *string, char *result, size_t maxsize,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t util_path_encode(const char *src, char *dest, size_t size) {
|
|
||||||
size_t i, j;
|
|
||||||
|
|
||||||
assert(src);
|
|
||||||
assert(dest);
|
|
||||||
|
|
||||||
for (i = 0, j = 0; src[i] != '\0'; i++) {
|
|
||||||
if (src[i] == '/') {
|
|
||||||
if (j+4 >= size) {
|
|
||||||
j = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
memcpy(&dest[j], "\\x2f", 4);
|
|
||||||
j += 4;
|
|
||||||
} else if (src[i] == '\\') {
|
|
||||||
if (j+4 >= size) {
|
|
||||||
j = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
memcpy(&dest[j], "\\x5c", 4);
|
|
||||||
j += 4;
|
|
||||||
} else {
|
|
||||||
if (j+1 >= size) {
|
|
||||||
j = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
dest[j] = src[i];
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dest[j] = '\0';
|
|
||||||
return j;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* allow chars in allow list, plain ascii, hex-escaping and valid utf8 */
|
/* allow chars in allow list, plain ascii, hex-escaping and valid utf8 */
|
||||||
size_t util_replace_chars(char *str, const char *allow) {
|
size_t util_replace_chars(char *str, const char *allow) {
|
||||||
size_t i = 0, replaced = 0;
|
size_t i = 0, replaced = 0;
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
#define UTIL_NAME_SIZE 512
|
#define UTIL_NAME_SIZE 512
|
||||||
#define UTIL_LINE_SIZE 16384
|
#define UTIL_LINE_SIZE 16384
|
||||||
#define UDEV_ALLOWED_CHARS_INPUT "/ $%?,"
|
#define UDEV_ALLOWED_CHARS_INPUT "/ $%?,"
|
||||||
size_t util_path_encode(const char *src, char *dest, size_t size);
|
|
||||||
size_t util_replace_chars(char *str, const char *white);
|
size_t util_replace_chars(char *str, const char *white);
|
||||||
int util_resolve_subsys_kernel(const char *string, char *result, size_t maxsize, bool read_value);
|
int util_resolve_subsys_kernel(const char *string, char *result, size_t maxsize, bool read_value);
|
||||||
|
|
||||||
|
@ -192,6 +192,40 @@ static int link_find_prioritized(sd_device *dev, bool add, const char *stackdir,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static size_t escape_path(const char *src, char *dest, size_t size) {
|
||||||
|
size_t i, j;
|
||||||
|
|
||||||
|
assert(src);
|
||||||
|
assert(dest);
|
||||||
|
|
||||||
|
for (i = 0, j = 0; src[i] != '\0'; i++) {
|
||||||
|
if (src[i] == '/') {
|
||||||
|
if (j+4 >= size) {
|
||||||
|
j = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
memcpy(&dest[j], "\\x2f", 4);
|
||||||
|
j += 4;
|
||||||
|
} else if (src[i] == '\\') {
|
||||||
|
if (j+4 >= size) {
|
||||||
|
j = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
memcpy(&dest[j], "\\x5c", 4);
|
||||||
|
j += 4;
|
||||||
|
} else {
|
||||||
|
if (j+1 >= size) {
|
||||||
|
j = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
dest[j] = src[i];
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dest[j] = '\0';
|
||||||
|
return j;
|
||||||
|
}
|
||||||
|
|
||||||
/* manage "stack of names" with possibly specified device priorities */
|
/* manage "stack of names" with possibly specified device priorities */
|
||||||
static int link_update(sd_device *dev, const char *slink, bool add) {
|
static int link_update(sd_device *dev, const char *slink, bool add) {
|
||||||
_cleanup_free_ char *target = NULL, *filename = NULL, *dirname = NULL;
|
_cleanup_free_ char *target = NULL, *filename = NULL, *dirname = NULL;
|
||||||
@ -206,7 +240,7 @@ static int link_update(sd_device *dev, const char *slink, bool add) {
|
|||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_device_debug_errno(dev, r, "Failed to get id_filename: %m");
|
return log_device_debug_errno(dev, r, "Failed to get id_filename: %m");
|
||||||
|
|
||||||
util_path_encode(slink + STRLEN("/dev"), name_enc, sizeof(name_enc));
|
escape_path(slink + STRLEN("/dev"), name_enc, sizeof(name_enc));
|
||||||
dirname = path_join("/run/udev/links/", name_enc);
|
dirname = path_join("/run/udev/links/", name_enc);
|
||||||
if (!dirname)
|
if (!dirname)
|
||||||
return log_oom();
|
return log_oom();
|
||||||
|
Loading…
Reference in New Issue
Block a user