From 938730662dd2ec407c28380de66c3053f05e3159 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 1 Jan 2023 13:30:19 +0100 Subject: Fix accessing cred before checking it is non-NULL --- libdiskfs/file-lock.c | 3 ++- libnetfs/file-lock.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/libdiskfs/file-lock.c b/libdiskfs/file-lock.c index b95c3f0c..0446fc3d 100644 --- a/libdiskfs/file-lock.c +++ b/libdiskfs/file-lock.c @@ -27,7 +27,7 @@ diskfs_S_file_lock (struct protid *cred, int flags) error_t err; struct flock64 lock; struct node *node; - int openstat = cred->po->openstat; + int openstat; mach_port_t rendezvous = MACH_PORT_NULL; if (! cred) @@ -51,6 +51,7 @@ diskfs_S_file_lock (struct protid *cred, int flags) From flock(2): A shared or exclusive lock can be placed on a file regardless of the mode in which the file was opened. */ + openstat = cred->po->openstat; if (openstat & (O_RDONLY|O_WRONLY|O_EXEC)) openstat |= O_RDONLY|O_WRONLY; node = cred->po->np; diff --git a/libnetfs/file-lock.c b/libnetfs/file-lock.c index 7bb81d43..2aa28458 100644 --- a/libnetfs/file-lock.c +++ b/libnetfs/file-lock.c @@ -30,7 +30,7 @@ netfs_S_file_lock (struct protid *user, error_t err; struct flock64 lock; struct node *node; - int openstat = user->po->openstat; + int openstat; mach_port_t rendezvous = MACH_PORT_NULL; if (!user) @@ -54,6 +54,7 @@ netfs_S_file_lock (struct protid *user, From flock(2): A shared or exclusive lock can be placed on a file regardless of the mode in which the file was opened. */ + openstat = user->po->openstat; if (openstat & (O_RDONLY|O_WRONLY|O_EXEC)) openstat |= O_RDONLY|O_WRONLY; node = user->po->np; -- cgit v1.2.3