cluster-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
* [Cluster-devel] [PATCH v1] fs:dlm:Fix potential null pointer dereference on pointer
@ 2023-06-16  2:48 Wang Ming
  2023-06-16  6:15 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Wang Ming @ 2023-06-16  2:48 UTC (permalink / raw)
  To: cluster-devel.redhat.com

Before dereferencing the pointer, first judge whether
it is NULL, if it is NULL, there is no need to dereference.
Fix the following coccicheck ERROR:

fs/dlm/lowcomms.c:1082:26-28: ERROR: newcon -> sock is NULL
but dereferenced.

Signed-off-by: Wang Ming <machel@vivo.com>
---
 fs/dlm/lowcomms.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/fs/dlm/lowcomms.c b/fs/dlm/lowcomms.c
index 3d3802c47..0a2d1b5ab 100644
--- a/fs/dlm/lowcomms.c
+++ b/fs/dlm/lowcomms.c
@@ -1079,7 +1079,18 @@ static int accept_from_sock(void)
        sock_set_mark(newsock->sk, mark);

        down_write(&newcon->sock_lock);
-       if (newcon->sock) {
+       if (newcon->sock == NULL) {
+               /*  accept copies the sk after we've saved the callbacks, so we
+                *  don't want to save them a second time or comm errors will
+                *  result in calling sk_error_report recursively.
+                */
+               add_sock(newsock, newcon);
+
+               /* check if we receved something while adding */
+               lock_sock(newcon->sock->sk);
+               lowcomms_queue_rwork(newcon);
+               release_sock(newcon->sock->sk);
+       } else {
                struct connection *othercon = newcon->othercon;

                if (!othercon) {
@@ -1110,17 +1121,7 @@ static int accept_from_sock(void)
                release_sock(othercon->sock->sk);
                up_write(&othercon->sock_lock);
        }
-       else {
-               /* accept copies the sk after we've saved the callbacks, so we
-                  don't want to save them a second time or comm errors will
-                  result in calling sk_error_report recursively. */
-               add_sock(newsock, newcon);

-               /* check if we receved something while adding */
-               lock_sock(newcon->sock->sk);
-               lowcomms_queue_rwork(newcon);
-               release_sock(newcon->sock->sk);
-       }
        up_write(&newcon->sock_lock);
        srcu_read_unlock(&connections_srcu, idx);

--
2.25.1


________________________________
????????????????/??????????????????????????????????????????????????????????????????????????????????????????????????????????
The contents of this message and any attachments may contain confidential and/or privileged information and are intended exclusively for the addressee(s). If you are not the intended recipient of this message or their agent, please note that any use, dissemination, copying, or storage of this message or its attachments is not allowed. If you receive this message in error, please notify the sender by reply the message or phone and delete this message, any attachments and any copies immediately.
Thank you


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-06-16  6:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-16  2:48 [Cluster-devel] [PATCH v1] fs:dlm:Fix potential null pointer dereference on pointer Wang Ming
2023-06-16  6:15 ` Greg KH

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).