summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTing-Wei Lan <lantw44@gmail.com>2013-08-18 11:13:38 +0800
committerLAN-TW <lantw44@gmail.com>2013-08-18 11:13:38 +0800
commit41bcd01e3944c5c4551b52e50d56cc1bc621e101 (patch)
treefcb98357aac7e842814f0a52e1a097598fb9e5f3
parent85b868031d0592c721548a2a9613033de6f6a5ca (diff)
downloadgsoc2013-libgnome-autoar-41bcd01e3944c5c4551b52e50d56cc1bc621e101.tar
gsoc2013-libgnome-autoar-41bcd01e3944c5c4551b52e50d56cc1bc621e101.tar.gz
gsoc2013-libgnome-autoar-41bcd01e3944c5c4551b52e50d56cc1bc621e101.tar.bz2
gsoc2013-libgnome-autoar-41bcd01e3944c5c4551b52e50d56cc1bc621e101.tar.lz
gsoc2013-libgnome-autoar-41bcd01e3944c5c4551b52e50d56cc1bc621e101.tar.xz
gsoc2013-libgnome-autoar-41bcd01e3944c5c4551b52e50d56cc1bc621e101.tar.zst
gsoc2013-libgnome-autoar-41bcd01e3944c5c4551b52e50d56cc1bc621e101.zip
AutoarExtract: Fix segmentation fault if source is memory
-rw-r--r--gnome-autoar/autoar-extract.c14
-rw-r--r--tests/test-extract.c27
2 files changed, 33 insertions, 8 deletions
diff --git a/gnome-autoar/autoar-extract.c b/gnome-autoar/autoar-extract.c
index f1131fb..694f6e1 100644
--- a/gnome-autoar/autoar-extract.c
+++ b/gnome-autoar/autoar-extract.c
@@ -131,10 +131,10 @@ enum
enum
{
PROP_0,
- PROP_SOURCE, /* Must not be NULL */
- PROP_SOURCE_FILE, /* It may be NULL if source-is-mem is TRUE */
- PROP_OUTPUT, /* Must not be NULL */
- PROP_OUTPUT_FILE, /* Must not be NULL */
+ PROP_SOURCE, /* Only used to display messages */
+ PROP_SOURCE_FILE, /* It may be invalid if source-is-mem is TRUE */
+ PROP_OUTPUT, /* Only used to display messages */
+ PROP_OUTPUT_FILE,
PROP_SIZE,
PROP_COMPLETED_SIZE,
PROP_FILES,
@@ -648,7 +648,7 @@ g_file_get_name (GFile *file) {
char *name;
name = g_file_get_path (file);
if (name == NULL)
- g_file_get_uri (file);
+ name = g_file_get_uri (file);
return name;
}
@@ -1342,7 +1342,7 @@ autoar_extract_new_full (const char *source,
if (source_is_mem) {
gen_source = g_strdup_printf ("(memory %p, size %" G_GSIZE_FORMAT ")", buffer, buffer_size);
- gen_source_file = NULL;
+ gen_source_file = g_file_new_for_commandline_arg (gen_source);;
} else {
if (source == NULL)
gen_source = g_file_get_name (source_file);
@@ -1362,7 +1362,7 @@ autoar_extract_new_full (const char *source,
"output", output != NULL ? output : gen_output,
"output-file", output_file != NULL ? output_file : gen_output_file,
"source-is-mem", source_is_mem,
- "output-is-dest", output_is_dest);
+ "output-is-dest", output_is_dest, NULL);
arextract->priv->arpref = g_object_ref (arpref);
if (source_is_mem) {
diff --git a/tests/test-extract.c b/tests/test-extract.c
index a592dd8..98a5950 100644
--- a/tests/test-extract.c
+++ b/tests/test-extract.c
@@ -58,6 +58,7 @@ main (int argc,
AutoarExtract *arextract;
AutoarPref *arpref;
GSettings *settings;
+ char *content;
if (argc < 3) {
g_printerr ("Usage: %s archive_file output_dir pattern_to_ignore ...\n",
@@ -65,6 +66,7 @@ main (int argc,
return 255;
}
+ content = NULL;
settings = g_settings_new (AUTOAR_PREF_DEFAULT_GSCHEMA_ID);
arpref = autoar_pref_new_with_gsettings (settings);
@@ -74,7 +76,29 @@ main (int argc,
autoar_pref_forget_changes (arpref);
autoar_pref_write_gsettings (arpref, settings);
- arextract = autoar_extract_new (argv[1], argv[2], arpref);
+ if (g_str_has_suffix (argv[0], "test-extract-memory")) {
+ gsize length;
+ GFile *file;
+ GError *error;
+
+ g_print ("Loading whole file into memory ... ");
+
+ error = NULL;
+ file = g_file_new_for_commandline_arg (argv[1]);
+ if (!g_file_load_contents (file, NULL, &content, &length, NULL, &error)) {
+ g_printerr ("\ntest-extract-memory: Error %d: %s\n", error->code, error->message);
+ g_object_unref (file);
+ g_error_free (error);
+ return 1;
+ }
+
+ g_print ("OK\n");
+ g_object_unref (file);
+ arextract = autoar_extract_new_memory (content, length, argv[2], arpref);
+ } else {
+ arextract = autoar_extract_new (argv[1], argv[2], arpref);
+ }
+
g_signal_connect (arextract, "scanned", G_CALLBACK (my_handler_scanned), NULL);
g_signal_connect (arextract, "decide-dest", G_CALLBACK (my_handler_decide_dest), NULL);
g_signal_connect (arextract, "progress", G_CALLBACK (my_handler_progress), NULL);
@@ -86,6 +110,7 @@ main (int argc,
g_object_unref (arextract);
g_object_unref (arpref);
g_object_unref (settings);
+ g_free (content);
return 0;
}