Skip to contentSkip to conversation

cifs: improve symlink handling for smb2+

bug report New Dan Carpenter 2 participants 2 messages Oct 14, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hello Paulo Alcantara,

This is a semi-automatic email about new static checker warnings.

The patch d87ee26fa912: "cifs: improve symlink handling for smb2+" from Oct 3, 2022, leads to the following Smatch complaint:

    fs/cifs/smb2file.c:126 smb2_open_file()
    warn: variable dereferenced before check 'oparms->cifs_sb' (see line 112)

fs/cifs/smb2file.c
111

   112		smb2_path = cifs_convert_path_to_utf16(oparms->path, oparms->cifs_sb);
                                                                     ^^^^^^^^^^^^^^^

The existing code dereferences "oparms->cifs_sb" without checking for NULL

113 if (smb2_path == NULL)
114 return -ENOMEM;
115
116 oparms->desired_access |= FILE_READ_ATTRIBUTES;
117 smb2_oplock = SMB2_OPLOCK_LEVEL_BATCH;
118
119 rc = SMB2_open(xid, oparms, smb2_path, &smb2_oplock, smb2_data, NULL, &err_iov,
120 &err_buftype);
121 if (rc && data) {
122 struct smb2_hdr *hdr = err_iov.iov_base;
123
124 if (unlikely(!err_iov.iov_base || err_buftype == CIFS_NO_BUFFER))
125 rc = -ENOMEM;

   126			else if (hdr->Status == STATUS_STOPPED_ON_SYMLINK && oparms->cifs_sb) {
                                                                             ^^^^^^^^^^^^^^^

so presumably this new NULL check can be deleted as well.

127 rc = smb2_parse_symlink_response(oparms->cifs_sb, &err_iov,
128 &data->symlink_target);

regards,
dan carpenter

#1 lore raw

PATCH 1/1 cifs: fix static checker warning

Remove unnecessary NULL check of oparam->cifs_sb when parsing symlink error response as it's already set by all smb2_open_file() callers and deferenced earlier.

This fixes below report:

fs/cifs/smb2file.c:126 smb2_open_file()
warn: variable dereferenced before check 'oparms->cifs_sb' (see line 112)

---
 fs/cifs/smb2file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/cifs/smb2file.c +1 -1
index 4992b43616a7..ffbd9a99fc12 100644
@@ -123,7 +123,7 @@ int smb2_open_file(const unsigned int xid, struct cifs_open_parms *oparms, __u32
 
 		if (unlikely(!err_iov.iov_base || err_buftype == CIFS_NO_BUFFER))
 			rc = -ENOMEM;
-		else if (hdr->Status == STATUS_STOPPED_ON_SYMLINK && oparms->cifs_sb) {
+		else if (hdr->Status == STATUS_STOPPED_ON_SYMLINK) {
 			rc = smb2_parse_symlink_response(oparms->cifs_sb, &err_iov,
 							 &data->symlink_target);
 			if (!rc) {
Signature · 1 line
2.37.3