Opened 9 years ago
Closed 8 years ago
#104 closed task (fixed)
ash/dash: Convert backslashes to forward slashes in PATH-like environment vars
Reported by: | dmik | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | |
Component: | dash | Version: | |
Severity: | medium | Keywords: | |
Cc: |
Description
There is a fundamental problem in Unix-like shells when run under OS/2: backslashes in PATH-like environment variables. The backslashes will be interpreted as escape sequences by the shell in many cases which will produce incorrect results.
Examples of such cases include:
- Unquoted strings in shell scripts where backslashes will be simply dropped. E.g
sh -c '\abc\def.exe'
will try to startabcdef.exe
). - Special escape processing by the
echo
built-in. E.g. dashecho
will treat backspaces as escape chars in ANSI escape sequences and will eat them/replace with special characters. Some other shells like mksh behave the same way which makesecho
generally unsafe/unportable.
These cases are very common so a global solution is required — otherwise you have to patch each script to make path strings quoted and/or replace echo
with an external expr
command but this sounds like a really bad alternative.
The obvious solution is to fix all well-known PATH-like environment variables at the beginning of shell execution by replacing backslashes with slashes. The only drawback here is the in theory a PATH-like variable may be treated differently by a script but for variables like PATH/TMPDIR etc this is very unlikely (and even wrong) because they have a well-defined global system meaning so it looks safe to patch them. Another potential problem is custom script-specific variables that also contain paths but this is something we can't cover. A good idea is to introduce an environment variable recognized by shells that will contain the names of all PATH-like environment variables to fix (and that will default to PATH/TMPDIR etc).
Change History (4)
comment:1 by , 9 years ago
comment:2 by , 9 years ago
There is another potential problem. In theory, there still may be some applications that don't understand forward slashes in PATH etc. So they will fail when started from ash/dash. To solve this, we will use the original environment (that is not patched) to run external commands. And for the environment variables changed in ash and exported with export
we will do the opposite conversion (forward slashes to back slashes) before passing them to the external command.
comment:3 by , 8 years ago
I implemented the task in r1657. This change makes dash convert backslashes to forward ones in PATH-like variables at startup *and* convert them back before executing any external command (so that old OS/2 tools won't freak out). However, by default, dash only does conversion on the PATH variable itself. The rest of the variables needs to be listed in a special environment variable called PATHLIKE_VARS
(which takes comma separated values) prior to dash startup.
I'm still thinking if we should support more variables by default (i.e. w/o the need to specify them in PATHLIKE_VARS), like TMPDIR (used e.g. in ffmpeg configure) or HOME (also frequently used). The question is which ones exactly. As this list may be pretty big...
comment:4 by , 8 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
After some discussion with colleagues I added some default vars besides PATH in r1658. This should be enough for Unix-like software. More can be added later if needed. Note that there are much more PATH-like variables on OS/2 than the ones hardcoded (e.g. DPATH, BOOKSHELF, HELP, INCLUDE, LIBRARY, MOZILLA_HOME, C_INCLUDE_PATH, LIBRARY_PATH etc etc) but these are too OS- and configuration-specific, hence they should be added via PATHLIKE_VARS in config.sys.
BTW, this is where this ticket comes from: http://article.gmane.org/gmane.comp.video.ffmpeg.devel/213300.