On 25/03/2024 18:40, Ihor Radchenko wrote:
Max Nikulin writes:
This feature should not write temporary files to /tmp directly

See the attached tentative patch.

Thanks for prompt reaction.

+++ b/lisp/org.el
@@ -16361,7 +16361,7 @@ (defun org-create-formula-image
               org-format-latex-header
               'snippet)))
         (latex-compiler (plist-get processing-info :latex-compiler))
-        (tmpdir temporary-file-directory)
+        (tmpdir (concat temporary-file-directory "orgtex/"))
         (texfilebase (make-temp-name
                       (expand-file-name "orgtex" tmpdir)))

Since directory name already contains "org", it may be shortened to just "tex"

         (texfile (concat texfilebase ".tex"))

I would use `make-temp-file' to create TEXFILE and would derive TEXFILEBASE from it. In general it is safer.

To create directory I expect a call of a function similar to the following one. Perhaps it exists already somewhere.

(defun org-ensure-tmp-dir (dir-symbol prefix)
  (let ((dir (symbol-value dir-symbol)))
    ;; Temporary directory has not been cleaned.
    (or (and dir (file-directory-p dir) dir)
        (setf (symbol-value dir-symbol)
              (make-temp-file (or prefix "orgtmp-") 'dir)))))

(defvar org-tex-tmpdir nil)

Usage example: (org-ensure-tmp-dir 'org-tex-tmpdir "orgtex-")

Fixed directory name is not friendly for multi-user systems and predictable name in /tmp might be a source of security issues.


Reply via email to