[Top][All Lists]

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

Re: [bug-recutils] Cant use recset when in dir that does not allow to wr

From: Jose E. Marchesi
Subject: Re: [bug-recutils] Cant use recset when in dir that does not allow to write
Date: Thu, 15 Feb 2018 09:45:12 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux)

Hi Jakob.
    when trying to use recset on a file that does not lie in the current
    directory and one does not have write permissions on the current
    directory following error occures:
    recset: error: cannot create a unique name.
    If I understand the code in utils/recutl.c around line 411 correctly,
    recutils tries to create a temporary file in the current directory.

Fixed in git with the patch below.
Thanks for reporting!

commit 70fc0f36caca9079c77a6a115b87b715947aae01
Author: Jose E. Marchesi <address@hidden>
Date:   Thu Feb 15 09:44:08 2018 +0100

    utils: do not use the current directory to hold temporary files

diff --git a/ChangeLog b/ChangeLog
index 2c073fb..222d432 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2018-02-15  Jose E. Marchesi  <address@hidden>
+       * utils/recutl.c (recutl_write_db_to_file): Do not use the current
+       directory to hold temporary files.
 2017-01-31  Jose E. Marchesi  <address@hidden>
        * README-dev: Correct typo.
diff --git a/bootstrap.conf b/bootstrap.conf
index b7ac8f8..2661a88 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -26,7 +26,7 @@ gnulib_modules="
   c-ctype extensions fwriting getdelim getopt gettext-h localcharset mbrlen
   mbrtowc mbsinit memchr mkostemp obstack pathmax regex rename selinux-h 
   stat-macros ssize_t strerror strverscmp threadlib unlocked-io verify
-  version-etc-fsf wcrtomb wctob"
+  version-etc-fsf wcrtomb wctob tmpdir pathmax"
diff --git a/utils/recutl.c b/utils/recutl.c
index ce4a74e..4099762 100644
--- a/utils/recutl.c
+++ b/utils/recutl.c
@@ -47,6 +47,8 @@
 #include <time.h>
 #include <unistd.h>
 #include <getpass.h>
+#include <tmpdir.h>
+#include <pathmax.h>
 #include <rec.h>
 #include <recutl.h>
@@ -389,7 +391,7 @@ recutl_write_db_to_file (rec_db_t db,
                          char *file_name)
   FILE *out;
-  char tmp_file_name[10]="recXXXXXX";
+  char tmp_file_name[PATH_MAX];
   rec_writer_t writer;
   int des;
   struct stat st1;
@@ -405,11 +407,11 @@ recutl_write_db_to_file (rec_db_t db,
       stat_result = stat (file_name, &st1);
       /* Create a temporary file with the results. */
-      des = mkstemp (tmp_file_name);
-      if (des == -1)
-        {
-          recutl_fatal (_("cannot create a unique name.\n"));
-        }
+      if ((path_search (tmp_file_name, PATH_MAX, NULL,
+                        "rec", true) == -1)
+          || ((des = mkstemp (tmp_file_name)) == -1))
+        recutl_fatal (_("cannot create a unique name.\n"));
       out = fdopen (des, "w+");

reply via email to

[Prev in Thread] Current Thread [Next in Thread]