From 31a39d2a3700b2285c847e9b9269f5b7ec39d8f2 Mon Sep 17 00:00:00 2001 From: Yura Pakhuchiy Date: Wed, 12 Sep 2007 16:43:27 +0300 Subject: [PATCH] Fix memory corruption in case option parsing failed. --- ntfsprogs/ntfsmount.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/ntfsprogs/ntfsmount.c b/ntfsprogs/ntfsmount.c index 83107a24..09d38afe 100644 --- a/ntfsprogs/ntfsmount.c +++ b/ntfsprogs/ntfsmount.c @@ -1556,6 +1556,7 @@ static int ntfs_fuse_opt_proc(void *data __attribute__((unused)), { switch (key) { case NF_KEY_HELP: + usage(); return -1; /* Force usage show. */ case NF_KEY_UMASK: ctx->dmask = ctx->fmask; @@ -1635,12 +1636,14 @@ static int ntfs_fuse_is_block_dev(void) static int parse_options(struct fuse_args *args) { - int ret; char *buffer = NULL; - ret = fuse_opt_parse(args, ctx, ntfs_fuse_opts, ntfs_fuse_opt_proc); + if (fuse_opt_parse(args, ctx, ntfs_fuse_opts, ntfs_fuse_opt_proc)) + return -1; + if (!ctx->device) { ntfs_log_error("No device specified.\n"); + usage(); return -1; } if (ctx->quiet && ctx->verbose) { @@ -1697,7 +1700,7 @@ static int parse_options(struct fuse_args *args) if (fuse_opt_add_arg(args, "-odebug") == -1) return -1; } - return ret; + return 0; } static int ntfs_fuse_mount(void) @@ -1724,8 +1727,7 @@ int main(int argc, char *argv[]) struct fuse_chan *fch; ntfs_fuse_init(); - if (parse_options(&args) == -1) { - usage(); + if (parse_options(&args)) { fuse_opt_free_args(&args); ntfs_fuse_destroy(NULL); return 1;