From: Darrick J. Wong Date: Mon, 6 May 2019 22:00:20 +0000 (-0400) Subject: xfs: check attribute name validity X-Git-Tag: v5.1.0-rc0~32 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=069265796cd74ed48b64490c047d6d70402c8837;p=thirdparty%2Fxfsprogs-dev.git xfs: check attribute name validity Source kernel commit: 654805367d982cffdb9979453673aab9c3c96d07 Check extended attribute entry names for invalid characters. Signed-off-by: Darrick J. Wong Reviewed-by: Brian Foster Signed-off-by: Eric Sandeen --- diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c index 95f040b8d..b88383023 100644 --- a/libxfs/xfs_attr.c +++ b/libxfs/xfs_attr.c @@ -1331,3 +1331,20 @@ xfs_attr_node_get(xfs_da_args_t *args) xfs_da_state_free(state); return retval; } + +/* Returns true if the attribute entry name is valid. */ +bool +xfs_attr_namecheck( + const void *name, + size_t length) +{ + /* + * MAXNAMELEN includes the trailing null, but (name/length) leave it + * out, so use >= for the length check. + */ + if (length >= MAXNAMELEN) + return false; + + /* There shouldn't be any nulls here */ + return !memchr(name, 0, length); +} diff --git a/libxfs/xfs_attr.h b/libxfs/xfs_attr.h index bdf52a333..2297d8467 100644 --- a/libxfs/xfs_attr.h +++ b/libxfs/xfs_attr.h @@ -145,6 +145,6 @@ int xfs_attr_remove(struct xfs_inode *dp, const unsigned char *name, int flags); int xfs_attr_remove_args(struct xfs_da_args *args); int xfs_attr_list(struct xfs_inode *dp, char *buffer, int bufsize, int flags, struct attrlist_cursor_kern *cursor); - +bool xfs_attr_namecheck(const void *name, size_t length); #endif /* __XFS_ATTR_H__ */