diff options
author | lixiaokeng <lixiaokeng@huawei.com> | 2021-06-16 16:57:16 +0800 |
---|---|---|
committer | Nikolaus Rath <Nikolaus@rath.org> | 2021-06-16 18:25:14 +0100 |
commit | a1e41676e34096abe21d202f4c4e440fd1257672 (patch) | |
tree | 7c2ea1002710c4e11caafa4fc7ee1754db8c5b87 | |
parent | 80f2b8b469d97349d87cfd59725cbc7c19959bf6 (diff) | |
download | fuse-a1e41676e34096abe21d202f4c4e440fd1257672.tar.gz |
Fix: a potential crash on failure to setlocale
setlocale() can fail, returning NULL, which will lead
to a crash in iconv_new(). Fix it like in iconv_help().
Signed-off-by: Lixiaokeng <lixiaokeng@huawei.com>
-rwxr-xr-x | lib/modules/iconv.c | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/lib/modules/iconv.c b/lib/modules/iconv.c index 76e2f7d..0ec3c2b 100755 --- a/lib/modules/iconv.c +++ b/lib/modules/iconv.c @@ -672,7 +672,7 @@ static struct fuse_fs *iconv_new(struct fuse_args *args, { struct fuse_fs *fs; struct iconv *ic; - char *old = NULL; + const char *old = NULL; const char *from; const char *to; @@ -694,7 +694,7 @@ static struct fuse_fs *iconv_new(struct fuse_args *args, to = ic->to_code ? ic->to_code : ""; /* FIXME: detect charset equivalence? */ if (!to[0]) - old = strdup(setlocale(LC_CTYPE, "")); + old = setlocale(LC_CTYPE, ""); ic->tofs = iconv_open(from, to); if (ic->tofs == (iconv_t) -1) { fuse_log(FUSE_LOG_ERR, "fuse-iconv: cannot convert from %s to %s\n", @@ -709,7 +709,6 @@ static struct fuse_fs *iconv_new(struct fuse_args *args, } if (old) { setlocale(LC_CTYPE, old); - free(old); old = NULL; } @@ -730,7 +729,6 @@ out_free: free(ic); if (old) { setlocale(LC_CTYPE, old); - free(old); } return NULL; } |