mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-03 01:17:45 +03:00
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.
This commit is contained in:
parent
4531a9bc20
commit
8f2807bab5
@ -29,25 +29,19 @@
|
|||||||
#include "bus-label.h"
|
#include "bus-label.h"
|
||||||
#include "missing.h"
|
#include "missing.h"
|
||||||
#include "memfd.h"
|
#include "memfd.h"
|
||||||
|
#include "utf8.h"
|
||||||
|
|
||||||
int memfd_new(const char *name) {
|
int memfd_new(const char *name) {
|
||||||
|
|
||||||
_cleanup_free_ char *g = NULL;
|
_cleanup_free_ char *g = NULL;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
assert(name);
|
|
||||||
|
|
||||||
if (name) {
|
if (name) {
|
||||||
/* The kernel side is pretty picky about the character
|
g = utf8_escape_invalid(name);
|
||||||
* set here, let's do the usual bus escaping to deal
|
|
||||||
* with that. */
|
|
||||||
|
|
||||||
g = bus_label_escape(name);
|
|
||||||
if (!g)
|
if (!g)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
name = g;
|
name = g;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
char pr[17] = {};
|
char pr[17] = {};
|
||||||
|
|
||||||
@ -62,7 +56,7 @@ int memfd_new(const char *name) {
|
|||||||
else {
|
else {
|
||||||
_cleanup_free_ char *e = NULL;
|
_cleanup_free_ char *e = NULL;
|
||||||
|
|
||||||
e = bus_label_escape(pr);
|
e = utf8_escape_invalid(pr);
|
||||||
if (!e)
|
if (!e)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
@ -161,7 +155,6 @@ int memfd_new_and_map(const char *name, size_t sz, void **p) {
|
|||||||
_cleanup_close_ int fd = -1;
|
_cleanup_close_ int fd = -1;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
assert(name);
|
|
||||||
assert(sz > 0);
|
assert(sz > 0);
|
||||||
assert(p);
|
assert(p);
|
||||||
|
|
||||||
@ -221,7 +214,7 @@ int memfd_get_name(int fd, char **name) {
|
|||||||
if (!n)
|
if (!n)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
e = bus_label_unescape(n);
|
e = utf8_escape_invalid(n);
|
||||||
if (!e)
|
if (!e)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user