diff options
author | Ronnie Sahlberg <lsahlber@redhat.com> | 2019-08-27 01:30:14 +0200 |
---|---|---|
committer | Steve French <stfrench@microsoft.com> | 2019-08-28 00:25:12 +0200 |
commit | 340625e618e1b37a72a02f07aa7144ae0ab0b19e (patch) | |
tree | 9bac6626dd3e1477a93301a84c7c797b7db5526c /fs/cifs/misc.c | |
parent | cifs: Use kzfree() to zero out the password (diff) | |
download | linux-340625e618e1b37a72a02f07aa7144ae0ab0b19e.tar.xz linux-340625e618e1b37a72a02f07aa7144ae0ab0b19e.zip |
cifs: replace various strncpy with strscpy and similar
Using strscpy is cleaner, and avoids some problems with
handling maximum length strings. Linus noticed the
original problem and Aurelien pointed out some additional
problems. Fortunately most of this is SMB1 code (and
in particular the ASCII string handling older, which
is less common).
Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Reviewed-by: Aurelien Aptel <aaptel@suse.com>
Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
Diffstat (limited to 'fs/cifs/misc.c')
-rw-r--r-- | fs/cifs/misc.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c index f383877a6511..5ad83bdb9bea 100644 --- a/fs/cifs/misc.c +++ b/fs/cifs/misc.c @@ -1011,3 +1011,25 @@ void extract_unc_hostname(const char *unc, const char **h, size_t *len) *h = unc; *len = end - unc; } + +/** + * copy_path_name - copy src path to dst, possibly truncating + * + * returns number of bytes written (including trailing nul) + */ +int copy_path_name(char *dst, const char *src) +{ + int name_len; + + /* + * PATH_MAX includes nul, so if strlen(src) >= PATH_MAX it + * will truncate and strlen(dst) will be PATH_MAX-1 + */ + name_len = strscpy(dst, src, PATH_MAX); + if (WARN_ON_ONCE(name_len < 0)) + name_len = PATH_MAX-1; + + /* we count the trailing nul */ + name_len++; + return name_len; +} |