fs:dlm:Fix potential null pointer dereference on pointer
PATCH 1/1 fs:dlm:Fix potential null pointer dereference on pointer
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.
--- fs/dlm/lowcomms.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-)
fs/dlm/lowcomms.c +12 -11
@@ -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
Quoted 4 lines · Wang Ming
________________________________
????????????????/??????????????????????????????????????????????????????????????????????????????????????????????????????????
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
Now deleted.