The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
From: "G. Branden Robinson" <g.branden.robinson@gmail.com>
To: The Eunuchs Hysterical Society <tuhs@tuhs.org>
Subject: [TUHS] Re: shell escapes in utilities
Date: Tue, 1 Aug 2023 07:31:39 -0500	[thread overview]
Message-ID: <20230801123139.6splbkt4n7c75wu7@illithid> (raw)
In-Reply-To: <87zg3b3sc0.fsf@vuxu.org>

[-- Attachment #1: Type: text/plain, Size: 2356 bytes --]

At 2023-08-01T13:38:55+0200, Leah Neukirchen wrote:
> > I got to wondering, based on the sendmail discussions, how many
> > shell escapes have appeared over the years?
> >
> > uucp
> > sendmail
> > xdvi : "The "allowShell" option enables the shell escape in PostScript specials"
> 
> From the top of my head, where it can be disabled:
> 
> ghostscript (see above)
> tex (write18)
> ed/ex/vi
> nethack

And the *roffs of course.  nroff/troff/groff, with the `sy` (system(3))
and `pi` (popen(3)) requests.  pic(1) as well ("sh").

groff has, since version 1.12 in 1999, disabled these features by
default; the '-U' ("unsafe") command-line option reënables them.  It
added some additional unsafe requests for arbitrary stream I/O, `open`,
`opena` (open with append), and `pso` (`so` for pipeline output).

I recently learned of a limitation in the way AT&T and GNU *roffs, at
least, construct the string `sy` passes passes to system(3), which makes
certain things impossible.  Unfortunately it forecloses useful
applications, not any particularly malicious ones.

    There is a problem with trying to embed true newlines into the
    arguments of a `sy` request.  The C++ function that GNU troff uses
    to assemble the command string (character by character) _does not
    recognize C/C++ string literal escape sequences_.  This means that
    you _cannot_ embed "\n" in `sy`'s arguments and have it survive, as
    a newline character, into the command string passed to the standard
    C library's system(3) function.  ("A\nB" gets encoded as 'A', '\\',
    'n', 'B', not 'A', '\n', 'B'.) Unfortunately, this appears to be
    AT&T troff-compatible behavior.  But it means that you _cannot_
    portably construct multi-line replacement text for sed's 's'
    command.  (Other sed commands like 'a', 'c', and 'i' will be
    similarly affected.)  See Savannah #64071.

AT&T troff obviously wasn't written in C++, so this would appear to be
an instance of independent oversight.  (Where James Clark had gripes
about AT&T troff behavior, he left them in source code comments.)

I aim to fix this.  If I can write an arbitrary shell command, then I
darn well ought to be able to embed an arbitrary sed script in that
shell command (without needing a GNU sed extension to embed newlines).

Regards,
Branden

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2023-08-01 12:31 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-01  5:47 [TUHS] " ron minnich
2023-08-01 11:38 ` [TUHS] " Leah Neukirchen
2023-08-01 12:31   ` G. Branden Robinson [this message]
2023-08-01 20:33   ` Dave Horsfall
2023-08-01 20:40     ` arnold
2023-08-01 14:29 ` Skip Tavakkolian
2023-08-01 15:30   ` ron minnich
2023-08-01 18:43     ` Ron Natalie
2023-08-01 18:55       ` Niklas Karlsson
2023-08-01 20:48         ` Steffen Nurpmeso
2023-08-01 21:11           ` Ron Natalie
2023-08-01 21:52             ` Steffen Nurpmeso
2023-08-01 21:13           ` Niklas Karlsson
2023-08-01 21:19         ` Dave Horsfall
2023-08-02  3:01         ` Grant Taylor via TUHS
2023-08-02  3:42           ` Niklas Karlsson
2023-08-02  2:59       ` Grant Taylor via TUHS
2023-08-02 10:49         ` Rich Salz
2023-08-02 14:49           ` Grant Taylor via TUHS
2023-08-02 14:20         ` Clem Cole
2023-09-19 16:56     ` Ori Bernstein
2023-09-19 17:04       ` ron minnich
2023-08-01 15:36 ` Phil Budne
2023-08-01 15:37 ` Clem Cole
2023-08-01 15:37 ` Grant Taylor via TUHS

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230801123139.6splbkt4n7c75wu7@illithid \
    --to=g.branden.robinson@gmail.com \
    --cc=tuhs@tuhs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).