From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Max Nikulin Newsgroups: gmane.emacs.bugs Subject: bug#59743: Implement `command-line-args-left' for emacsclient --eval expressions Date: Thu, 1 Dec 2022 22:06:00 +0700 Message-ID: <438a7286-ee4c-74a1-c24b-d788a6507ad6@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26474"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 To: 59743@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Dec 01 16:07:15 2022 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 1p0l9f-0006gI-EX for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 01 Dec 2022 16:07:15 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p0l9V-0002qw-O6; Thu, 01 Dec 2022 10:07:05 -0500 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 1p0l9T-0002qj-1a for bug-gnu-emacs@gnu.org; Thu, 01 Dec 2022 10:07:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p0l9S-0008IG-Pz for bug-gnu-emacs@gnu.org; Thu, 01 Dec 2022 10:07:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1p0l9S-0008Uv-Et for bug-gnu-emacs@gnu.org; Thu, 01 Dec 2022 10:07:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Max Nikulin Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 01 Dec 2022 15:07:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 59743 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.166990717632653 (code B ref -1); Thu, 01 Dec 2022 15:07:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 1 Dec 2022 15:06:16 +0000 Original-Received: from localhost ([127.0.0.1]:40187 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p0l8h-0008Ub-JL for submit@debbugs.gnu.org; Thu, 01 Dec 2022 10:06:16 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:60954) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p0l8f-0008UV-5F for submit@debbugs.gnu.org; Thu, 01 Dec 2022 10:06:13 -0500 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 1p0l8f-0002iL-0d for bug-gnu-emacs@gnu.org; Thu, 01 Dec 2022 10:06:13 -0500 Original-Received: from mail-lj1-x22b.google.com ([2a00:1450:4864:20::22b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p0l8d-0008C4-0G for bug-gnu-emacs@gnu.org; Thu, 01 Dec 2022 10:06:12 -0500 Original-Received: by mail-lj1-x22b.google.com with SMTP id n1so2203546ljg.3 for ; Thu, 01 Dec 2022 07:06:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:subject:from:to:content-language :user-agent:mime-version:date:message-id:sender:from:to:cc:subject :date:message-id:reply-to; bh=6mdV/KlJ0hWR7r2/mVHZdz0v45EqWE/wSFnkgtnMxa0=; b=Noonw0gTBTfmyObS7KLMJkAV679TyHNClnhYU0JswEEgPc73NnMjwG7ugU1a5IeZCh Y4Sj40Dmjr7QeIfBLv/2Zfx+gjn7kqmPj2XEB7h1/SdV7F3kPu2/PDTSxKbN1q9Kw0tw KuficR24JalSvgNU8pLZSvUirWdJ4gznMJmpi8zlHnC/dKs4bRUAf9JASYbMIp8XfyRm gGf+W3sgzmgQ5nQH7hsPr9uaP+T0uzehREmbs6WrUbrVh7uj7IJlUF/WOfXTecq9ErKC ht9Je65unKMILgjqMYIxXR61P1aPg2ZG3r7AuJXsiLpsteLdboQ3mAxMjnwW/jS18He1 oZmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:subject:from:to:content-language :user-agent:mime-version:date:message-id:sender:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=6mdV/KlJ0hWR7r2/mVHZdz0v45EqWE/wSFnkgtnMxa0=; b=sNPsiVj39KMNXIBmHlhLbocaX1dAxKZGEARHYr5Vx/S/7/FK8ICu1bIiLJlV0DTYz7 uw1FYhk8etaryaePeRDqJ/Xfp/b5MYp1xrnOOp6uinrbxbNP65NEVSHwuS6sJDmYDSvZ rVi26rbgNpX5FFzts/4qKO0GJIndNhY/AmApBrx/BqL9N3u2LiOb8XWKtLOpZDo7wwlV Zi40fmJMJxCKHsjzRF2Wrditcce6kyM/nDHCVNuwIz+0Gq4+FCd9ghogf4CeNwGHlPzp JekCrsd2heCkFdznmXjYFpqXqu74EuMIkn/tZjY+ZfYPNRNQcCyyAEsvUYzVHuFeQIoE AVtA== X-Gm-Message-State: ANoB5pmTtagqWvw457gnMn6jY7DYb5aidWns/lyQpqgJj8tx9lJHTIzB cI4f97JsqZ+pGpZlN9DYliZMrzbbDnk= X-Google-Smtp-Source: AA0mqf7KF9z9tKTFY0nogqYFxqmMEd8bIpRPf9kvqOsA0u3ym1/SzhheJBob8+iFfY/04lvq1l9Kbw== X-Received: by 2002:a2e:bf27:0:b0:279:74ab:77bd with SMTP id c39-20020a2ebf27000000b0027974ab77bdmr13326569ljr.380.1669907165458; Thu, 01 Dec 2022 07:06:05 -0800 (PST) Original-Received: from [192.168.0.101] (nat-0-0.nsk.sibset.net. [5.44.169.188]) by smtp.googlemail.com with ESMTPSA id h1-20020a056512220100b004b4e67c3c00sm674816lfu.53.2022.12.01.07.06.02 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 01 Dec 2022 07:06:03 -0800 (PST) Content-Language: en-US Received-SPF: pass client-ip=2a00:1450:4864:20::22b; envelope-from=manikulin@gmail.com; helo=mail-lj1-x22b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:249638 Archived-At: I propose to expand protocol of communication between emacsclient and server to allow passing of arbitrary arguments for --eval expression that are not treated as files. The goal is to pass strings to evaluated expressions in a safe way without necessity of escaping double quotes and backslashes. I suggest to add e,g, --args option of emacsclient that transfers everything after it (including arguments starting with dash) to server and causes let-binding the list to command-line-args-left (or another variable) before execution of preceding --eval options. It was briefly discussed in the following thread: Max Nikulin to emacs-orgmode. Re: Lazy load of org-protocol. Mon, 7 Feb 2022 21:57:09 +0700. https://list.orgmode.org/strc07$3o0$1@ciao.gmane.io Such feature will allow to avoid the following complications: - A lot of backslashes are used to escape double quotes in http://git.savannah.gnu.org/cgit/emacs.git/tree/etc/emacsclient-mail.desktop --eval \\\\(message-mailto\\\\ \\\\\\"%u\\\\\\"\\\\) and this file still relies on desktop environment protection against shell special characters in the value of %u - org-protocol sets an advice to intercept file names containing components like org-protocol:/store-link?url=URL&title=TITLE It is a hack since current working directory is prepended when such URI is specified as an emacsclient argument. Autoloading currently is not implemented for this advice. - There are enough unsafe suggestions on the web to directly inject argument into elisp expression without proper escaping. Consider the following message: Gregory Heytings to emacs-devel. Re: How to get DISPLAY of emacsclient? Mon, 28 Nov 2022 17:15:28 +0000. https://lists.gnu.org/archive/html/emacs-devel/2022-11/msg01771.html mid:338f50d42149668a6b3a@heytings.org emacsclient --eval '(progn (setq display "'$DISPLAY'") (princ display))' Despite probability of such event is rather low, accidentally DISPLAY value may be corrupted causing undesired effects of unsafe usage of the variable: - Word splitting is performed by shell after variable substitution. - If $DISPLAY is additionally wrapped into shell double quotes then something unexpected may still be executed by emacs DISPLAY=':0") (do-something-else) (ignore "' More examples of unsafe substitutions into evaluated expression: - https://www.reddit.com/r/emacs/comments/hhbcg7/emacsclient_eval_with_command_line_arguments/ - https://stackoverflow.com/questions/8848819/emacs-eval-ediff-1-2-how-to-put-this-line-in-to-shell-script the second link contains a recipe for proper quoting, but it is not in the accepted answer quoted1=${1//\\/\\\\}; quoted1=${quoted1//\"/\\\"} As an alternative, Jim Porter suggested an emacsclient option similar to emacs --funcall that should apply function to the following argument. I believe, if --args is implemented then it will be possible to define a helper function that combines function name and the command-line-args-left list. It will not require further extension of client-server protocol. Since the function to be applied must take strings arguments only, no integers or symbols are allowed, anyway wrapper functions to convert argument types will be required. That is why I do not expect real value of such apply feature. I hope, the emacsclient --eval "(message-mailto (car command-line-args-left))" \ --args mailto:bug-gnu-emacs@gnu.org feature will make it easier to pass arguments to the evaluated expressions in a safe way.