From: Lennart Poettering Date: Mon, 22 Jul 2019 11:49:17 +0000 (+0200) Subject: xattr-util: document that we NUL suffix X-Git-Tag: v243-rc1~32^2~24 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5373172e80e90c7a108693a83f2586d18e9c99b5;p=thirdparty%2Fsystemd.git xattr-util: document that we NUL suffix --- diff --git a/src/basic/xattr-util.c b/src/basic/xattr-util.c index 1d045f911b7..ab321e0293c 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;