Repository navigation
Conversation
The attachment name comes from the document and was used as is to build the destination, so a name like ../Desktop/x.desktop wrote the file outside the folder picked in Save Attachment As. The same name was also suggested in the save dialog for a single attachment, where GTK resolves it the same way. Use g_path_get_basename for both, like ev_attachment_open already does for its temporary file.
|
I think there is one more place that needs the same treatment: dragging an attachment out of the sidebar.
template = g_strdup_printf ("%s.XXXXXX", ev_attachment_get_name (attachment));
file = ev_mkstemp_file (template, &error);
An alternative is to sanitize the name once, when the --- a/libdocument/ev-attachment.c
+++ b/libdocument/ev-attachment.c
@@ -104,6 +104,24 @@
G_OBJECT_CLASS (ev_attachment_parent_class)->finalize (object);
}
+/* The name comes from the document and is later used to build file names
+ * (save, save as, drag and drop, open). Reduce it to a single path component
+ * so that it can never point outside the destination directory. */
+static gchar *
+ev_attachment_safe_name (const gchar *name)
+{
+ gchar *basename = g_path_get_basename (name ? name : "");
+
+ if (g_strcmp0 (basename, ".") == 0 ||
+ g_strcmp0 (basename, "..") == 0 ||
+ g_strcmp0 (basename, G_DIR_SEPARATOR_S) == 0) {
+ g_free (basename);
+ basename = g_strdup ("attachment");
+ }
+
+ return basename;
+}
+
static void
ev_attachment_set_property (GObject *object,
guint prop_id,
@@ -114,7 +132,7 @@
switch (prop_id) {
case PROP_NAME:
- attachment->priv->name = g_value_dup_string (value);
+ attachment->priv->name = ev_attachment_safe_name (g_value_get_string (value));
break;
case PROP_DESCRIPTION:
attachment->priv->description = g_value_dup_string (value); |
the attachment name comes straight from the pdf, so with a name like
../Desktop/test.desktop"Save Attachment As..." wrote the file outside the folder you picked. both the folder path (g_file_get_child) and the suggested name in the dialog for a single attachment had this, the dialog one too since gtk resolves the../on save. they now useg_path_get_basenameof the name, same asev_attachment_openalready does for its temp file. checked with a pdf that has../escaped.txtandinside.txtattached, both end up in the picked folder now. Fixes #714