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.
<https://list.orgmode.org/87h6ihgphf.fsf@martinmarshall.com>
This commit is contained in:
Max Nikulin 2024-03-27 23:04:07 +07:00 committed by Ihor Radchenko
parent badb09d679
commit 0f0019e326
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
1 changed files with 9 additions and 6 deletions

View File

@ -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