LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [RFC 1/1 linux-next] fs/hfsplus: use kasprintf instead of kmalloc/strcpy.
@ 2015-03-09 19:11 Fabian Frederick
0 siblings, 0 replies; only message in thread
From: Fabian Frederick @ 2015-03-09 19:11 UTC (permalink / raw)
To: linux-kernel; +Cc: Fabian Frederick, Andrew Morton
This patch removes prefixlen from all getxattr/setxattr callsites and
maximum attribute preallocation.
It's an RFC because it could bring a memory leak somewhere if attribute
is stored on the old preallocation basis and I don't know the code enough
to evaluate the risk.
Suggested-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Fabian Frederick <fabf@skynet.be>
---
fs/hfsplus/xattr.c | 21 +++++++--------------
fs/hfsplus/xattr.h | 4 ++--
fs/hfsplus/xattr_security.c | 6 ++----
fs/hfsplus/xattr_trusted.c | 5 ++---
fs/hfsplus/xattr_user.c | 4 ++--
5 files changed, 15 insertions(+), 25 deletions(-)
diff --git a/fs/hfsplus/xattr.c b/fs/hfsplus/xattr.c
index 16f545d..99d84fa 100644
--- a/fs/hfsplus/xattr.c
+++ b/fs/hfsplus/xattr.c
@@ -426,7 +426,7 @@ static int copy_name(char *buffer, const char *xattr_name, int name_len)
int hfsplus_setxattr(struct dentry *dentry, const char *name,
const void *value, size_t size, int flags,
- const char *prefix, size_t prefixlen)
+ const char *prefix)
{
char *xattr_name;
int res;
@@ -434,12 +434,10 @@ int hfsplus_setxattr(struct dentry *dentry, const char *name,
if (!strcmp(name, ""))
return -EINVAL;
- xattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + 1,
- GFP_KERNEL);
+ xattr_name = kasprintf(GFP_KERNEL, "%s%s", prefix, name);
if (!xattr_name)
return -ENOMEM;
- strcpy(xattr_name, prefix);
- strcpy(xattr_name + prefixlen, name);
+
res = __hfsplus_setxattr(dentry->d_inode, xattr_name, value, size,
flags);
kfree(xattr_name);
@@ -584,7 +582,7 @@ failed_getxattr_init:
ssize_t hfsplus_getxattr(struct dentry *dentry, const char *name,
void *value, size_t size,
- const char *prefix, size_t prefixlen)
+ const char *prefix)
{
int res;
char *xattr_name;
@@ -592,14 +590,10 @@ ssize_t hfsplus_getxattr(struct dentry *dentry, const char *name,
if (!strcmp(name, ""))
return -EINVAL;
- xattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + 1,
- GFP_KERNEL);
+ xattr_name = kasprintf(GFP_KERNEL, "%s%s", prefix, name);
if (!xattr_name)
return -ENOMEM;
- strcpy(xattr_name, prefix);
- strcpy(xattr_name + prefixlen, name);
-
res = __hfsplus_getxattr(dentry->d_inode, xattr_name, value, size);
kfree(xattr_name);
return res;
@@ -863,7 +857,7 @@ static int hfsplus_osx_getxattr(struct dentry *dentry, const char *name,
return -EOPNOTSUPP;
return hfsplus_getxattr(dentry, name, buffer, size,
- XATTR_MAC_OSX_PREFIX, XATTR_MAC_OSX_PREFIX_LEN);
+ XATTR_MAC_OSX_PREFIX);
}
static int hfsplus_osx_setxattr(struct dentry *dentry, const char *name,
@@ -880,8 +874,7 @@ static int hfsplus_osx_setxattr(struct dentry *dentry, const char *name,
return -EOPNOTSUPP;
return hfsplus_setxattr(dentry, name, buffer, size, flags,
- XATTR_MAC_OSX_PREFIX,
- XATTR_MAC_OSX_PREFIX_LEN);
+ XATTR_MAC_OSX_PREFIX);
}
static size_t hfsplus_osx_listxattr(struct dentry *dentry, char *list,
diff --git a/fs/hfsplus/xattr.h b/fs/hfsplus/xattr.h
index f9b0955..fa637ab 100644
--- a/fs/hfsplus/xattr.h
+++ b/fs/hfsplus/xattr.h
@@ -23,14 +23,14 @@ int __hfsplus_setxattr(struct inode *inode, const char *name,
int hfsplus_setxattr(struct dentry *dentry, const char *name,
const void *value, size_t size, int flags,
- const char *prefix, size_t prefixlen);
+ const char *prefix);
ssize_t __hfsplus_getxattr(struct inode *inode, const char *name,
void *value, size_t size);
ssize_t hfsplus_getxattr(struct dentry *dentry, const char *name,
void *value, size_t size,
- const char *prefix, size_t prefixlen);
+ const char *prefix);
ssize_t hfsplus_listxattr(struct dentry *dentry, char *buffer, size_t size);
diff --git a/fs/hfsplus/xattr_security.c b/fs/hfsplus/xattr_security.c
index aacff00..d19d626 100644
--- a/fs/hfsplus/xattr_security.c
+++ b/fs/hfsplus/xattr_security.c
@@ -17,16 +17,14 @@ static int hfsplus_security_getxattr(struct dentry *dentry, const char *name,
void *buffer, size_t size, int type)
{
return hfsplus_getxattr(dentry, name, buffer, size,
- XATTR_SECURITY_PREFIX,
- XATTR_SECURITY_PREFIX_LEN);
+ XATTR_SECURITY_PREFIX);
}
static int hfsplus_security_setxattr(struct dentry *dentry, const char *name,
const void *buffer, size_t size, int flags, int type)
{
return hfsplus_setxattr(dentry, name, buffer, size, flags,
- XATTR_SECURITY_PREFIX,
- XATTR_SECURITY_PREFIX_LEN);
+ XATTR_SECURITY_PREFIX);
}
static size_t hfsplus_security_listxattr(struct dentry *dentry, char *list,
diff --git a/fs/hfsplus/xattr_trusted.c b/fs/hfsplus/xattr_trusted.c
index bcf6508..6aad192 100644
--- a/fs/hfsplus/xattr_trusted.c
+++ b/fs/hfsplus/xattr_trusted.c
@@ -15,15 +15,14 @@ static int hfsplus_trusted_getxattr(struct dentry *dentry, const char *name,
void *buffer, size_t size, int type)
{
return hfsplus_getxattr(dentry, name, buffer, size,
- XATTR_TRUSTED_PREFIX,
- XATTR_TRUSTED_PREFIX_LEN);
+ XATTR_TRUSTED_PREFIX);
}
static int hfsplus_trusted_setxattr(struct dentry *dentry, const char *name,
const void *buffer, size_t size, int flags, int type)
{
return hfsplus_setxattr(dentry, name, buffer, size, flags,
- XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN);
+ XATTR_TRUSTED_PREFIX);
}
static size_t hfsplus_trusted_listxattr(struct dentry *dentry, char *list,
diff --git a/fs/hfsplus/xattr_user.c b/fs/hfsplus/xattr_user.c
index 5aa0e6d..8c86183 100644
--- a/fs/hfsplus/xattr_user.c
+++ b/fs/hfsplus/xattr_user.c
@@ -16,14 +16,14 @@ static int hfsplus_user_getxattr(struct dentry *dentry, const char *name,
{
return hfsplus_getxattr(dentry, name, buffer, size,
- XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN);
+ XATTR_USER_PREFIX);
}
static int hfsplus_user_setxattr(struct dentry *dentry, const char *name,
const void *buffer, size_t size, int flags, int type)
{
return hfsplus_setxattr(dentry, name, buffer, size, flags,
- XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN);
+ XATTR_USER_PREFIX);
}
static size_t hfsplus_user_listxattr(struct dentry *dentry, char *list,
--
1.9.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2015-03-09 19:12 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-09 19:11 [RFC 1/1 linux-next] fs/hfsplus: use kasprintf instead of kmalloc/strcpy Fabian Frederick
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).