Commit f9c62d3c authored by Morten Welinder's avatar Morten Welinder Committed by Morten Welinder

Catch invalid file names.

2002-10-08  Morten Welinder  <terra@diku.dk>

	* src/workbook-view.c (wb_view_new_from_file): Catch invalid file
	names.

	* src/gutils.c (gnumeric_valid_filename): New function.
parent 80a73121
2002-10-08 Morten Welinder <terra@diku.dk>
* src/workbook-view.c (wb_view_new_from_file): Catch invalid file
names.
* src/gutils.c (gnumeric_valid_filename): New function.
2002-10-08 Jody Goldberg <jody@gnome.org>
* src/parser.y (parser_lookup_name) : default the placeholder to be at
......
Gnumeric 1.1.11
Morten:
* Start handling invalid (== non-utf8) file names.
--------------------------------------------------------------------------
Gnumeric 1.1.10
Andreas:
......
2002-10-08 Morten Welinder <terra@diku.dk>
* src/workbook-view.c (wb_view_new_from_file): Catch invalid file
names.
* src/gutils.c (gnumeric_valid_filename): New function.
2002-10-08 Jody Goldberg <jody@gnome.org>
* src/parser.y (parser_lookup_name) : default the placeholder to be at
......
2002-10-08 Morten Welinder <terra@diku.dk>
* src/workbook-view.c (wb_view_new_from_file): Catch invalid file
names.
* src/gutils.c (gnumeric_valid_filename): New function.
2002-10-08 Jody Goldberg <jody@gnome.org>
* src/parser.y (parser_lookup_name) : default the placeholder to be at
......
......@@ -654,6 +654,25 @@ gnumeric_utf8_strcapital (const char *p, ssize_t len)
/* ------------------------------------------------------------------------- */
gboolean
gnumeric_valid_filename (const char *filename)
{
GError *err = NULL;
char *utf8name;
gboolean res;
g_return_val_if_fail (filename != NULL, FALSE);
utf8name = g_filename_to_utf8 (filename, -1, NULL, NULL, &err);
res = utf8name && !err;
g_free (utf8name);
g_clear_error (&err);
return res;
}
/* ------------------------------------------------------------------------- */
#undef DEBUG_CHUNK_ALLOCATOR
typedef struct _gnm_mem_chunk_freeblock gnm_mem_chunk_freeblock;
......
......@@ -90,6 +90,8 @@ char * gnumeric_strescape (const char *string);
char * gnumeric_utf8_strcapital (const char *p, ssize_t len);
gboolean gnumeric_valid_filename (const char *filename);
gnm_mem_chunk *gnm_mem_chunk_new (const char *, size_t, size_t);
void gnm_mem_chunk_destroy (gnm_mem_chunk *, gboolean);
gpointer gnm_mem_chunk_alloc (gnm_mem_chunk *);
......
......@@ -43,10 +43,12 @@
#include "mstyle.h"
#include "position.h"
#include "cell.h"
#include "gutils.h"
#include "io-context.h"
#include <gsf/gsf-input-memory.h>
#include <gsf/gsf-input-stdio.h>
#include <gsf/gsf-utils.h>
#include <gsf/gsf-impl-utils.h>
#include <locale.h>
......@@ -684,32 +686,43 @@ wb_view_new_from_file (char const *file_name,
GnumFileOpener const *optional_fmt,
IOContext *io_context)
{
GError *err = NULL;
char *msg = NULL;
GsfInput *input;
/* Only report error if stdio fails too */
input = gsf_input_mmap_new (file_name, NULL);
if (input == NULL)
input = gsf_input_stdio_new (file_name, &err);
puts (file_name);
if (input != NULL) {
WorkbookView *res = wb_view_new_from_input (input,
optional_fmt, io_context);
g_object_unref (G_OBJECT (input));
return res;
}
if (err != NULL) {
if (err->message != NULL)
msg = g_strdup (err->message);
g_error_free (err);
if (gnumeric_valid_filename (file_name)) {
GError *err = NULL;
GsfInput *input;
/* Only report error if stdio fails too */
input = gsf_input_mmap_new (file_name, NULL);
if (input == NULL)
input = gsf_input_stdio_new (file_name, &err);
puts (file_name);
if (input != NULL) {
WorkbookView *res = wb_view_new_from_input (input,
optional_fmt, io_context);
g_object_unref (G_OBJECT (input));
return res;
}
if (err != NULL) {
if (err->message != NULL)
msg = g_strdup (err->message);
g_error_free (err);
}
if (msg == NULL)
msg = g_strdup_printf (_("An unexplained error happened while opening %s"),
file_name);
} else {
/*
* This should be quite rare. To provoke, use
* gnumeric `echo -e '\377\376'`
*/
msg = g_strdup (_("The filename given is not valid."));
}
if (msg == NULL)
msg = g_strdup_printf (_("An unexplained error happened while opening '%s'"),
file_name);
gnumeric_error_read (COMMAND_CONTEXT (io_context), msg);
g_free (msg);
return NULL;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment