summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mack <zonque@gmail.com>2014-08-19 21:09:16 +0200
committerDaniel Mack <zonque@gmail.com>2014-08-19 21:49:05 +0200
commit8f2807bab569b27eae5459854a48cdd4dead4d2c (patch)
treea69e12dc60ee2d7c9a38b87bb0df3c5c721963bc
parent4531a9bc206c0c22e29b56ac4a7528afba2e9c83 (diff)
memfd: reduce name escaping logic to utf-8 checks
As memfds are now created by proper kernel API, and not by our functions, we can't rely on names being escaped/unescaped according to our current logic. Thus, the only safe way is to remove the escaping and when reading names, just escape names that are not properly encoded in UTF-8. Also, remove assert(name) lines from the memfd creation functions, as we explictly allow name to be NULL.
-rw-r--r--src/shared/memfd.c15
1 files changed, 4 insertions, 11 deletions
diff --git a/src/shared/memfd.c b/src/shared/memfd.c
index 6e2319d6ee..e335c0c18b 100644
--- a/src/shared/memfd.c
+++ b/src/shared/memfd.c
@@ -29,25 +29,19 @@
#include "bus-label.h"
#include "missing.h"
#include "memfd.h"
+#include "utf8.h"
int memfd_new(const char *name) {
_cleanup_free_ char *g = NULL;
int fd;
- assert(name);
-
if (name) {
- /* The kernel side is pretty picky about the character
- * set here, let's do the usual bus escaping to deal
- * with that. */
-
- g = bus_label_escape(name);
+ g = utf8_escape_invalid(name);
if (!g)
return -ENOMEM;
name = g;
-
} else {
char pr[17] = {};
@@ -62,7 +56,7 @@ int memfd_new(const char *name) {
else {
_cleanup_free_ char *e = NULL;
- e = bus_label_escape(pr);
+ e = utf8_escape_invalid(pr);
if (!e)
return -ENOMEM;
@@ -161,7 +155,6 @@ int memfd_new_and_map(const char *name, size_t sz, void **p) {
_cleanup_close_ int fd = -1;
int r;
- assert(name);
assert(sz > 0);
assert(p);
@@ -221,7 +214,7 @@ int memfd_get_name(int fd, char **name) {
if (!n)
return -ENOMEM;
- e = bus_label_unescape(n);
+ e = utf8_escape_invalid(n);
if (!e)
return -ENOMEM;