2009-12-21 11:55:08

by liu weni

[permalink] [raw]
Subject: [PATCHv2 06/12]posix_acl: Add the check items

move the ACL validation check in to fs/posix_acl.c.
Including nullpointer check and PTR_ERR check.

---
Signed-off-by: Liuwenyi <[email protected]>
Cc: Alexander Viro <[email protected]>
Cc: Christoph Hellwig <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
diff --git a/fs/generic_acl.c b/fs/generic_acl.c
index 5545803..5d88218 100644
--- a/fs/generic_acl.c
+++ b/fs/generic_acl.c
@@ -68,6 +68,7 @@ generic_acl_set(struct dentry *dentry, const char
*name, const void *value,
struct inode *inode = dentry->d_inode;
struct posix_acl *acl = NULL;
int error;
+ mode_t mode;

if (strcmp(name, "") != 0)
return -EINVAL;
@@ -80,32 +81,31 @@ generic_acl_set(struct dentry *dentry, const char
*name, const void *value,
if (IS_ERR(acl))
return PTR_ERR(acl);
}
- if (acl) {
- mode_t mode;

- error = posix_acl_valid(acl);
- if (error)
+ error = posix_acl_valid(acl);
+ if (error)
+ goto failed;
+
+ switch (type) {
+ case ACL_TYPE_ACCESS:
+ mode = inode->i_mode;
+ error = posix_acl_equiv_mode(acl, &mode);
+ if (error < 0)
goto failed;
- switch (type) {
- case ACL_TYPE_ACCESS:
- mode = inode->i_mode;
- error = posix_acl_equiv_mode(acl, &mode);
- if (error < 0)
- goto failed;
- inode->i_mode = mode;
- if (error == 0) {
- posix_acl_release(acl);
- acl = NULL;
- }
- break;
- case ACL_TYPE_DEFAULT:
- if (!S_ISDIR(inode->i_mode)) {
- error = -EINVAL;
- goto failed;
- }
- break;
+ inode->i_mode = mode;
+ if (error == 0) {
+ posix_acl_release(acl);
+ acl = NULL;
}
+ break;
+ case ACL_TYPE_DEFAULT:
+ if (!S_ISDIR(inode->i_mode)) {
+ error = -EINVAL;
+ goto failed;
+ }
+ break;
}
+
set_cached_acl(inode, type, acl);
error = 0;
failed:

--
Best Regards,
Liuwenyi