[empathy] Refuse sending empty or special files (directories, char/block devices, etc.)



commit 0f4c81cabf14b37cebef3f4c22f9bdc3ce5238b3
Author: Frédéric Péters <fpeters 0d be>
Date:   Wed Jun 17 09:57:02 2009 +0200

    Refuse sending empty or special files (directories, char/block devices, etc.)
    
    (GNOME bug 563678)

 libempathy/empathy-ft-handler.c |   19 ++++++++++++++++++-
 libempathy/empathy-tp-file.h    |    4 +++-
 2 files changed, 21 insertions(+), 2 deletions(-)
---
diff --git a/libempathy/empathy-ft-handler.c b/libempathy/empathy-ft-handler.c
index ba81fd4..d24467b 100644
--- a/libempathy/empathy-ft-handler.c
+++ b/libempathy/empathy-ft-handler.c
@@ -1149,9 +1149,25 @@ ft_handler_gfile_ready_cb (GObject *source,
   if (error != NULL)
     goto out;
 
+  if (g_file_info_get_file_type (info) != G_FILE_TYPE_REGULAR)
+    {
+      error = g_error_new_literal (EMPATHY_FT_ERROR_QUARK,
+          EMPATHY_FT_ERROR_INVALID_SOURCE_FILE,
+          _("The selected file is not a regular file"));
+      goto out;
+    }
+
+  priv->total_bytes = g_file_info_get_size (info);
+  if (priv->total_bytes == 0)
+    {
+      error = g_error_new_literal (EMPATHY_FT_ERROR_QUARK,
+          EMPATHY_FT_ERROR_EMPTY_SOURCE_FILE,
+          _("The selected file is empty"));
+      goto out;
+    }
+
   priv->content_type = g_strdup (g_file_info_get_content_type (info));
   priv->filename = g_strdup (g_file_info_get_display_name (info));
-  priv->total_bytes = g_file_info_get_size (info);
   g_file_info_get_modification_time (info, &mtime);
   priv->mtime = mtime.tv_sec;
   priv->transferred_bytes = 0;
@@ -1303,6 +1319,7 @@ empathy_ft_handler_new_outgoing (EmpathyContact *contact,
       G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME ","
       G_FILE_ATTRIBUTE_STANDARD_SIZE ","
       G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE ","
+      G_FILE_ATTRIBUTE_STANDARD_TYPE ","
       G_FILE_ATTRIBUTE_TIME_MODIFIED,
       G_FILE_QUERY_INFO_NONE, G_PRIORITY_DEFAULT,
       NULL, (GAsyncReadyCallback) ft_handler_gfile_ready_cb, data);
diff --git a/libempathy/empathy-tp-file.h b/libempathy/empathy-tp-file.h
index 0d7d8ef..b40b8c3 100644
--- a/libempathy/empathy-tp-file.h
+++ b/libempathy/empathy-tp-file.h
@@ -50,7 +50,9 @@ typedef enum {
 	EMPATHY_FT_ERROR_HASH_MISMATCH,
 	EMPATHY_FT_ERROR_TP_ERROR,
 	EMPATHY_FT_ERROR_SOCKET,
-	EMPATHY_FT_ERROR_NOT_SUPPORTED
+	EMPATHY_FT_ERROR_NOT_SUPPORTED,
+	EMPATHY_FT_ERROR_INVALID_SOURCE_FILE,
+	EMPATHY_FT_ERROR_EMPTY_SOURCE_FILE
 } EmpathyFTErrorEnum;
 
 typedef struct _EmpathyTpFile EmpathyTpFile;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]