Skip to content

Commit 82e5d8c

Browse files
arndbJames Morris
authored andcommitted
security: commoncap: fix -Wstringop-overread warning
gcc-11 introdces a harmless warning for cap_inode_getsecurity: security/commoncap.c: In function ‘cap_inode_getsecurity’: security/commoncap.c:440:33: error: ‘memcpy’ reading 16 bytes from a region of size 0 [-Werror=stringop-overread] 440 | memcpy(&nscap->data, &cap->data, sizeof(__le32) * 2 * VFS_CAP_U32); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The problem here is that tmpbuf is initialized to NULL, so gcc assumes it is not accessible unless it gets set by vfs_getxattr_alloc(). This is a legitimate warning as far as I can tell, but the code is correct since it correctly handles the error when that function fails. Add a separate NULL check to tell gcc about it as well. Signed-off-by: Arnd Bergmann <[email protected]> Acked-by: Christian Brauner <[email protected]> Signed-off-by: James Morris <[email protected]>
1 parent f40ddce commit 82e5d8c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

security/commoncap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ int cap_inode_getsecurity(struct inode *inode, const char *name, void **buffer,
391391
&tmpbuf, size, GFP_NOFS);
392392
dput(dentry);
393393

394-
if (ret < 0)
394+
if (ret < 0 || !tmpbuf)
395395
return ret;
396396

397397
fs_ns = inode->i_sb->s_user_ns;

0 commit comments

Comments
 (0)