| From c230b67f61d93c0ce9e591ca00600877b1724198 Mon Sep 17 00:00:00 2001 |
| From: Gabriel Krisman Bertazi <krisman@collabora.com> |
| Date: Tue, 2 Jul 2019 17:53:22 -0400 |
| Subject: [PATCH] ext4: fix coverity warning on error path of filename setup |
| |
| commit 96fcaf86c3cb9340015fb475d79ef0a6fcf858ed upstream. |
| |
| Fix the following coverity warning reported by Dan Carpenter: |
| |
| fs/ext4/namei.c:1311 ext4_fname_setup_ci_filename() |
| warn: 'cf_name->len' unsigned <= 0 |
| |
| Fixes: 3ae72562ad91 ("ext4: optimize case-insensitive lookups") |
| Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com> |
| Signed-off-by: Theodore Ts'o <tytso@mit.edu> |
| Reported-by: Dan Carpenter <dan.carpenter@oracle.com> |
| Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com> |
| |
| diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c |
| index 2631fded446b..8d2935e9de30 100644 |
| --- a/fs/ext4/namei.c |
| +++ b/fs/ext4/namei.c |
| @@ -1309,6 +1309,8 @@ int ext4_ci_compare(const struct inode *parent, const struct qstr *name, |
| void ext4_fname_setup_ci_filename(struct inode *dir, const struct qstr *iname, |
| struct fscrypt_str *cf_name) |
| { |
| + int len; |
| + |
| if (!IS_CASEFOLDED(dir)) { |
| cf_name->name = NULL; |
| return; |
| @@ -1318,13 +1320,16 @@ void ext4_fname_setup_ci_filename(struct inode *dir, const struct qstr *iname, |
| if (!cf_name->name) |
| return; |
| |
| - cf_name->len = utf8_casefold(EXT4_SB(dir->i_sb)->s_encoding, |
| - iname, cf_name->name, |
| - EXT4_NAME_LEN); |
| - if (cf_name->len <= 0) { |
| + len = utf8_casefold(EXT4_SB(dir->i_sb)->s_encoding, |
| + iname, cf_name->name, |
| + EXT4_NAME_LEN); |
| + if (len <= 0) { |
| kfree(cf_name->name); |
| cf_name->name = NULL; |
| + return; |
| } |
| + cf_name->len = (unsigned) len; |
| + |
| } |
| #endif |
| |
| -- |
| 2.7.4 |
| |