Chrome run as spot script bug when html file name contains "$..." (Solved)

interpretive language scripts


Moderator: Forum moderators

Post Reply
miltonx
Posts: 160
Joined: Sat Nov 28, 2020 12:04 am
Has thanked: 13 times
Been thanked: 6 times

Chrome run as spot script bug when html file name contains "$..." (Solved)

Post 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.

Last edited by miltonx on Tue Oct 11, 2022 1:38 am, edited 1 time in total.
User avatar
MochiMoppel
Posts: 1243
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 21 times
Been thanked: 444 times

Re: Chrome run as spot script bug when html file name contains "$..."

Post 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"
miltonx
Posts: 160
Joined: Sat Nov 28, 2020 12:04 am
Has thanked: 13 times
Been thanked: 6 times

Re: Chrome run as spot script bug when html file name contains "$..."

Post 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.

miltonx
Posts: 160
Joined: Sat Nov 28, 2020 12:04 am
Has thanked: 13 times
Been thanked: 6 times

Re: Chrome run as spot script bug when html file name contains "$..."

Post 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.

Burunduk
Posts: 257
Joined: Thu Jun 16, 2022 6:16 pm
Has thanked: 7 times
Been thanked: 127 times

Re: Chrome run as spot script bug when html file name contains "$..."

Post by Burunduk »

miltonx wrote: Wed Sep 28, 2022 3:33 am

Now 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:

Code: Select all

CMD=${@@Q}
miltonx
Posts: 160
Joined: Sat Nov 28, 2020 12:04 am
Has thanked: 13 times
Been thanked: 6 times

Re: Chrome run as spot script bug when html file name contains "$..."

Post 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:

Code: Select all

CMD=${@@Q}

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.

Post Reply

Return to “Scripts”