Hi, I'm trying to fix the compiling warnings of ntfs-3g and then found a possible leak in ntfs_fuse_parse_path of ntfs-3g.c.If I read the code correctly, in ntfs_fuse_parse_path(), it's possible that strdup() succeeds but ntfs_mbstoucs() returns a negative value. In such a case the callers just treat it as an error and ignores the allocated path buffer that results in a memory leak.
I suggest the attached patch to fix it, as well as some warnings. Let me know if it's the correct way to handle it. Regards, Chih-Wei
>From 65b8320710f1ca5fc5a36d6bb3de8a8b7ca8d38c Mon Sep 17 00:00:00 2001 From: Chih-Wei Huang <[email protected]> Date: Tue, 15 Apr 2014 16:23:07 +0800 Subject: [PATCH] Fix a possible memory leak and compiling warnings In ntfs_fuse_parse_path(), it's possible that strdup() succeeds but ntfs_mbstoucs() returns a negative value. In such a case the callers just treat it as an error and ignores the allocated path buffer that results in a memory leak. --- src/ntfs-3g.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/ntfs-3g.c b/src/ntfs-3g.c index baccbfd..166ef72 100644 --- a/src/ntfs-3g.c +++ b/src/ntfs-3g.c @@ -524,8 +524,11 @@ static int ntfs_fuse_parse_path(const char *org_path, char **path, if (stream_name_mbs) { *stream_name = NULL; res = ntfs_mbstoucs(stream_name_mbs, stream_name); - if (res < 0) + if (res < 0) { + free(*path); + *path = NULL; return -errno; + } return res; } } else @@ -896,7 +899,7 @@ exit: static int ntfs_fuse_readlink(const char *org_path, char *buf, size_t buf_size) { - char *path; + char *path = NULL; ntfschar *stream_name; ntfs_inode *ni = NULL; ntfs_attr *na = NULL; @@ -1617,7 +1620,7 @@ static int ntfs_fuse_create(const char *org_path, mode_t typemode, dev_t dev, ntfs_inode *dir_ni = NULL, *ni; char *dir_path; le32 securid; - char *path; + char *path = NULL; gid_t gid; mode_t dsetgid; ntfschar *stream_name; -- 1.9.0
------------------------------------------------------------------------------ Learn Graph Databases - Download FREE O'Reilly Book "Graph Databases" is the definitive new guide to graph databases and their applications. Written by three acclaimed leaders in the field, this first edition is now available. Download your free book today! http://p.sf.net/sfu/NeoTech
_______________________________________________ ntfs-3g-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ntfs-3g-devel
