[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: lynx-dev HTString.c patch for HTQuoteParameter()

From: Klaus Weide
Subject: Re: lynx-dev HTString.c patch for HTQuoteParameter()
Date: Fri, 14 Jul 2000 09:23:52 -0500 (CDT)

On Thu, 13 Jul 2000, Duncan Simpson wrote:

> In bash, and AFAIK most other shells (I think including *csh) it is permitted 
> to partial quote an argument, and even arbitarily mixed quoted and unquoted 
> sections in a single argument, provided yyou portect things that would be 
> seperators in the normal course of events. The agument will remain a single 
> argument.

Lynx's HTQuoteParameter function already uses a trick like this (not
exactly as shown by you), but only if the string to be quoted includes
a single quote character.

      ab"cd   (five characters)  ->  'ab'"'"'cd'

I don't know what DOS or VMS shells do with *that*... But then
HTQuoteParameter isn't used for them anyway.  (But it *is* used
when __CYGWIN__ is defined.  For whatever reason.)

It seems there is no protection like HTQuoteParameter in place for DOS or
WINDOS (non-__CYGWIN__) or VMS.   I guess those folks live more

Well, there is some kind of quoting for Windows if WIN_EX is defined
(quote_pathname in LYExtern.c).  But that one only puts double quotes
around a string if it contains spaces (without checking whether the
string contains, for example, alread a '" character).  And it is
only applied to EXTERNAL and VIEWER (or mailcap) commands.

And then there is some strange stuff in LYSystem(), only aplies for
defined(__EMX__) (one case) and defined(__CYGWIN__) && defined(DOSPATH)
(another case), that does some strange things like quoting (second
case only) and/or slash <-> backslash conversion on the already
constructed shell command.  Now *that* is silly, IMNSHO.  If such
transformations are needed, they should be done when the command
string is constructed (the way HTQuoteParameter is used), not by
attempting to analyze the alredy constructed command string afterwards.

Anyway, back to UNIX shells and HTQuoteParameter.  The problem my
patch fixes is that lynx would do

      ab\cd   (five characters)  ->  'ab\\cd'

when it should just do

      ab\cd   (five characters)  ->  'ab\cd'

> However laboriously turning off shell metacharacters and then using system is 
> silly and will breed nasty shell gotchas and exploits. Instead use fork() and 
> exec*() directly, which avoids the shell enitrely and is within POSIX. cygwin 
> also supports this solution.

Whether it's silly or not depends on what one is trying to do.
If the input consists of a number of arguments that are already separated
and can be used in argv[] directly, then what you write applies.  If
the input is a string that has to be parsed in order to separate it
into arguments, then it's easier to use /bin/sh to parse it (that's what
it's for!).  If the input is a string that is specd as being a shell
command, including shell interpretation of ';', '|', and so on, then of
course one has to use the shell.


; To UNSUBSCRIBE: Send "unsubscribe lynx-dev" to address@hidden

reply via email to

[Prev in Thread] Current Thread [Next in Thread]