Skip to content

Commit 352f2c9

Browse files
aaptelsmfrench
authored andcommitted
cifs: cifsroot: add more err checking
make cifs more verbose about buffer size errors and add some comments Signed-off-by: Aurelien Aptel <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent c349818 commit 352f2c9

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

fs/cifs/cifsroot.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ static char root_opts[1024] __initdata = DEFAULT_MNT_OPTS;
2424

2525
static __be32 __init parse_srvaddr(char *start, char *end)
2626
{
27+
/* TODO: ipv6 support */
2728
char addr[sizeof("aaa.bbb.ccc.ddd")];
2829
int i = 0;
2930

@@ -50,14 +51,24 @@ static int __init cifs_root_setup(char *line)
5051
if (!s || s[1] == '\0')
5152
return 1;
5253

54+
/* make s point to ',' or '\0' at end of line */
5355
s = strchrnul(s, ',');
56+
/* len is strlen(unc) + '\0' */
5457
len = s - line + 1;
55-
if (len <= sizeof(root_dev)) {
56-
strlcpy(root_dev, line, len);
57-
srvaddr = parse_srvaddr(&line[2], s);
58-
if (*s) {
59-
snprintf(root_opts, sizeof(root_opts), "%s,%s",
58+
if (len > sizeof(root_dev)) {
59+
printk(KERN_ERR "Root-CIFS: UNC path too long\n");
60+
return 1;
61+
}
62+
strlcpy(root_dev, line, len);
63+
srvaddr = parse_srvaddr(&line[2], s);
64+
if (*s) {
65+
int n = snprintf(root_opts,
66+
sizeof(root_opts), "%s,%s",
6067
DEFAULT_MNT_OPTS, s + 1);
68+
if (n >= sizeof(root_opts)) {
69+
printk(KERN_ERR "Root-CIFS: mount options string too long\n");
70+
root_opts[sizeof(root_opts)-1] = '\0';
71+
return 1;
6172
}
6273
}
6374
}

0 commit comments

Comments
 (0)