Merge branch '2632_vfs_store_file_fix'

* 2632_vfs_store_file_fix:
  little optimization to make code more intuitive.
  Ticket #2623: vfs: use data after free.
This commit is contained in:
Andrew Borodin 2011-10-19 14:12:32 +04:00
commit ff3c4084a2
6 changed files with 50 additions and 25 deletions

View File

@ -730,6 +730,8 @@ vfs_s_close (void *fh)
close (FH->handle);
vfs_s_free_inode (me, FH->ino);
if (MEDATA->fh_free_data != NULL)
MEDATA->fh_free_data (fh);
g_free (fh);
return res;
}
@ -1264,11 +1266,18 @@ vfs_s_open (const vfs_path_t * vpath, int flags, mode_t mode)
fh->linear = LS_LINEAR_PREOPEN;
}
}
else if ((VFSDATA (path_element)->fh_open != NULL)
&& (VFSDATA (path_element)->fh_open (path_element->class, fh, flags, mode) != 0))
else
{
g_free (fh);
return NULL;
struct vfs_s_subclass *s;
s = VFSDATA (path_element);
if (s->fh_open != NULL && s->fh_open (path_element->class, fh, flags, mode) != 0)
{
if (s->fh_free_data != NULL)
s->fh_free_data (fh);
g_free (fh);
return NULL;
}
}
if (fh->ino->localname)

View File

@ -133,6 +133,7 @@ struct vfs_s_subclass
int (*fh_open) (struct vfs_class * me, vfs_file_handler_t * fh, int flags, mode_t mode);
int (*fh_close) (struct vfs_class * me, vfs_file_handler_t * fh);
void (*fh_free_data) (vfs_file_handler_t * fh);
struct vfs_s_entry *(*find_entry) (struct vfs_class * me,
struct vfs_s_inode * root,

View File

@ -148,7 +148,7 @@ typedef struct
{
off_t got;
off_t total;
int append;
gboolean append;
} fish_fh_data_t;
/*** file scope variables ************************************************************************/
@ -908,7 +908,7 @@ fish_file_store (struct vfs_class *me, vfs_file_handler_t * fh, char *name, char
vfs_print_message (_("fish: store %s: sending command..."), quoted_name);
/* FIXME: File size is limited to ULONG_MAX */
if (!fish->append)
if (fish->append)
{
shell_commands =
g_strconcat (SUP->scr_env, "FISH_FILENAME=%s FISH_FILESIZE=%" PRIuMAX ";\n",
@ -1000,7 +1000,7 @@ fish_linear_start (struct vfs_class *me, vfs_file_handler_t * fh, off_t offset)
return 0;
quoted_name = strutils_shell_escape (name);
g_free (name);
fish->append = 0;
fish->append = FALSE;
/*
* Check whether the remote file is readable by using `dd' to copy
@ -1445,6 +1445,18 @@ fish_rmdir (const vfs_path_t * vpath)
/* --------------------------------------------------------------------------------------------- */
static void
fish_fh_free_data (vfs_file_handler_t * fh)
{
if (fh != NULL)
{
g_free (fh->data);
fh->data = NULL;
}
}
/* --------------------------------------------------------------------------------------------- */
static int
fish_fh_open (struct vfs_class *me, vfs_file_handler_t * fh, int flags, mode_t mode)
{
@ -1458,7 +1470,10 @@ fish_fh_open (struct vfs_class *me, vfs_file_handler_t * fh, int flags, mode_t m
/* File will be written only, so no need to retrieve it */
if (((flags & O_WRONLY) == O_WRONLY) && ((flags & (O_RDONLY | O_RDWR)) == 0))
{
fish->append = flags & O_APPEND;
/* user pressed the button [ Append ] in the "Copy" dialog */
if ((flags & O_APPEND) != 0)
fish->append = TRUE;
if (!fh->ino->localname)
{
int tmp_handle = vfs_mkstemps (&fh->ino->localname, me->name,
@ -1476,23 +1491,12 @@ fish_fh_open (struct vfs_class *me, vfs_file_handler_t * fh, int flags, mode_t m
return 0;
fail:
g_free (fh->data);
fish_fh_free_data (fh);
return -1;
}
/* --------------------------------------------------------------------------------------------- */
static int
fish_fh_close (struct vfs_class *me, vfs_file_handler_t * fh)
{
(void) me;
g_free (fh->data);
return 0;
}
/* --------------------------------------------------------------------------------------------- */
static void
fish_fill_names (struct vfs_class *me, fill_names_f func)
{
@ -1561,7 +1565,7 @@ init_fish (void)
fish_subclass.open_archive = fish_open_archive;
fish_subclass.free_archive = fish_free_archive;
fish_subclass.fh_open = fish_fh_open;
fish_subclass.fh_close = fish_fh_close;
fish_subclass.fh_free_data = fish_fh_free_data;
fish_subclass.dir_load = fish_dir_load;
fish_subclass.file_store = fish_file_store;
fish_subclass.linear_start = fish_linear_start;

View File

@ -2,7 +2,6 @@
FILENAME="/${FISH_FILENAME}"
echo "### 001"
{
> "${FILENAME}"
bss=4096
bsl=4095
if [ $FISH_FILESIZE -lt $bss ]; then

View File

@ -2,6 +2,7 @@
FILENAME="/${FISH_FILENAME}"
echo "### 001"
{
> "${FILENAME}"
bss=4096
bsl=4095
if [ $FISH_FILESIZE -lt $bss ]; then

View File

@ -2102,6 +2102,18 @@ ftpfs_rmdir (const vfs_path_t * vpath)
/* --------------------------------------------------------------------------------------------- */
static void
ftpfs_fh_free_data (vfs_file_handler_t *fh)
{
if (fh != NULL)
{
g_free (fh->data);
fh->data = NULL;
}
}
/* --------------------------------------------------------------------------------------------- */
static int
ftpfs_fh_open (struct vfs_class *me, vfs_file_handler_t * fh, int flags, mode_t mode)
{
@ -2170,7 +2182,7 @@ ftpfs_fh_open (struct vfs_class *me, vfs_file_handler_t * fh, int flags, mode_t
return 0;
fail:
g_free (fh->data);
ftpfs_fh_free_data (fh);
return -1;
}
@ -2194,8 +2206,6 @@ ftpfs_fh_close (struct vfs_class *me, vfs_file_handler_t * fh)
vfs_s_invalidate (me, FH_SUPER);
}
g_free (fh->data);
return 0;
}
@ -2556,6 +2566,7 @@ init_ftpfs (void)
ftpfs_subclass.free_archive = ftpfs_free_archive;
ftpfs_subclass.fh_open = ftpfs_fh_open;
ftpfs_subclass.fh_close = ftpfs_fh_close;
ftpfs_subclass.fh_free_data = ftpfs_fh_free_data;
ftpfs_subclass.dir_load = ftpfs_dir_load;
ftpfs_subclass.file_store = ftpfs_file_store;
ftpfs_subclass.linear_start = ftpfs_linear_start;