Make nfs_file_cred more robust.
authorNeil Brown <neilb@suse.de>
Thu, 16 Oct 2008 03:15:16 +0000 (14:15 +1100)
committerTrond Myklebust <Trond.Myklebust@netapp.com>
Fri, 17 Oct 2008 17:06:45 +0000 (13:06 -0400)
As not all files have an associated open_context (e.g. device special
files), it is safest to test for the existence of the open context
before de-referencing it.

Signed-off-by: NeilBrown <neilb@suse.de>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
fs/nfs/nfs4proc.c
include/linux/nfs_fs.h

index c910413eaecafd80ff2c6012dda6baad388cc6dd..83e700a2b0c0096d100c58a31fcf3ad0023f73b6 100644 (file)
@@ -1659,8 +1659,10 @@ nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
                struct nfs_open_context *ctx;
 
                ctx = nfs_file_open_context(sattr->ia_file);
-               cred = ctx->cred;
-               state = ctx->state;
+               if (ctx) {
+                       cred = ctx->cred;
+                       state = ctx->state;
+               }
        }
 
        status = nfs4_do_setattr(inode, cred, fattr, sattr, state);
index ac8d0233b05c00650498f92750a1b0b8db994239..4eaa8347a0d9ce08d09c7bb8436642e92c35fd0c 100644 (file)
@@ -367,8 +367,12 @@ static inline struct nfs_open_context *nfs_file_open_context(struct file *filp)
 
 static inline struct rpc_cred *nfs_file_cred(struct file *file)
 {
-       if (file != NULL)
-               return nfs_file_open_context(file)->cred;
+       if (file != NULL) {
+               struct nfs_open_context *ctx =
+                       nfs_file_open_context(file);
+               if (ctx)
+                       return ctx->cred;
+       }
        return NULL;
 }