More fixes:

- make sure that the args array is NULL terminated.
- make sure argc is initialized and argv is set to NULL after freeing.
- make the deep copy function an opt interface function.
This commit is contained in:
christos 2007-05-17 01:55:43 +00:00
parent ae218465f7
commit 19468d62cc
4 changed files with 46 additions and 50 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: fuse.h,v 1.18 2007/05/16 22:17:52 xtraeme Exp $ */
/* $NetBSD: fuse.h,v 1.19 2007/05/17 01:55:43 christos Exp $ */
/*
* Copyright © 2007 Alistair Crooks. All rights reserved.
@ -181,9 +181,6 @@ void fuse_unmount_compat22(const char *);
fuse_main_real(argc, argv, op, sizeof(*(op)), NULL)
#endif
struct fuse_args *_fuse_deep_copy_args(int, char **);
void _fuse_free_args(struct fuse_args *);
#ifdef __cplusplus
}
#endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: fuse_opt.h,v 1.3 2007/05/03 20:58:22 agc Exp $ */
/* $NetBSD: fuse_opt.h,v 1.4 2007/05/17 01:55:43 christos Exp $ */
/*
* Copyright (c) 2007 Alistair Crooks. All rights reserved.
@ -51,6 +51,7 @@ typedef int (*fuse_opt_proc_t)(void *, const char *, int, struct fuse_args *);
int fuse_opt_add_arg(struct fuse_args *, const char *);
struct fuse_args *fuse_opt_deep_copy_args(int, char **);
void fuse_opt_free_args(struct fuse_args *);
int fuse_opt_insert_arg(struct fuse_args *, int, const char *);
int fuse_opt_add_opt(char **, const char *);

View File

@ -1,4 +1,4 @@
/* $NetBSD: refuse.c,v 1.55 2007/05/16 21:39:08 christos Exp $ */
/* $NetBSD: refuse.c,v 1.56 2007/05/17 01:55:43 christos Exp $ */
/*
* Copyright © 2007 Alistair Crooks. All rights reserved.
@ -30,7 +30,7 @@
#include <sys/cdefs.h>
#if !defined(lint)
__RCSID("$NetBSD: refuse.c,v 1.55 2007/05/16 21:39:08 christos Exp $");
__RCSID("$NetBSD: refuse.c,v 1.56 2007/05/17 01:55:43 christos Exp $");
#endif /* !lint */
#include <assert.h>
@ -220,39 +220,6 @@ puffs_fuse_dirfil(fuse_dirh_t h, const char *name, int type, ino_t ino)
return fill_dirbuf(h, name, dino, dtype);
}
struct fuse_args *
_fuse_deep_copy_args(int argc, char **argv)
{
struct fuse_args *ap;
size_t i;
if ((ap = malloc(sizeof(*ap))) == NULL)
err(1, "_fuse_deep_copy_args");
/* deep copy args structure into channel args */
ap->allocated = ((argc / 10) + 1) * 10;
if ((ap->argv = calloc((size_t)ap->allocated,
sizeof(*ap->argv))) == NULL)
err(1, "_fuse_deep_copy_args");
for (i = 0; i < argc; i++) {
if ((ap->argv[i] = strdup(argv[i])) == NULL)
err(1, "_fuse_deep_copy_args");
}
return ap;
}
void
_fuse_free_args(struct fuse_args *ap)
{
int i;
for (i = 0; i < ap->argc; i++) {
free(ap->argv[i]);
}
free(ap);
}
static void
set_refuse_mount_name(char **argv, char *name, size_t size)
{
@ -302,7 +269,7 @@ fuse_setup(int argc, char **argv, const struct fuse_operations *ops,
set_refuse_mount_name(argv, name, sizeof(name));
/* stuff name into fuse_args */
args = _fuse_deep_copy_args(argc, argv);
args = fuse_opt_deep_copy_args(argc, argv);
if (args->argc > 0) {
free(args->argv[0]);
}
@ -315,7 +282,8 @@ fuse_setup(int argc, char **argv, const struct fuse_operations *ops,
fc = fuse_mount(*mountpoint = argv[i], args);
fuse = fuse_new(fc, args, ops, size, NULL);
_fuse_free_args(args);
fuse_opt_free_args(args);
free(args);
/* XXX - wait for puffs to become multi-threaded */
if (multithreaded) {
@ -1115,7 +1083,7 @@ fuse_mount(const char *dir, struct fuse_args *args)
* systems "clean up" the argument vector for "security
* reasons"
*/
fc->args = _fuse_deep_copy_args(args->argc, args->argv);
fc->args = fuse_opt_deep_copy_args(args->argc, args->argv);
if (args->argc > 0) {
set_refuse_mount_name(args->argv, name, sizeof(name));

View File

@ -1,4 +1,4 @@
/* $NetBSD: refuse_opt.c,v 1.10 2007/05/16 21:39:08 christos Exp $ */
/* $NetBSD: refuse_opt.c,v 1.11 2007/05/17 01:55:43 christos Exp $ */
/*-
* Copyright (c) 2007 Juan Romero Pardines.
@ -88,7 +88,7 @@ fuse_opt_add_arg(struct fuse_args *args, const char *arg)
struct fuse_args *ap;
if (args->allocated == 0) {
ap = _fuse_deep_copy_args(args->argc, args->argv);
ap = fuse_opt_deep_copy_args(args->argc, args->argv);
args->argv = ap->argv;
args->argc = ap->argc;
args->allocated = ap->allocated;
@ -106,15 +106,44 @@ fuse_opt_add_arg(struct fuse_args *args, const char *arg)
DPRINTF(("%s: arguments passed: [arg:%s]\n", __func__, arg));
if ((args->argv[args->argc++] = strdup(arg)) == NULL)
err(1, "fuse_opt_add_arg");
args->argv[args->argc] = NULL;
return 0;
}
/* ARGSUSED */
void
fuse_opt_free_args(struct fuse_args *args)
struct fuse_args *
fuse_opt_deep_copy_args(int argc, char **argv)
{
_fuse_free_args(args);
args->allocated = args->argc = 0;
struct fuse_args *ap;
size_t i;
if ((ap = malloc(sizeof(*ap))) == NULL)
err(1, "_fuse_deep_copy_args");
/* deep copy args structure into channel args */
ap->allocated = ((argc / 10) + 1) * 10;
if ((ap->argv = calloc((size_t)ap->allocated,
sizeof(*ap->argv))) == NULL)
err(1, "_fuse_deep_copy_args");
for (i = 0; i < argc; i++) {
if ((ap->argv[i] = strdup(argv[i])) == NULL)
err(1, "_fuse_deep_copy_args");
}
ap->argv[ap->argc = i] = NULL;
return ap;
}
void
fuse_opt_free_args(struct fuse_args *ap)
{
int i;
for (i = 0; i < ap->argc; i++) {
free(ap->argv[i]);
}
free(ap->argv);
ap->argv = NULL;
ap->allocated = ap->argc = 0;
}
/* ARGSUSED */
@ -146,6 +175,7 @@ fuse_opt_insert_arg(struct fuse_args *args, int pos, const char *arg)
}
if ((args->argv[pos] = strdup(arg)) == NULL)
err(1, "fuse_opt_insert_arg");
args->argv[args->argc] = NULL;
return 0;
}