diff options
author | Lennart Poettering <lennart@poettering.net> | 2019-07-22 13:49:17 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2019-07-25 17:10:51 +0200 |
commit | 5373172e80e90c7a108693a83f2586d18e9c99b5 (patch) | |
tree | c8122628b4bb5ecc1fd556918ede3bafab329149 /src/basic/xattr-util.c | |
parent | 63d59b8dcf4a911703e5188bc14c39b5eea0d050 (diff) | |
download | systemd-5373172e80e90c7a108693a83f2586d18e9c99b5.tar.gz |
xattr-util: document that we NUL suffix
Diffstat (limited to 'src/basic/xattr-util.c')
-rw-r--r-- | src/basic/xattr-util.c | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/src/basic/xattr-util.c b/src/basic/xattr-util.c index 1d045f911b..ab321e0293 100644 --- a/src/basic/xattr-util.c +++ b/src/basic/xattr-util.c @@ -27,7 +27,7 @@ int getxattr_malloc(const char *path, const char *name, char **value, bool allow assert(name); assert(value); - for (l = 100; ; l = (size_t) n + 1) { + for (l = 100; ; l = (size_t) n + 1 /* extra byte to make sure this remains NUL suffixed */) { v = new0(char, l); if (!v) return -ENOMEM; @@ -36,7 +36,6 @@ int getxattr_malloc(const char *path, const char *name, char **value, bool allow n = lgetxattr(path, name, v, l); else n = getxattr(path, name, v, l); - if (n >= 0 && (size_t) n < l) { *value = v; return n; @@ -65,13 +64,12 @@ int fgetxattr_malloc(int fd, const char *name, char **value) { assert(name); assert(value); - for (l = 100; ; l = (size_t) n + 1) { + for (l = 100;; l = (size_t) n + 1 /* extra byte to make sure this remains NUL suffixed */) { v = new0(char, l); if (!v) return -ENOMEM; n = fgetxattr(fd, name, v, l); - if (n >= 0 && (size_t) n < l) { *value = v; return n; |