mirror of https://gitee.com/openkylin/linux.git
9p: fix misuse of sscanf() in v9fs_stat2inode()
1) sscanf() return value needs to be checked, damnit 2) sscanf() is perfectly capable of checking for fixed prefix, no need for that %13s + strncmp with constant string. 3) st->extension is a valid string; no need for voodoo with str*cpy() there. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
parent
b1adbdbda4
commit
9652c73246
|
@ -1137,9 +1137,6 @@ v9fs_stat2inode(struct p9_wstat *stat, struct inode *inode,
|
||||||
struct super_block *sb, unsigned int flags)
|
struct super_block *sb, unsigned int flags)
|
||||||
{
|
{
|
||||||
umode_t mode;
|
umode_t mode;
|
||||||
char ext[32];
|
|
||||||
char tag_name[14];
|
|
||||||
unsigned int i_nlink;
|
|
||||||
struct v9fs_session_info *v9ses = sb->s_fs_info;
|
struct v9fs_session_info *v9ses = sb->s_fs_info;
|
||||||
struct v9fs_inode *v9inode = V9FS_I(inode);
|
struct v9fs_inode *v9inode = V9FS_I(inode);
|
||||||
|
|
||||||
|
@ -1157,18 +1154,18 @@ v9fs_stat2inode(struct p9_wstat *stat, struct inode *inode,
|
||||||
inode->i_gid = stat->n_gid;
|
inode->i_gid = stat->n_gid;
|
||||||
}
|
}
|
||||||
if ((S_ISREG(inode->i_mode)) || (S_ISDIR(inode->i_mode))) {
|
if ((S_ISREG(inode->i_mode)) || (S_ISDIR(inode->i_mode))) {
|
||||||
if (v9fs_proto_dotu(v9ses) && (stat->extension[0] != '\0')) {
|
if (v9fs_proto_dotu(v9ses)) {
|
||||||
|
unsigned int i_nlink;
|
||||||
/*
|
/*
|
||||||
* Hadlink support got added later to
|
* Hadlink support got added later to the .u extension.
|
||||||
* to the .u extension. So there can be
|
* So there can be a server out there that doesn't
|
||||||
* server out there that doesn't support
|
* support this even with .u extension. That would
|
||||||
* this even with .u extension. So check
|
* just leave us with stat->extension being an empty
|
||||||
* for non NULL stat->extension
|
* string, though.
|
||||||
*/
|
*/
|
||||||
strlcpy(ext, stat->extension, sizeof(ext));
|
|
||||||
/* HARDLINKCOUNT %u */
|
/* HARDLINKCOUNT %u */
|
||||||
sscanf(ext, "%13s %u", tag_name, &i_nlink);
|
if (sscanf(stat->extension,
|
||||||
if (!strncmp(tag_name, "HARDLINKCOUNT", 13))
|
" HARDLINKCOUNT %u", &i_nlink) == 1)
|
||||||
set_nlink(inode, i_nlink);
|
set_nlink(inode, i_nlink);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue