9front - general discussion about 9front
 help / color / mirror / Atom feed
From: cinap_lenrek@felloff.net
To: 9front@9front.org
Subject: Re: [9front] [PATCH] rio: add -label wctl param; improve window(1)
Date: Sat, 16 May 2020 16:04:15 +0200	[thread overview]
Message-ID: <0C539553752FA1BAD2349A7EA7CF0902@felloff.net> (raw)
In-Reply-To: <5908F322508015DD8DD7AF2C02532108@a-b.xyz>

you want:

#pragma varargck argpos wsetlabel 2

and change:

+	if(label)
+		wsetlabel(w, label);

to:

+	if(label)
+		wsetlabel(w, "%s", label);

otherwise you got a classical format string attack.

about the -label flag in wctl message. i'm not so sure it is a good
idea. adding new flags there means a breaking change and updating rio
needs to be synchronized.

also we have the problem with quoting. (-cd also suffers from this).

i think running window recursively is not really the issue. the real
issue is that we have to properly preserve the arguments. all text
that comes after the last parsed word in wctl "new" word is passed
as a single argument to rc -c

however, when window receives multiple cmd arguments, we need to quote
the argument list proper as we'r essentially generating a rc script
that reproduces the argument list. the bug is when we do $"cmd
which destroys list tokenization.

a solution can be accomplished with rc's whatis, which lets rc
serialize a variable as a string that we can tunnel thru the wctl
text interface.

something like the diff at the bottom (this is just
for illustration, you can still simplify this further)?

note that we still handle one argument as a rc script for backwards
compatibility. so you can still do:

window 'echo hello; echo world; sleep 1'

but if you pass multile arguments, it will preserve the argument
list and not fail on strings that have spaces in them.

diff -r 4be989798860 rc/bin/window
--- a/rc/bin/window	Wed May 13 00:17:07 2020 +0200
+++ b/rc/bin/window	Sat May 16 15:52:47 2020 +0200
@@ -48,8 +48,11 @@
 		}
 }
 
-if(~ $#* 0) cmd=rc
-if not cmd=$*
+switch($#*){
+case 0; cmd=(rc -i)
+case 1; cmd=(rc -c $1)
+case *; cmd=$*
+}
 
 if(~ $#xflag 1){
 	echo -n `{basename $cmd(1)} >/dev/label >[2]/dev/null
@@ -100,5 +103,5 @@
 
 	if(! ~ $#wdir 0)
 		spec=($spec -cd $wdir)
-	echo new $spec $argv0 -x $cmd >>$wctl
+	echo new $spec `{whatis cmd} $argv0 -x '$cmd' >>$wctl
 }

--
cinap


  parent reply	other threads:[~2020-05-16 14:04 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-13 10:20 kvik
2020-05-13 13:34 ` [9front] " Ethan Gardener
2020-05-13 13:14   ` kvik
2020-05-14 13:28     ` Ethan Gardener
2020-05-14 12:20       ` kvik
2020-05-16 12:22   ` cinap_lenrek
2020-05-16 11:53     ` kvik
2020-05-16 18:04       ` cinap_lenrek
2020-05-16 14:04 ` cinap_lenrek [this message]
2020-05-16 16:08   ` kvik
2020-05-16 20:30     ` cinap_lenrek
2020-05-16 19:05       ` kvik

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=0C539553752FA1BAD2349A7EA7CF0902@felloff.net \
    --to=cinap_lenrek@felloff.net \
    --cc=9front@9front.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).