Skip to content

Commit 2e2fae9

Browse files
salyzyndhowells
authored andcommitted
afs: xattr: use scnprintf
sprintf and snprintf are fragile in future maintenance, switch to using scnprintf to ensure no accidental Use After Free conditions are introduced. Signed-off-by: Mark Salyzyn <[email protected]> Cc: [email protected] Cc: [email protected] Cc: David Howells <[email protected]> Cc: [email protected] Cc: Jan Kara <[email protected]> Signed-off-by: David Howells <[email protected]>
1 parent d4438a2 commit 2e2fae9

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

fs/afs/xattr.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,11 @@ static int afs_xattr_get_yfs(const struct xattr_handler *handler,
228228
break;
229229
case 1:
230230
data = buf;
231-
dsize = snprintf(buf, sizeof(buf), "%u", yacl->inherit_flag);
231+
dsize = scnprintf(buf, sizeof(buf), "%u", yacl->inherit_flag);
232232
break;
233233
case 2:
234234
data = buf;
235-
dsize = snprintf(buf, sizeof(buf), "%u", yacl->num_cleaned);
235+
dsize = scnprintf(buf, sizeof(buf), "%u", yacl->num_cleaned);
236236
break;
237237
case 3:
238238
data = yacl->vol_acl->data;
@@ -370,13 +370,15 @@ static int afs_xattr_get_fid(const struct xattr_handler *handler,
370370
/* The volume ID is 64-bit, the vnode ID is 96-bit and the
371371
* uniquifier is 32-bit.
372372
*/
373-
len = sprintf(text, "%llx:", vnode->fid.vid);
373+
len = scnprintf(text, sizeof(text), "%llx:", vnode->fid.vid);
374374
if (vnode->fid.vnode_hi)
375-
len += sprintf(text + len, "%x%016llx",
376-
vnode->fid.vnode_hi, vnode->fid.vnode);
375+
len += scnprintf(text + len, sizeof(text) - len, "%x%016llx",
376+
vnode->fid.vnode_hi, vnode->fid.vnode);
377377
else
378-
len += sprintf(text + len, "%llx", vnode->fid.vnode);
379-
len += sprintf(text + len, ":%x", vnode->fid.unique);
378+
len += scnprintf(text + len, sizeof(text) - len, "%llx",
379+
vnode->fid.vnode);
380+
len += scnprintf(text + len, sizeof(text) - len, ":%x",
381+
vnode->fid.unique);
380382

381383
if (size == 0)
382384
return len;

0 commit comments

Comments
 (0)