summaryrefslogtreecommitdiff
path: root/fs/btrfs/rcu-string.h
diff options
context:
space:
mode:
authorArtem Chernyshev <artem.chernyshev@red-soft.ru>2022-11-19 11:13:29 +0300
committerDavid Sterba <dsterba@suse.com>2022-12-05 20:00:59 +0300
commit63d5429f68a3d4c4aa27e65a05196c17f86c41d6 (patch)
tree44c4ea0f73aa09dd970063817049433c3694185a /fs/btrfs/rcu-string.h
parent26df39a9e5a8985674e814f0b27b25e8b4eb9ba7 (diff)
downloadlinux-63d5429f68a3d4c4aa27e65a05196c17f86c41d6.tar.xz
btrfs: replace strncpy() with strscpy()
Using strncpy() on NUL-terminated strings are deprecated. To avoid possible forming of non-terminated string strscpy() should be used. Found by Linux Verification Center (linuxtesting.org) with SVACE. CC: stable@vger.kernel.org # 4.9+ Signed-off-by: Artem Chernyshev <artem.chernyshev@red-soft.ru> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs/btrfs/rcu-string.h')
-rw-r--r--fs/btrfs/rcu-string.h6
1 files changed, 5 insertions, 1 deletions
diff --git a/fs/btrfs/rcu-string.h b/fs/btrfs/rcu-string.h
index 5c1a617eb25d..5c2b66d155ef 100644
--- a/fs/btrfs/rcu-string.h
+++ b/fs/btrfs/rcu-string.h
@@ -18,7 +18,11 @@ static inline struct rcu_string *rcu_string_strdup(const char *src, gfp_t mask)
(len * sizeof(char)), mask);
if (!ret)
return ret;
- strncpy(ret->str, src, len);
+ /* Warn if the source got unexpectedly truncated. */
+ if (WARN_ON(strscpy(ret->str, src, len) < 0)) {
+ kfree(ret);
+ return NULL;
+ }
return ret;
}