Page 1 of 1
Chrome run as spot script bug when html file name contains "$..." (Solved)
Posted: Tue Sep 27, 2022 7:20 am
by miltonx
Most puppy distros, in order to run chrome browser as spot user, modifies chrome launch script to contain something like this:
Code: Select all
exec su spot -s /bin/sh -c "google-chrome $ARGS"
When I try to open a local html file whose name contains "$...", for example "xxx$2yyy.html", somehow chrome removes "$" when it tries to interpret the file path, resulting in failure to open the file. As the "google-chrome..." command is written as a string argument following "/bin/sh -c", it looks very difficult for the /bin/sh/ command to properly parse the argument (to avoid reading "$2" as another arg). I tried different combinations of single and double quotes, but did not come to a solution.
Re: Chrome run as spot script bug when html file name contains "$..."
Posted: Tue Sep 27, 2022 12:52 pm
by MochiMoppel
Has nothing to do with Chrome or spot and is not a bug. You need to escape any dollar sign(s) in ARGS before running /bin/sh.
Try
Code: Select all
ARGS=${ARGS//$/\\$}
exec su spot -s /bin/sh -c "google-chrome $ARGS"
Re: Chrome run as spot script bug when html file name contains "$..."
Posted: Wed Sep 28, 2022 3:08 am
by miltonx
MochiMoppel wrote: Tue Sep 27, 2022 12:52 pm
Has nothing to do with Chrome or spot and is not a bug. You need to escape any dollar sign(s) in ARGS before running /bin/sh.
Try
Code: Select all
ARGS=${ARGS//$/\\$}
exec su spot -s /bin/sh -c "google-chrome $ARGS"
Strictly speaking, it is a bug since the run-chrome-as-spot script forgot to take into account special characters in the args. (That said, I'm not ungrateful for this nice chrome-as-spot hack in puppy.)
Yes, escaping is an obvious solution. But I was wondering whether there could be any other cleaner approach to make the program interpret the file name arg as literal string, since escaping could be complicated when other potentially michievous characters are included in the file name.
Re: Chrome run as spot script bug when html file name contains "$..."
Posted: Wed Sep 28, 2022 3:33 am
by miltonx
I found the chrome-as-spot to contain this line:
Code: Select all
[ "$1" ] && while [ "$1" ]; do ARGS="$ARGS \"$1\""; shift; done
I modifed it to:
Code: Select all
[ "$1" ] && while [ "$1" ]; do ARGS="$ARGS '$1'"; shift; done
Now it can open files whose names contain '$". But I wonder whether this modification could incur other potential problems.
Re: Chrome run as spot script bug when html file name contains "$..."
Posted: Mon Oct 10, 2022 11:44 pm
by Burunduk
miltonx wrote: Wed Sep 28, 2022 3:33 amNow it can open files whose names contain '$". But I wonder whether this modification could incur other potential problems.
The other problem can be single quotes in file names. I don't have the chrome-as-spot script on Fossapup64 but the /usr/sbin/run-as-spot has similar lines:
Code: Select all
CMD=''
while [ "$1" ]; do
CMD="$CMD \"$1\""
shift
done
The script starts with #!/bin/ash and something like this may fix it for the busybox shell:
Code: Select all
CMD=''
while [ "$1" ]; do
CMD="$CMD '${1//\'/\'\\\'\'}'"
shift
done
However, it's easier to just change the shebang to #!/bin/bash and then:
Re: Chrome run as spot script bug when html file name contains "$..."
Posted: Tue Oct 11, 2022 1:35 am
by miltonx
Burunduk wrote: Mon Oct 10, 2022 11:44 pm
The other problem can be single quotes in file names.
Oh, my... I just came to know that quotation marks can be used in linux file names.
Burunduk wrote: Mon Oct 10, 2022 11:44 pm
However, it's easier to just change the shebang to #!/bin/bash and then:
This is super neat. Exactly what I was trying to find.
For other users who may be interested, the @Q expansion means this, accoring to https://www.gnu.org/software/bash/manua ... nsion.html
${parameter@operator}
operator Q: The expansion is a string that is the value of parameter quoted in a format that can be reused as input.