From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Kangas Newsgroups: gmane.emacs.bugs Subject: bug#66390: `man' allows to inject arbitrary shell code Date: Fri, 20 Oct 2023 14:00:50 -0700 Message-ID: References: <83wmvyzir2.fsf@gnu.org> <585dcaf0-358e-4a9d-84d1-6fd9c2c8aec5@gmail.com> <83v8bizf9r.fsf@gnu.org> <1865abb8-16cd-4570-9a8a-87cf9430583d@gmail.com> <875y3iigua.fsf@gmx.de> <83o7hazap7.fsf@gnu.org> <87mswugyoq.fsf@gmx.de> <83jzryz6op.fsf@gnu.org> <87a5sugwcx.fsf@gmx.de> <83h6n2z3tr.fsf@gnu.org> <831qe5znrz.fsf@gnu.org> <262ed9fe-b92b-489d-b1f0-5202bfdb088b@gmail.com> <87il7e78j5.fsf@igel.home> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26458"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Max Nikulin , 66390@debbugs.gnu.org, michael.albinus@gmx.de, Eli Zaretskii To: lux , Andreas Schwab Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Oct 20 23:01:49 2023 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 1qtwcu-0006jD-Tc for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 20 Oct 2023 23:01:49 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtwcn-0000xw-A9; Fri, 20 Oct 2023 17:01:41 -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 1qtwcg-0000xe-UF for bug-gnu-emacs@gnu.org; Fri, 20 Oct 2023 17:01:35 -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 1qtwcg-0004hZ-Ll for bug-gnu-emacs@gnu.org; Fri, 20 Oct 2023 17:01:34 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qtwd8-000605-0x for bug-gnu-emacs@gnu.org; Fri, 20 Oct 2023 17:02:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Kangas Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 20 Oct 2023 21:02:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66390 X-GNU-PR-Package: emacs Original-Received: via spool by 66390-submit@debbugs.gnu.org id=B66390.169783568623012 (code B ref 66390); Fri, 20 Oct 2023 21:02:01 +0000 Original-Received: (at 66390) by debbugs.gnu.org; 20 Oct 2023 21:01:26 +0000 Original-Received: from localhost ([127.0.0.1]:41747 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qtwcY-0005z6-E2 for submit@debbugs.gnu.org; Fri, 20 Oct 2023 17:01:26 -0400 Original-Received: from mail-lj1-x231.google.com ([2a00:1450:4864:20::231]:51310) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qtwcW-0005yt-DW for 66390@debbugs.gnu.org; Fri, 20 Oct 2023 17:01:25 -0400 Original-Received: by mail-lj1-x231.google.com with SMTP id 38308e7fff4ca-2c50cd16f3bso18275631fa.2 for <66390@debbugs.gnu.org>; Fri, 20 Oct 2023 14:00:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697835651; x=1698440451; darn=debbugs.gnu.org; h=content-transfer-encoding:cc:to:subject:message-id:date :mime-version:references:in-reply-to:from:from:to:cc:subject:date :message-id:reply-to; bh=YWC5HGdci8HtfWESn98zSc+ThdVeoudm4wIs94D7h5s=; b=bmVug3ewkPFWATKjWL6qKCGs6DdF1X63h/n9Q/tTLONdfg5q2/+v0pqIwSO+AFZvs5 MhBcBEcw0O8LCXp7UJ0hPlbKOhTcDxszzpMlyiwDFA5bVE3kLxWbXjEJOvnAr8+3TwY9 8sn8Z3NeAJyBMwyZrsnMoyjETvCdqMMX7OmgdM3+aJWKd79zj1JtmMs4W39jBwFHZu5L KdUm2UHq479HyOnAymSubqVma2kIWTytaWxxgUlhIKqN9yA69S5gteKWCltBijakdELP oV+NyDp4wGTNhSp6vTKgeHsVhgwG24mIfQmknvEUTw/M8lnAMt8eX7fgx+wblf9AbNRr 2Aew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697835651; x=1698440451; h=content-transfer-encoding:cc:to:subject:message-id:date :mime-version:references:in-reply-to:from:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=YWC5HGdci8HtfWESn98zSc+ThdVeoudm4wIs94D7h5s=; b=gaZDk3QOvCQOtZ40JY/LuRnQumUPvNYhp0T5+WVrCMzH+Tmb3xChSyKpnXsUvtgDM6 9elbBawYyRmh48gs2BjejrVuA6uKOYaoh1LMysOwwDjw6xNX94/Y6ob9YR+1N/HIL6SJ eyXV4D+/vwg6WikpIjYz3IiQqQroRw0OBoSzkAWDJvkg+lZH/aIp3qoHaSeL63I0+bv3 gDVNE8RREP6eVusko2ggOHnICCWeLCPvt1vgqTAn7WAUBaQv6v5K5lvD45RgJDJfc+Y0 74Z8+jmN1fuUorsQHXWpACpM91DXFM9AuqN0Uf7K/fkFMkbDHyAMS4BWiHkGY6jxTzkW zJVg== X-Gm-Message-State: AOJu0YwvGoxasHwuKtekH6ID+FnbsYWdaHgoD/8tdmhyO3Zsa72MsKFr D4AJwHnQrl5qlsopgDp9tHnrId3+TtyGdcOgqlU= X-Google-Smtp-Source: AGHT+IEhl8E9wgdFTHoVKcUqL5DjNB+dRHmXpMjB1dUmSxnZvEdu/H0j8f6PS8hbaQDAVjEsBoP0oRNAjlznkIKU4Uo= X-Received: by 2002:a2e:a7cc:0:b0:2c5:fb9:49b6 with SMTP id x12-20020a2ea7cc000000b002c50fb949b6mr3217244ljp.10.1697835650808; Fri, 20 Oct 2023 14:00:50 -0700 (PDT) Original-Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Fri, 20 Oct 2023 14:00:50 -0700 In-Reply-To: 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:272818 Archived-At: lux writes: > On Tue, 2023-10-10 at 18:21 +0200, Andreas Schwab wrote: >> On Okt 10 2023, lux wrote: >> >> > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ;; see Bug#66390 >> > + (mapconcat 'identity >> > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (mapcar #'shell-quote-argument >> > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0 (split-string ref " ")) >> >> You need to split on arbitrary sequences of whitespace to not introduce >> spurious empty arguments. >> > > Thanks, I've modified it to (split-string ref "\\s-+"). I lost track of this discussion a little bit, but I think we should try to have this fixed in Emacs 29.2. Is the below patch acceptable? > From faa49ba78a203d47740280e5c6fd0e075628b507 Mon Sep 17 00:00:00 2001 > From: Xi Lu > Date: Tue, 10 Oct 2023 22:20:05 +0800 > Subject: [PATCH] Fix man.el code injection vulnerability. > > * lisp/man.el (Man-translate-references): Fix code injection. > * test/lisp/man-tests.el (man-tests-Man-translate-references): New. > --- > lisp/man.el | 6 +++++- > test/lisp/man-tests.el | 12 ++++++++++++ > 2 files changed, 17 insertions(+), 1 deletion(-) > > diff --git a/lisp/man.el b/lisp/man.el > index 506d6060269..a95435c7ea0 100644 > --- a/lisp/man.el > +++ b/lisp/man.el > @@ -692,7 +692,11 @@ Man-translate-references > (setq name (match-string 2 ref) > section (match-string 1 ref)))) > (if (string=3D name "") > - ref ; Return the reference as is > + ;; see Bug#66390 > + (mapconcat 'identity > + (mapcar #'shell-quote-argument > + (split-string ref "\\s-+")) > + " ") ; Return the reference as is > (if Man-downcase-section-letters-flag > (setq section (downcase section))) > (while slist > diff --git a/test/lisp/man-tests.el b/test/lisp/man-tests.el > index e3657d7df8a..1c6dcb63a5c 100644 > --- a/test/lisp/man-tests.el > +++ b/test/lisp/man-tests.el > @@ -161,6 +161,18 @@ man-bgproc-filter-buttonize-includes > (let ((button (button-at (match-beginning 0)))) > (should (and button (eq 'Man-xref-header-file (button-type b= utton)))))))))) > > +(ert-deftest man-tests-Man-translate-references () > + (should (equal (Man-translate-references "basename") > + "basename")) > + (should (equal (Man-translate-references "basename(3)") > + "3 basename")) > + (should (equal (Man-translate-references "basename(3v)") > + "3v basename")) > + (should (equal (Man-translate-references ";id") > + "\\;id")) > + (should (equal (Man-translate-references "-k basename") > + "-k basename"))) > + > (provide 'man-tests) > > ;;; man-tests.el ends here > -- > 2.42.0