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#59817: [PATCH] Fix etags local command injection vulnerability Date: Tue, 06 Dec 2022 16:52:40 +0200 Message-ID: <83bkog7fev.fsf@gnu.org> References: <83r0xf9qsx.fsf@gnu.org> <834jua9ggd.fsf@gnu.org> <83lenk7kuq.fsf@gnu.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28081"; mail-complaints-to="usenet@ciao.gmane.io" Cc: stefankangas@gmail.com, 59817@debbugs.gnu.org To: lux Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Dec 06 15:54:27 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 1p2ZKu-0006ox-Mq for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 06 Dec 2022 15:54:20 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p2ZKe-0007HD-St; Tue, 06 Dec 2022 09:54:04 -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 1p2ZKc-0007GG-Qm for bug-gnu-emacs@gnu.org; Tue, 06 Dec 2022 09:54:02 -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 1p2ZKc-0003iz-Hf for bug-gnu-emacs@gnu.org; Tue, 06 Dec 2022 09:54:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1p2ZKc-0004eq-5B for bug-gnu-emacs@gnu.org; Tue, 06 Dec 2022 09:54:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 06 Dec 2022 14:54:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 59817 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 59817-submit@debbugs.gnu.org id=B59817.167033838417897 (code B ref 59817); Tue, 06 Dec 2022 14:54:02 +0000 Original-Received: (at 59817) by debbugs.gnu.org; 6 Dec 2022 14:53:04 +0000 Original-Received: from localhost ([127.0.0.1]:43380 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p2ZJg-0004eb-8b for submit@debbugs.gnu.org; Tue, 06 Dec 2022 09:53:04 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:41480) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p2ZJd-0004eE-Sg for 59817@debbugs.gnu.org; Tue, 06 Dec 2022 09:53:03 -0500 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 1p2ZJX-0003au-Uu; Tue, 06 Dec 2022 09:52:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=rFLlVaf65ps/ksHkAlRhZ56IQfR6PWpOtcjgHprmAD0=; b=K5HwiLZFwvSl mBlDsB48LGIVPRugsr3mPRpJWTA+B8EcgylhaffnNtDBM3/RRwJOGpFPWQQGiee5zDHmWx8dMr691 8NRVZycGJjwEd7fUZzbcNyfQ/dodCJI0Bq7BB9SoeRil7nufQq7GohjZ3jonu8CiIltS0LOSx6yUj aqIk9QfWPwYw+TNmVOwe2/xMqtbYS/MI99DJ0D5gHVznEe4mRHEXiehvObrr26TNEffyz8rFKkbiv TMwkv79wwyCEKEMHdV7uC/2RsTK1W729ltGvR2RZ0p6vO5rDbb4kNyHrmYiJJIBN7fShCTHlJO0NQ QCjdpmcHpHVdcKz2VEoJcw==; Original-Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p2ZJX-00040G-4K; Tue, 06 Dec 2022 09:52:55 -0500 In-Reply-To: (message from lux on Tue, 6 Dec 2022 21:11:35 +0800) 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:250115 Archived-At: > Date: Tue, 6 Dec 2022 21:11:35 +0800 > From: lux > Cc: stefankangas@gmail.com, 59817@debbugs.gnu.org > > On Tue, 06 Dec 2022 14:55:09 +0200 > Eli Zaretskii wrote: > > > The "MSDOS || DOS_NT" case also needs a small change: > > > > > char *cmd = concat (cmd1, "\" > ", tmp_name); > > > > This doesn't quote tmp_name; it should. > > Because double quotes have been used here The double quotes are only around real_name, but not around tmp_name. One of the issues you originally described was a bogus value of the TEMP environment variable, which gets used in etags_mktmp that produces tmp_name. > I have not reproduced this > vulnerability in Windows, so I have not dealt: > > $ touch "etags.c\" && ipconfig \".z" > $ ./etags.exe "etags.c\" && ipconfig \".z" > etags.c" && ipconfig ".z: Invalid argument Windows file names cannot include quote characters, so don't use them. And it's TEMP value that you need to tweak, not the file names etags scans. > > I don't understand why you are adding ''\'' and not just \'. > > Wouldn't the latter work for some reason? > > > > Because the single quote escape is: '\'' > > $ echo ''\''hello world'\''' > 'hello world' > $ echo 'I'\''m a poor man' > I'm a poor man I don't understand why you need an extra pair of quotes in the expanded string. $ echo \''hello; world' 'hello; world As you see, the semi-colon was successfully hidden from the shell. What am I missing?