Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

cifs: cifsroot: add more err checking

make cifs more verbose about buffer size errors
and add some comments

Signed-off-by: Aurelien Aptel <aaptel@suse.com>
Signed-off-by: Steve French <stfrench@microsoft.com>

authored by

Aurelien Aptel and committed by
Steve French
352f2c9a c3498185

+16 -5
+16 -5
fs/cifs/cifsroot.c
··· 24 24 25 25 static __be32 __init parse_srvaddr(char *start, char *end) 26 26 { 27 + /* TODO: ipv6 support */ 27 28 char addr[sizeof("aaa.bbb.ccc.ddd")]; 28 29 int i = 0; 29 30 ··· 51 50 if (!s || s[1] == '\0') 52 51 return 1; 53 52 53 + /* make s point to ',' or '\0' at end of line */ 54 54 s = strchrnul(s, ','); 55 + /* len is strlen(unc) + '\0' */ 55 56 len = s - line + 1; 56 - if (len <= sizeof(root_dev)) { 57 - strlcpy(root_dev, line, len); 58 - srvaddr = parse_srvaddr(&line[2], s); 59 - if (*s) { 60 - snprintf(root_opts, sizeof(root_opts), "%s,%s", 57 + if (len > sizeof(root_dev)) { 58 + printk(KERN_ERR "Root-CIFS: UNC path too long\n"); 59 + return 1; 60 + } 61 + strlcpy(root_dev, line, len); 62 + srvaddr = parse_srvaddr(&line[2], s); 63 + if (*s) { 64 + int n = snprintf(root_opts, 65 + sizeof(root_opts), "%s,%s", 61 66 DEFAULT_MNT_OPTS, s + 1); 67 + if (n >= sizeof(root_opts)) { 68 + printk(KERN_ERR "Root-CIFS: mount options string too long\n"); 69 + root_opts[sizeof(root_opts)-1] = '\0'; 70 + return 1; 62 71 } 63 72 } 64 73 }