From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#71935: split-string-and-unquote mishandles dired-listing-switches with ' Date: Thu, 04 Jul 2024 20:56:11 +0300 Message-ID: <868qyh82is.fsf@gnu.org> References: <86tth5tztt.fsf@mail.linkov.net> <86zfqx8tnn.fsf@gnu.org> <86a5ixqhd4.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3104"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 71935@debbugs.gnu.org To: Juri Linkov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jul 04 19:57:33 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sPQi4-0000Yy-4m for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 04 Jul 2024 19:57:32 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sPQhe-0001tV-AG; Thu, 04 Jul 2024 13:57:06 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sPQhZ-0001jg-1J for bug-gnu-emacs@gnu.org; Thu, 04 Jul 2024 13:57:01 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sPQhX-00058q-W2 for bug-gnu-emacs@gnu.org; Thu, 04 Jul 2024 13:57:00 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sPQha-0000bF-EN for bug-gnu-emacs@gnu.org; Thu, 04 Jul 2024 13:57:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 04 Jul 2024 17:57:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 71935 X-GNU-PR-Package: emacs Original-Received: via spool by 71935-submit@debbugs.gnu.org id=B71935.17201157852232 (code B ref 71935); Thu, 04 Jul 2024 17:57:02 +0000 Original-Received: (at 71935) by debbugs.gnu.org; 4 Jul 2024 17:56:25 +0000 Original-Received: from localhost ([127.0.0.1]:42910 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sPQgy-0000Zw-NE for submit@debbugs.gnu.org; Thu, 04 Jul 2024 13:56:25 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:33436) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sPQgw-0000Ze-FQ for 71935@debbugs.gnu.org; Thu, 04 Jul 2024 13:56:23 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sPQgo-00054X-BB; Thu, 04 Jul 2024 13:56:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=/SKPPCbkX9u7vEpJYyhqZ6r7+O6kkRNA4s+ytH4uCbM=; b=DcB5eJ15IbD5pTxyuLlp mw+aUCCmfzf/ppbyIRay6MJNtRahcXKSPpc04c9JOPnnU6/8Xahy1HnBojJUpJXBpbuXxpjV04Tim z8rUKKK80TwKnrbKzKrb1i5ZQ6x6KYZd5HJwPMG27rKjDsdoTQDNs6qBDQi1pSFQ72sRbuaxTV+A3 k7WRb6g/Z3+M587/Rq9Ow8q9rURh8gEVdAwC33milncxi3ZTmxylXGMWrMOjdYzF+U3PuynRybN4I zTG06xeDpzLUQhaQfxKwYuR/S+0yXQg/PvH+JLLT8K/ioDUxwlOgcaYgoi0PZo8eLbqPHl3mMNKOg VxBhy2LeUiLKdg==; In-Reply-To: <86a5ixqhd4.fsf@mail.linkov.net> (message from Juri Linkov on Thu, 04 Jul 2024 19:10:17 +0300) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:288385 Archived-At: > From: Juri Linkov > Cc: 71935@debbugs.gnu.org > Date: Thu, 04 Jul 2024 19:10:17 +0300 > > >> 1. (setopt dired-listing-switches "-al --block-size='1") > >> 2. C-x d /tmp/* > >> > >> /tmp: > >> wildcard * > >> /bin/bash: -c: line 0: unexpected EOF while looking for matching `'' > >> /bin/bash: -c: line 1: syntax error: unexpected end of file > >> > >> 3. (setopt dired-listing-switches "-al --block-size=\\'1") > >> 4. C-x d /tmp/ > >> > >> Debugger entered--Lisp error: (error "Listing directory failed but ‘access-file’ worked") > >> error("Listing directory failed but `access-file' worked") > >> insert-directory("/tmp/" "--dired -N -al --block-size=\\'1" nil t) > > > > I think the part of insert-directory that deals with wildcard lacks > > the call to shell-quote-argument here: > > > > ;; NB since switches is passed to the shell, be > > ;; careful of malicious values, eg "-l;reboot". > > ;; See eg dired-safe-switches-p. > > (call-process > > shell-file-name nil t nil > > shell-command-switch > > (concat (if (memq system-type '(ms-dos windows-nt)) > > "" > > "\\") ; Disregard Unix shell aliases! > > insert-directory-program > > " -d " > > (if (stringp switches) > > switches > > (mapconcat #'identity switches " ")) > > > > Can you try running each switch through shell-quote-argument? > > This part of insert-directory is used only in case of 1-2 above, > i.e. for wildcard '/tmp/*'. In this case the value of 'switches' > is "--dired -N -al --block-size='1", and 'shell-quote-argument' > returns "--dired\\ -N\\ -al\\ --block-size\\=\\'1" that fails. I meant to call shell-quote-argument on each option, before they are concatenated. > For the non-wildcard case of 3-4 above, this doesn't help either. > Using (mapcar 'shell-quote-argument (split-string-and-unquote switches)) > on ("--dired" "-N" "-al" "--block-size=\\'1") returns > ("--dired" "-N" "-al" "--block-size\\=\\\\\\'1") that fails with > > /bin/ls: unrecognized option '--block-size\=\\\'1' Why did you use "--block-size=\\'1"? My idea is that the quoting should not come from the user.