Skip to content

Commit 9652c73

Browse files
author
Al Viro
committed
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>
1 parent b1adbdb commit 9652c73

1 file changed

Lines changed: 9 additions & 12 deletions

File tree

fs/9p/vfs_inode.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,9 +1137,6 @@ v9fs_stat2inode(struct p9_wstat *stat, struct inode *inode,
11371137
struct super_block *sb, unsigned int flags)
11381138
{
11391139
umode_t mode;
1140-
char ext[32];
1141-
char tag_name[14];
1142-
unsigned int i_nlink;
11431140
struct v9fs_session_info *v9ses = sb->s_fs_info;
11441141
struct v9fs_inode *v9inode = V9FS_I(inode);
11451142

@@ -1157,18 +1154,18 @@ v9fs_stat2inode(struct p9_wstat *stat, struct inode *inode,
11571154
inode->i_gid = stat->n_gid;
11581155
}
11591156
if ((S_ISREG(inode->i_mode)) || (S_ISDIR(inode->i_mode))) {
1160-
if (v9fs_proto_dotu(v9ses) && (stat->extension[0] != '\0')) {
1157+
if (v9fs_proto_dotu(v9ses)) {
1158+
unsigned int i_nlink;
11611159
/*
1162-
* Hadlink support got added later to
1163-
* to the .u extension. So there can be
1164-
* server out there that doesn't support
1165-
* this even with .u extension. So check
1166-
* for non NULL stat->extension
1160+
* Hadlink support got added later to the .u extension.
1161+
* So there can be a server out there that doesn't
1162+
* support this even with .u extension. That would
1163+
* just leave us with stat->extension being an empty
1164+
* string, though.
11671165
*/
1168-
strlcpy(ext, stat->extension, sizeof(ext));
11691166
/* HARDLINKCOUNT %u */
1170-
sscanf(ext, "%13s %u", tag_name, &i_nlink);
1171-
if (!strncmp(tag_name, "HARDLINKCOUNT", 13))
1167+
if (sscanf(stat->extension,
1168+
" HARDLINKCOUNT %u", &i_nlink) == 1)
11721169
set_nlink(inode, i_nlink);
11731170
}
11741171
}

0 commit comments

Comments
 (0)