From 0f0019e326ad48c93d6ede55bf12dfcf9a756997 Mon Sep 17 00:00:00 2001 From: Max Nikulin Date: Wed, 27 Mar 2024 23:04:07 +0700 Subject: [PATCH] org-ctags.el: Protect shell specials in directory name * lisp/org-ctags.el (org-ctags-create-tags): Escape shell specials. Directory name (the argument or `default-directory') may contain various characters interpreted by shell. Effects may vary from just incorrect actual path to execution of a command embedded into path. Neither double nor single quotes is a safe way to use directory name in shell commands since the name may contain these characters. A follow-up to Martin Marshall. [PATCH] `org-ctags-create-tags` creates empty TAGS file. Fri, 09 Feb 2024 18:57:48 -0500. --- lisp/org-ctags.el | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lisp/org-ctags.el b/lisp/org-ctags.el index 784147572..d3af103dd 100644 --- a/lisp/org-ctags.el +++ b/lisp/org-ctags.el @@ -504,18 +504,21 @@ function may take several seconds to finish if the directory or its subdirectories contain large numbers of taggable files." (interactive) (cl-assert (buffer-file-name)) - (let ((dir-name (or directory-name - (file-name-directory (buffer-file-name)))) + (let ((dir-name (shell-quote-argument + (expand-file-name + (if directory-name + (file-name-as-directory directory-name) + (file-name-directory (buffer-file-name)))))) (exitcode nil)) (save-excursion (setq exitcode (shell-command (format (concat "%s --langdef=orgmode --langmap=orgmode:.org " - "--regex-orgmode=\"%s\" -f \"%s\" -e -R %s") + "--regex-orgmode=%s -f %sTAGS -e -R %s*") org-ctags-path-to-ctags - org-ctags-tag-regexp - (expand-file-name (concat dir-name "/TAGS")) - (expand-file-name (concat (shell-quote-argument dir-name) "/*"))))) + (shell-quote-argument org-ctags-tag-regexp) + dir-name + dir-name))) (cond ((eql 0 exitcode) (setq-local org-ctags-tag-list